'use client'; import InventoryProductDetail from '@/components/pages/inventory/product/detail/InventoryProductDetail'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; import { InventoryProductApi } from '@/services/api/inventory'; import { useRouter, useSearchParams } from 'next/navigation'; import useSWR from 'swr'; const InventoryProductDetailPage = () => { const router = useRouter(); const searchParams = useSearchParams(); const inventoryProductId = searchParams.get('inventoryProductId'); const { data: inventoryProduct, isLoading: isLoadingInventoryProduct } = useSWR(inventoryProductId, (id: number) => InventoryProductApi.getSingle(id) ); if (!inventoryProductId) { router.back(); return (
); } if ( !isLoadingInventoryProduct && (!inventoryProduct || isResponseError(inventoryProduct)) ) { router.replace('/404'); return; } return (
{isLoadingInventoryProduct && ( )} {!isLoadingInventoryProduct && isResponseSuccess(inventoryProduct) && ( )}
); }; export default InventoryProductDetailPage;