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
133 lines
4.5 KiB
TypeScript
133 lines
4.5 KiB
TypeScript
import { Head, router } from '@inertiajs/react';
|
|
import { Plus } from 'lucide-react';
|
|
import { useState } from 'react';
|
|
import { CardTable } from '@/components/card-table';
|
|
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
|
import { useCardTableExpand } from '@/components/hooks/use-card-table-expand';
|
|
import { PageHeader } from '@/components/page-header';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useServerTable } from '@/hooks/use-server-table';
|
|
import {
|
|
destroy,
|
|
create as purchaseCreate,
|
|
index as purchaseIndex,
|
|
edit as purchaseEdit,
|
|
} from '@/routes/admin/manage/purchases';
|
|
import type { Purchase } from './columns';
|
|
import { PurchaseCardRow } from './purchase-card';
|
|
import { PurchaseItemSubRow } from './purchase-sub-row';
|
|
|
|
type Props = {
|
|
purchases: {
|
|
data: Purchase[];
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
};
|
|
|
|
export default function PurchaseIndex({ purchases }: Props) {
|
|
const [deleting, setDeleting] = useState<Purchase | null>(null);
|
|
const expand = useCardTableExpand(true);
|
|
|
|
const pagination = {
|
|
current_page: purchases.current_page,
|
|
last_page: purchases.last_page,
|
|
per_page: purchases.per_page,
|
|
total: purchases.total,
|
|
};
|
|
|
|
const {
|
|
search,
|
|
handlePageChange,
|
|
handlePerPageChange,
|
|
handleSearchChange,
|
|
} = useServerTable({
|
|
route: () => purchaseIndex.url(),
|
|
pagination,
|
|
});
|
|
|
|
function handleDelete() {
|
|
if (!deleting) {
|
|
return;
|
|
}
|
|
|
|
router.delete(destroy.url(deleting.id), {
|
|
onSuccess: () => setDeleting(null),
|
|
});
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Head title="Belanja" />
|
|
|
|
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto p-4 md:p-6">
|
|
<PageHeader
|
|
title="Belanja"
|
|
actions={
|
|
<Button asChild>
|
|
<a href={purchaseCreate.url()}>
|
|
<Plus className="h-4 w-4" />
|
|
Tambah
|
|
</a>
|
|
</Button>
|
|
}
|
|
/>
|
|
|
|
<CardTable
|
|
data={purchases.data}
|
|
getItemKey={(p) => p.id}
|
|
expandedKeys={expand.expandedKeys}
|
|
onToggleExpand={expand.toggleExpand}
|
|
searchValue={search}
|
|
onSearchChange={handleSearchChange}
|
|
searchPlaceholder="Cari berdasarkan supplier..."
|
|
pagination={pagination}
|
|
onPageChange={handlePageChange}
|
|
onPerPageChange={handlePerPageChange}
|
|
renderCard={({
|
|
item,
|
|
index,
|
|
isExpanded,
|
|
onToggleExpand,
|
|
}) => (
|
|
<PurchaseCardRow
|
|
purchase={item}
|
|
index={
|
|
(pagination.current_page - 1) *
|
|
pagination.per_page +
|
|
index +
|
|
1
|
|
}
|
|
isExpanded={isExpanded}
|
|
onToggleExpand={onToggleExpand}
|
|
onEdit={(p) => {
|
|
window.location.href = purchaseEdit.url(p.id);
|
|
}}
|
|
onDelete={(p) => setDeleting(p)}
|
|
/>
|
|
)}
|
|
renderSubContent={(purchase) => (
|
|
<PurchaseItemSubRow purchase={purchase} />
|
|
)}
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
target={deleting}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setDeleting(null);
|
|
}
|
|
}}
|
|
title="Hapus Belanja"
|
|
description={(purchase) =>
|
|
`Apakah Anda yakin ingin menghapus belanja dari "${purchase.supplier?.name}"? Stok akan dikembalikan. Tindakan ini tidak dapat dibatalkan.`
|
|
}
|
|
onConfirm={handleDelete}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|