'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 } = 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