diff --git a/src/app/production/transfer-to-laying/detail/page.tsx b/src/app/production/transfer-to-laying/detail/page.tsx new file mode 100644 index 00000000..91b70bc6 --- /dev/null +++ b/src/app/production/transfer-to-laying/detail/page.tsx @@ -0,0 +1,138 @@ +'use client'; + +import { useRouter, useSearchParams } from 'next/navigation'; +import useSWR from 'swr'; + +import TransferToLayingForm from '@/components/pages/production/transfer-to-laying/form/TransferToLayingForm'; + +import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying'; +import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; + +import { TransferToLaying } from '@/types/api/production/transfer-to-laying'; + +// TODO: delete dummy data +const DUMMY_TRANSFER_TO_LAYING_DETAIL: TransferToLaying = { + id: 1, + transfer_date: '14-10-2025', + flock_source: { + id: 1, + name: 'Flock asal test', + }, + flock_destination: { + id: 2, + name: 'Flock tujuan destination', + }, + quantity: 10, + kandangs: [ + { + kandang: { + id: 1, + name: 'Kandang test', + location: { + id: 1, + name: 'test location', + address: 'test address 1', + area: { id: 1, name: 'test area 1' }, + }, + pic: { + id: 1, + id_user: 2, + email: 'test@gmail.com', + name: 'test', + }, + created_user: { + id: 1, + id_user: 2, + email: 'test@gmail.com', + name: 'test', + }, + created_at: '14-10-2025', + updated_at: '14-10-2025', + }, + quantity: 8, + }, + { + kandang: { + id: 1, + name: 'Kandang test 2', + location: { + id: 1, + name: 'test location', + address: 'test address 1', + area: { id: 1, name: 'test area 1' }, + }, + pic: { + id: 1, + id_user: 2, + email: 'test@gmail.com', + name: 'test', + }, + created_user: { + id: 1, + id_user: 2, + email: 'test@gmail.com', + name: 'test', + }, + created_at: '14-10-2025', + updated_at: '14-10-2025', + }, + quantity: 2, + }, + ], + reason: 'Test alasan', + + created_user: { + id: 1, + id_user: 2, + email: 'test@gmail.com', + name: 'test', + }, + created_at: '14-10-2025', + updated_at: '14-10-2025', +}; + +const TransferToLayingDetail = () => { + const router = useRouter(); + const searchParams = useSearchParams(); + + const transferToLayingId = searchParams.get('transferToLayingId'); + + const { data: transferToLaying, isLoading: isLoadingTransferToLaying } = + useSWR(transferToLayingId, (id: number) => + TransferToLayingApi.getSingle(id) + ); + + if (!transferToLayingId) { + router.back(); + + return ( +
+ +
+ ); + } + + if ( + !isLoadingTransferToLaying && + (!transferToLaying || isResponseError(transferToLaying)) + ) { + router.replace('/404'); + return; + } + + return ( +
+ {isLoadingTransferToLaying && ( + + )} + {!isLoadingTransferToLaying && isResponseSuccess(transferToLaying) && ( + + )} +
+ ); +}; + +export default TransferToLayingDetail;