From 452139eeedc8155d8e8d8aeed312cf6c50e00eb2 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Sun, 5 Oct 2025 16:07:17 +0700 Subject: [PATCH] feat(FE-40,41): create Master Data Detail Warehouse page --- src/app/master-data/warehouse/detail/page.tsx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/app/master-data/warehouse/detail/page.tsx diff --git a/src/app/master-data/warehouse/detail/page.tsx b/src/app/master-data/warehouse/detail/page.tsx new file mode 100644 index 00000000..7d6381e3 --- /dev/null +++ b/src/app/master-data/warehouse/detail/page.tsx @@ -0,0 +1,49 @@ +'use client'; + +import { useRouter, useSearchParams } from 'next/navigation'; +import useSWR from 'swr'; + +import WarehouseForm from '@/components/pages/master-data/warehouse/form/WarehouseForm'; + +import { WarehouseApi } from '@/services/api/master-data'; +import { isResponseSuccess } from '@/lib/api-helper'; + +const WarehouseDetail = () => { + const router = useRouter(); + const searchParams = useSearchParams(); + + const warehouseId = searchParams.get('warehouseId'); + + const { data: warehouse, isLoading: isLoadingWarehouse } = useSWR( + warehouseId, + (id: number) => WarehouseApi.getSingle(id) + ); + + if (!warehouseId) { + router.back(); + + return ( +
+ +
+ ); + } + + if (!isLoadingWarehouse && !warehouse) { + router.replace('/404'); + return; + } + + return ( +
+ {isLoadingWarehouse && ( + + )} + {!isLoadingWarehouse && isResponseSuccess(warehouse) && ( + + )} +
+ ); +}; + +export default WarehouseDetail;