- Implemented employee columns for data table with sorting and action buttons. - Created employee creation form with validation and default password information. - Developed employee editing form pre-filled with existing data. - Added employee listing page with delete and reset password functionalities. - Introduced leave request management with columns for status and actions. - Created leave request form for adding and editing requests with date pickers. - Implemented confirmation dialogs for delete, approve, and reject actions.
255 lines
8.8 KiB
TypeScript
255 lines
8.8 KiB
TypeScript
import type { ColumnDef } from '@tanstack/react-table';
|
|
import { router } from '@inertiajs/react';
|
|
import { ArrowUpDown, KeyRound, Pencil, Trash2 } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Switch } from '@/components/ui/switch';
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from '@/components/ui/tooltip';
|
|
|
|
export type Employee = {
|
|
id: number;
|
|
email: string;
|
|
username: string;
|
|
is_active: boolean;
|
|
user_profile: {
|
|
full_name: string;
|
|
phone_number: string | null;
|
|
} | null;
|
|
employee: {
|
|
join_date: string;
|
|
employment_status: string;
|
|
base_salary: number;
|
|
} | null;
|
|
};
|
|
|
|
function getEmploymentStatusLabel(status: string): string {
|
|
const labels: Record<string, string> = {
|
|
full_time: 'Full Time',
|
|
part_time: 'Part Time',
|
|
contract: 'Kontrak',
|
|
internship: 'Magang',
|
|
resigned: 'Keluar',
|
|
};
|
|
|
|
return labels[status] ?? status;
|
|
}
|
|
|
|
function formatCurrency(amount: number): string {
|
|
return new Intl.NumberFormat('id-ID', {
|
|
style: 'currency',
|
|
currency: 'IDR',
|
|
minimumFractionDigits: 0,
|
|
}).format(amount);
|
|
}
|
|
|
|
type CreateColumnsParams = {
|
|
handleEdit: (employee: Employee) => void;
|
|
handleDeleteClick: (employee: Employee) => void;
|
|
handleResetPassword: (employee: Employee) => void;
|
|
toggleActiveUrl: (id: number) => string;
|
|
};
|
|
|
|
export function createEmployeeColumns(
|
|
params: CreateColumnsParams,
|
|
): ColumnDef<Employee>[] {
|
|
const { handleEdit, handleDeleteClick, handleResetPassword, toggleActiveUrl } = params;
|
|
|
|
return [
|
|
{
|
|
id: 'no',
|
|
header: () => <span className="block text-center">No</span>,
|
|
cell: ({ row }) => (
|
|
<span className="block text-center">
|
|
{row.index + 1}
|
|
</span>
|
|
),
|
|
meta: {
|
|
className: 'w-[50px] text-center',
|
|
headerClassName: 'w-[50px] text-center',
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'user_profile.full_name',
|
|
id: 'full_name',
|
|
header: ({ column }) => (
|
|
<Button
|
|
variant="ghost"
|
|
className="-ml-3 h-8"
|
|
onClick={() =>
|
|
column.toggleSorting(
|
|
column.getIsSorted() === 'asc',
|
|
)
|
|
}
|
|
>
|
|
<span>Nama</span>
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
),
|
|
cell: ({ row }) => {
|
|
const employee = row.original;
|
|
|
|
return (
|
|
<div className="flex flex-col">
|
|
<span className="font-medium">
|
|
{employee.user_profile?.full_name ?? '-'}
|
|
</span>
|
|
<span className="text-xs text-muted-foreground">
|
|
{employee.email}
|
|
</span>
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'username',
|
|
header: ({ column }) => (
|
|
<Button
|
|
variant="ghost"
|
|
className="-ml-3 h-8"
|
|
onClick={() =>
|
|
column.toggleSorting(
|
|
column.getIsSorted() === 'asc',
|
|
)
|
|
}
|
|
>
|
|
<span>Username</span>
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
),
|
|
cell: ({ row }) => (
|
|
<span className="font-medium">
|
|
{row.getValue('username') as string}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: 'user_profile.phone_number',
|
|
id: 'phone_number',
|
|
header: () => <span>No. HP</span>,
|
|
cell: ({ row }) => {
|
|
const employee = row.original;
|
|
|
|
return <span>{employee.user_profile?.phone_number ?? '-'}</span>;
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'employee.employment_status',
|
|
id: 'employment_status',
|
|
header: ({ column }) => (
|
|
<Button
|
|
variant="ghost"
|
|
className="-ml-3 h-8"
|
|
onClick={() =>
|
|
column.toggleSorting(
|
|
column.getIsSorted() === 'asc',
|
|
)
|
|
}
|
|
>
|
|
<span>Status</span>
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
),
|
|
cell: ({ row }) => {
|
|
const employee = row.original;
|
|
|
|
return (
|
|
<span className="inline-flex items-center rounded-md bg-muted px-2 py-1 text-xs font-medium">
|
|
{getEmploymentStatusLabel(employee.employee?.employment_status ?? '')}
|
|
</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: 'is_active',
|
|
header: () => <span className="block text-center">Aktif</span>,
|
|
meta: {
|
|
className: 'w-[80px] text-center',
|
|
headerClassName: 'w-[80px] text-center',
|
|
},
|
|
cell: ({ row }) => {
|
|
const employee = row.original;
|
|
|
|
return (
|
|
<div className="flex justify-center">
|
|
<Switch
|
|
size="sm"
|
|
checked={employee.is_active}
|
|
onCheckedChange={() => {
|
|
router.post(toggleActiveUrl(employee.id), {}, {
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
id: 'actions',
|
|
header: () => <span className="block text-center">Aksi</span>,
|
|
meta: {
|
|
className: 'w-[120px] text-center',
|
|
headerClassName: 'w-[120px] text-center',
|
|
},
|
|
cell: ({ row }) => {
|
|
const employee = row.original;
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
<div className="flex items-center justify-center gap-1">
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => handleEdit(employee)}
|
|
>
|
|
<Pencil className="h-4 w-4" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">
|
|
Edit
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => handleResetPassword(employee)}
|
|
>
|
|
<KeyRound className="h-4 w-4 text-muted-foreground" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">
|
|
Reset Kata Sandi
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => handleDeleteClick(employee)}
|
|
>
|
|
<Trash2 className="h-4 w-4 text-destructive" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">
|
|
Hapus
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</TooltipProvider>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
}
|