dstpabuaran.com/resources/js/pages/admin/finance/cash-account/transaction-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

192 lines
6.1 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 CashTransaction = {
id: number;
amount: number;
balance_after: number;
type: 'deposit' | 'withdrawal' | 'expense' | 'transfer';
description: string;
receipt_key: string | null;
receipt_url: string | null;
created_at: string;
created_by: {
user_profile: {
full_name: string;
};
};
reference: {
type: string;
} | null;
};
function getTypeLabel(type: string): string {
const labels: Record<string, string> = {
deposit: 'Deposit',
withdrawal: 'Withdrawal',
expense: 'Pengeluaran',
transfer: 'Transfer',
};
return labels[type] ?? type;
}
function getReferenceLabel(type: string): string {
const labels: Record<string, string> = {
'App\\Models\\Expense': 'Pengeluaran',
'App\\Models\\Order': 'Penjualan Tunai',
'App\\Models\\Purchase': 'Belanja',
'App\\Models\\CashAccount': 'Transfer Kas',
};
return labels[type] ?? '-';
}
type CreateColumnsParams = {
handleEdit: (transaction: CashTransaction) => void;
handleDeleteClick: (transaction: CashTransaction) => void;
};
export function createTransactionColumns(
params: CreateColumnsParams,
): ColumnDef<CashTransaction>[] {
const { handleEdit, handleDeleteClick } = params;
return [
{
accessorKey: 'created_at',
header: () => <span>Tanggal</span>,
cell: ({ row }) => (
<span>{formatDate(row.getValue('created_at') as string)}</span>
),
},
{
id: 'source',
header: () => <span>Sumber</span>,
cell: ({ row }) => {
const transaction = row.original;
return (
<div className="flex flex-col">
<span className="font-medium">
{getTypeLabel(transaction.type)}
</span>
<span className="text-xs text-muted-foreground">
{getReferenceLabel(
transaction.reference?.type ?? '',
)}
</span>
</div>
);
},
},
{
accessorKey: 'amount',
header: () => <span>Jumlah</span>,
cell: ({ row }) => {
const transaction = row.original;
const isDeposit = transaction.type === 'deposit';
return (
<span
className={
isDeposit
? 'font-medium text-green-600'
: 'font-medium text-red-600'
}
>
{isDeposit ? '+' : '-'}{' '}
{formatCurrency(row.getValue('amount') as number)}
</span>
);
},
},
{
accessorKey: 'balance_after',
header: () => <span>Saldo Setelah</span>,
cell: ({ row }) => (
<span className="font-medium">
{formatCurrency(row.getValue('balance_after') as number)}
</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}
/>
);
},
},
{
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 transaction = row.original;
const canEdit =
transaction.type === 'deposit' ||
transaction.type === 'withdrawal';
if (!canEdit) {
return <span className="block text-center">-</span>;
}
return (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
onClick: () => handleEdit(transaction),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
onClick: () => handleDeleteClick(transaction),
},
]}
/>
);
},
},
];
}