- Integrated permission checks using `can` function in payroll period management to control visibility of adjustment, pay, and cancel actions. - Updated employee management to conditionally render edit, reset password, and delete actions based on permissions. - Enhanced leave request management with permission checks for approve, reject, edit, and delete actions. - Implemented permission checks in cutting management for edit and delete actions. - Added permission checks for purchase management actions including create, edit, and delete. - Integrated permission checks in restock management for create, edit, and delete actions. - Updated transaction management to conditionally render create, edit, and delete actions based on permissions. - Enhanced category management with permission checks for edit and delete actions. - Integrated permission checks in customer management for edit and delete actions. - Updated product management to conditionally render create, edit, and delete actions based on permissions. - Enhanced raw material management with permission checks for edit and delete actions. - Integrated permission checks in supplier management for edit and delete actions. - Updated role management to conditionally render edit and delete actions based on permissions.
135 lines
4.5 KiB
TypeScript
135 lines
4.5 KiB
TypeScript
import { Head, Link, 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 { useCan } from '@/hooks/use-can';
|
|
import { useServerTable } from '@/hooks/use-server-table';
|
|
import {
|
|
destroy,
|
|
create as restockCreate,
|
|
index as restockIndex,
|
|
edit as restockEdit,
|
|
} from '@/routes/admin/manage/restocks';
|
|
import type { Restock } from './columns';
|
|
import { RestockCardRow } from './restock-card';
|
|
import { RestockItemSubRow } from './restock-sub-row';
|
|
|
|
type Props = {
|
|
restocks: {
|
|
data: Restock[];
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
};
|
|
|
|
export default function RestockIndex({ restocks }: Props) {
|
|
const { can } = useCan();
|
|
const [deleting, setDeleting] = useState<Restock | null>(null);
|
|
const expand = useCardTableExpand(true);
|
|
|
|
const pagination = {
|
|
current_page: restocks.current_page,
|
|
last_page: restocks.last_page,
|
|
per_page: restocks.per_page,
|
|
total: restocks.total,
|
|
};
|
|
|
|
const {
|
|
search,
|
|
handlePageChange,
|
|
handlePerPageChange,
|
|
handleSearchChange,
|
|
} = useServerTable({
|
|
route: () => restockIndex.url(),
|
|
pagination,
|
|
});
|
|
|
|
function handleDelete() {
|
|
if (!deleting) {
|
|
return;
|
|
}
|
|
|
|
router.delete(destroy.url(deleting.id), {
|
|
onSuccess: () => setDeleting(null),
|
|
});
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Head title="Restock" />
|
|
|
|
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto p-4 md:p-6">
|
|
<PageHeader
|
|
title="Restock"
|
|
actions={
|
|
can('restocks.create') ? (
|
|
<Button asChild>
|
|
<Link href={restockCreate.url()}>
|
|
<Plus className="h-4 w-4" />
|
|
Tambah
|
|
</Link>
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
/>
|
|
|
|
<CardTable
|
|
data={restocks.data}
|
|
getItemKey={(r) => r.id}
|
|
expandedKeys={expand.expandedKeys}
|
|
onToggleExpand={expand.toggleExpand}
|
|
searchValue={search}
|
|
onSearchChange={handleSearchChange}
|
|
searchPlaceholder="Cari berdasarkan produk..."
|
|
pagination={pagination}
|
|
onPageChange={handlePageChange}
|
|
onPerPageChange={handlePerPageChange}
|
|
renderCard={({
|
|
item,
|
|
index,
|
|
isExpanded,
|
|
onToggleExpand,
|
|
}) => (
|
|
<RestockCardRow
|
|
restock={item}
|
|
index={
|
|
(pagination.current_page - 1) *
|
|
pagination.per_page +
|
|
index +
|
|
1
|
|
}
|
|
isExpanded={isExpanded}
|
|
onToggleExpand={onToggleExpand}
|
|
onEdit={(r) => {
|
|
router.visit(restockEdit.url(r.id));
|
|
}}
|
|
onDelete={(r) => setDeleting(r)}
|
|
/>
|
|
)}
|
|
renderSubContent={(restock) => (
|
|
<RestockItemSubRow restock={restock} />
|
|
)}
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
target={deleting}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setDeleting(null);
|
|
}
|
|
}}
|
|
title="Hapus Restock"
|
|
description="Apakah Anda yakin ingin menghapus restock ini? Stok akan dikembalikan. Tindakan ini tidak dapat dibatalkan."
|
|
onConfirm={handleDelete}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|