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
117 lines
3.6 KiB
TypeScript
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';
|
|
import { formatDate } from '@/lib/format';
|
|
import { formatCurrency } from '@/lib/utils';
|
|
|
|
export type Expense = {
|
|
id: number;
|
|
amount: number;
|
|
description: string;
|
|
receipt_key: string | null;
|
|
receipt_url: string | null;
|
|
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: 'created_at',
|
|
header: () => <span>Tanggal</span>,
|
|
cell: ({ row }) => (
|
|
<span>{formatDate(row.getValue('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: 'amount',
|
|
header: () => <span>Jumlah</span>,
|
|
cell: ({ row }) => (
|
|
<span className="font-medium text-red-600">
|
|
- {formatCurrency(row.getValue('amount') as number)}
|
|
</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),
|
|
},
|
|
]}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
}
|