dstpabuaran.com/resources/js/pages/admin/finance/expense/columns.tsx
Yoga Pangestu 4517eeb7ee feat: enhance employee and leave request management
- Added roles property to Employee type and a new column for displaying employee roles in the employee table.
- Updated leave request columns to use formatted start and end dates instead of raw date strings.
- Enhanced leave request index to accept filter options for status dynamically.
- Refactored transaction index to support dynamic filter options for status, channel, and payment type.
- Introduced AGENTS.md for session notes detailing model relationships, casting, scopes, reorganizations, and conventions.
2026-08-04 23:03:56 +07:00

117 lines
3.6 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { Pencil, Trash2 } from 'lucide-react';
import { ImagePreviewButton } from '@/components/image-preview-button';
import { RowActions } from '@/components/row-actions';
export type Expense = {
id: number;
amount: number;
formatted_amount: string;
description: string;
receipt_key: string | null;
receipt_url: string | null;
created_at: string;
formatted_created_at: string;
created_by: {
user_profile: {
full_name: string;
};
};
};
type CreateColumnsParams = {
handleEdit: (expense: Expense) => void;
handleDeleteClick: (expense: Expense) => void;
};
export function createExpenseColumns(
params: CreateColumnsParams,
): ColumnDef<Expense>[] {
const { handleEdit, handleDeleteClick } = params;
return [
{
accessorKey: 'formatted_created_at',
header: () => <span>Tanggal</span>,
cell: ({ row }) => (
<span>{row.getValue('formatted_created_at') as string}</span>
),
},
{
accessorKey: 'description',
header: () => <span>Keterangan</span>,
cell: ({ row }) => (
<span className="block max-w-[200px] truncate">
{row.getValue('description') as string}
</span>
),
},
{
id: 'receipt',
header: () => <span>Bukti</span>,
cell: ({ row }) => {
const receiptUrl = row.original.receipt_url;
if (!receiptUrl) {
return <span className="text-muted-foreground">-</span>;
}
return (
<ImagePreviewButton
srcs={[receiptUrl]}
title={row.original.description}
/>
);
},
},
{
accessorKey: 'formatted_amount',
header: () => <span>Jumlah</span>,
cell: ({ row }) => (
<span className="font-medium text-red-600">
- {row.getValue('formatted_amount') as string}
</span>
),
},
{
id: 'created_by',
header: () => <span>Oleh</span>,
cell: ({ row }) => {
const createdBy = row.original.created_by;
return <span>{createdBy?.user_profile?.full_name ?? '-'}</span>;
},
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const expense = row.original;
return (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
onClick: () => handleEdit(expense),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
onClick: () => handleDeleteClick(expense),
},
]}
/>
);
},
},
];
}