dstpabuaran.com/resources/js/pages/admin/hr/employee/columns.tsx
Yoga Pangestu d91ec8869e refactor: replace tooltip buttons with row actions component in supplier and role columns
feat: implement delete confirmation dialog component for better UX

refactor: update supplier and role index pages to utilize new form dialog and delete confirm dialog components

feat: add reusable form dialog component for creating and editing entities

feat: introduce filter popover component for enhanced filtering options in data tables

feat: create image preview button component for displaying images with modal preview

feat: add page header component for consistent page layout

feat: implement row actions component for handling actions on table rows

feat: add status badge component for displaying entity statuses

feat: create toggle status component for easily toggling entity states

feat: implement draft save hook for auto-saving form data

feat: add server table hook for managing server-side pagination and filtering

feat: create utility functions for formatting dates and numbers

feat: add constants for month names and measurement units
2026-08-02 23:40:12 +07:00

169 lines
5.4 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { KeyRound, Pencil, Trash2 } from 'lucide-react';
import { RowActions } from '@/components/row-actions';
import { ToggleStatus } from '@/components/toggle-status';
import { formatCurrency } from '@/lib/utils';
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;
}
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 [
{
accessorKey: 'user_profile.full_name',
id: 'full_name',
header: () => <span>Nama</span>,
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: () => <span>Username</span>,
cell: ({ row }) => (
<span className="font-medium">
{row.getValue('username') as string}
</span>
),
},
{
accessorKey: 'user_profile.phone_number',
id: 'phone_number',
header: () => <span>No. Telepon</span>,
cell: ({ row }) => {
const employee = row.original;
return (
<span>{employee.user_profile?.phone_number ?? '-'}</span>
);
},
},
{
accessorKey: 'employee.employment_status',
id: 'employment_status',
header: () => <span>Status</span>,
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">
<ToggleStatus
url={toggleActiveUrl(employee.id)}
checked={employee.is_active}
wrapperClassName="flex items-center justify-center gap-1"
/>
</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 (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
onClick: () => handleEdit(employee),
},
{
label: 'Reset Kata Sandi',
icon: (
<KeyRound className="h-4 w-4 text-muted-foreground" />
),
onClick: () => handleResetPassword(employee),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
onClick: () => handleDeleteClick(employee),
},
]}
/>
);
},
},
];
}