From 3312a47f38f5f69d6dcfc92144fdc06fdb770b2d Mon Sep 17 00:00:00 2001 From: rstubryan Date: Tue, 4 Nov 2025 11:22:52 +0700 Subject: [PATCH] feat(FE-208): create PurchaseDetail page with dummy data and integrate PurchaseRequestForm --- src/app/purchase/detail/page.tsx | 107 ++++++++++++++++++ .../pages/purchase/PurchaseTable.tsx | 6 +- .../form/request/PurchaseRequestForm.tsx | 27 +++-- 3 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 src/app/purchase/detail/page.tsx diff --git a/src/app/purchase/detail/page.tsx b/src/app/purchase/detail/page.tsx new file mode 100644 index 00000000..c934a945 --- /dev/null +++ b/src/app/purchase/detail/page.tsx @@ -0,0 +1,107 @@ +'use client'; + +import { useRouter, useSearchParams } from 'next/navigation'; +import useSWR from 'swr'; + +import PurchaseRequestForm from '@/components/pages/purchase/form/request/PurchaseRequestForm'; + +import { PurchaseApi } from '@/services/api/purchase'; +import { isResponseError } from '@/lib/api-helper'; + +import { Purchase } from '@/types/api/purchase/purchase'; + +// TODO: delete dummy data +const DUMMY_PURCHASE_DETAIL: Purchase = { + id: 1, + pr_number: 'PR-001', + po_number: 'PO-001', + po_date: '2024-01-15', + supplier: { + id: 1, + name: 'Supplier A', + address: '123 Main St, Cityville', + account_number: 'ACC-12345', + alias: 'SupA', + category: 'Electronics', + type: 'Local', + phone: '555-1234', + email: 'email@.com', + npwp: '12.345.678.9-012.345', + pic: 'John Doe', + balance: 1000000, + hatchery: 'N/A', + due_date: 30, + created_at: '2024-01-10T10:00:00Z', + updated_at: '2024-01-12T12:00:00Z', + created_user: { + id: 2, + id_user: 2, + email: 'a@email.com', + name: 'Admin User', + }, + }, + credit_term: 30, + due_date: '2024-02-14', + grand_total: 1500000, + notes: 'Urgent delivery required', + deleted_at: null, + created_at: '2024-01-10T10:00:00Z', + updated_at: '2024-01-12T12:00:00Z', + created_by: 2, + created_user: { + id: 2, + id_user: 2, + email: 'a@email.com', + name: 'Admin User', + }, +}; + +const PurchaseDetail = () => { + const router = useRouter(); + const searchParams = useSearchParams(); + + const purchaseId = searchParams.get('purchaseId'); + + const { data: purchase, isLoading: isLoadingPurchase } = useSWR( + purchaseId, + (id: number) => PurchaseApi.getSingle(id) + ); + + if (!purchaseId) { + router.back(); + + return ( +
+ +
+ ); + } + + // TODO: remove dummy data and integrate with real API + if ( + !isLoadingPurchase && + (!purchase || (isResponseError(purchase) && !DUMMY_PURCHASE_DETAIL)) + ) { + router.replace('/404'); + return; + } + + return ( +
+ {isLoadingPurchase && ( + + )} + {/* {!isLoadingPurchase && isResponseSuccess(purchase) && ( + + )} */} + + {/* TODO: remove this dummy data and integrate to real API */} + +
+ ); +}; + +export default PurchaseDetail; diff --git a/src/components/pages/purchase/PurchaseTable.tsx b/src/components/pages/purchase/PurchaseTable.tsx index 0ff9b12c..9d0fd49b 100644 --- a/src/components/pages/purchase/PurchaseTable.tsx +++ b/src/components/pages/purchase/PurchaseTable.tsx @@ -40,7 +40,7 @@ const RowOptionsMenu = ({ return ( @@ -967,6 +968,12 @@ const PurchaseRequestForm = ({ onClick={deletePurchaseRequestClickHandler} className='px-4' > + Delete