From 50477d0850a67af453d8c27621eea578b5038f26 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Tue, 27 Jan 2026 16:57:46 +0700 Subject: [PATCH] feat: create TransferToLayingDetailModal component --- .../TransferToLayingDetailModal.tsx | 338 ++++++++++++++++++ 1 file changed, 338 insertions(+) create mode 100644 src/components/pages/production/transfer-to-laying/TransferToLayingDetailModal.tsx diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingDetailModal.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingDetailModal.tsx new file mode 100644 index 00000000..7be756e2 --- /dev/null +++ b/src/components/pages/production/transfer-to-laying/TransferToLayingDetailModal.tsx @@ -0,0 +1,338 @@ +'use client'; + +import { useEffect } from 'react'; +import { useRouter, useSearchParams } from 'next/navigation'; +import useSWR from 'swr'; + +import { Icon } from '@iconify/react'; +import Modal, { useModal } from '@/components/Modal'; +import Button from '@/components/Button'; +import DateInput from '@/components/input/DateInput'; +import SelectInputRadio from '@/components/input/SelectInputRadio'; +import NumberInput from '@/components/input/NumberInput'; +import TextArea from '@/components/input/TextArea'; +import ApprovalStepsV2 from '@/components/helper/ApprovalStepsV2'; +import StatusBadge from '@/components/helper/StatusBadge'; + +import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying'; +import { isResponseSuccess } from '@/lib/api-helper'; +import { formatNumber } from '@/lib/helper'; +import { APPROVAL_WORKFLOWS } from '@/config/constant'; + +const TransferToLayingDetailModal = () => { + const router = useRouter(); + const searchParams = useSearchParams(); + + const modalAction = searchParams.get('action'); + const transferToLayingId = searchParams.get('id'); + + const { + data: transferToLayingResponse, + isLoading: isLoadingTransferToLaying, + } = useSWR( + transferToLayingId + ? ['detail-transfer-to-laying', transferToLayingId] + : undefined, + ([, id]) => TransferToLayingApi.getSingle(Number(id)) + ); + + const transferToLaying = isResponseSuccess(transferToLayingResponse) + ? transferToLayingResponse.data + : undefined; + + const { + data: transferToLayingApprovalResponse, + isLoading: isLoadingTransferToLayingApproval, + } = useSWR( + transferToLayingId + ? ['approval-transfer-to-laying', transferToLayingId] + : undefined, + ([, id]) => TransferToLayingApi.getApprovalLineHistory(Number(id)) + ); + + const transferToLayingApproval = isResponseSuccess( + transferToLayingApprovalResponse + ) + ? transferToLayingApprovalResponse.data + : undefined; + + const detailModal = useModal(); + + const totalEnteredChickenForTransfer = + transferToLaying?.sources.reduce( + (acc, item) => acc + Number(item.qty), + 0 + ) ?? 0; + + const totalTransferedChicken = + transferToLaying?.targets.reduce( + (acc, item) => acc + Number(item.qty), + 0 + ) ?? 0; + + const totalAvailableChickenForTransfer = + totalEnteredChickenForTransfer - totalTransferedChicken; + + const closeModalHandler = (shouldPushToRoute: boolean = true) => { + if (shouldPushToRoute) { + router.push('/production/transfer-to-laying'); + } + + detailModal.closeModal(); + }; + + useEffect(() => { + if (modalAction === 'detail') { + detailModal.openModal(); + } + }, [modalAction]); + + return ( + +
+
+ + +
+ +

+ Confirmation +

+
+ + {!isLoadingTransferToLaying && transferToLaying && ( + <> + + +
+

+ Informasi Umum +

+ + + + + + +
+ +
+

+ Informasi Kandang +

+ + {/* Source Kandang */} +
+ + Kandang Asal{' '} + + * + + + + {transferToLaying?.sources.length === 0 && ( + + Belum ada kandang asal yang dipilih + + )} + + {transferToLaying?.sources && + transferToLaying?.sources.length > 0 && ( +
+ {transferToLaying?.sources.map((item, index) => { + return ( + + + { + item.source_project_flock_kandang.kandang + .name + } + + +
+
+ } + className={{ + inputPrefix: + 'py-0 px-0 pl-3 text-base-content/50 bg-transparent border-r-0', + inputPrefixSuffixWrapper: 'grid grid-cols-2', + inputWrapper: 'border-l-0 pl-5', + }} + /> + ); + })} +
+ )} +
+ + {/* Destination Kandang */} +
+ + + Kandang Tujuan{' '} + + * + + + +
+ + + + + {transferToLaying?.targets.length === 0 && ( + + Belum ada kandang tujuan yang dipilih + + )} + + {transferToLaying?.targets && + transferToLaying?.targets.length > 0 && ( +
+ {transferToLaying?.targets.map((item, index) => { + return ( + + + { + item.target_project_flock_kandang.kandang + .name + } + + +
+
+ } + className={{ + inputPrefix: + 'py-0 px-0 pl-3 text-base-content/50 bg-transparent border-r-0', + inputPrefixSuffixWrapper: 'grid grid-cols-2', + inputWrapper: 'border-l-0 pl-5', + }} + /> + ); + })} +
+ )} +
+
+ +
+

+ Informasi Umum +

+ + + +