mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE): Display FCR standards table in RecordingForm
This commit is contained in:
@@ -22,12 +22,16 @@ import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
|||||||
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
import Modal, { useModal } from '@/components/Modal';
|
import Modal, { useModal } from '@/components/Modal';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import Table from '@/components/Table';
|
||||||
|
import { type ColumnDef } from '@tanstack/react-table';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ProjectFlockKandangApi,
|
ProjectFlockKandangApi,
|
||||||
RecordingApi,
|
RecordingApi,
|
||||||
ProjectFlockApi,
|
ProjectFlockApi,
|
||||||
} from '@/services/api/production';
|
} from '@/services/api/production';
|
||||||
|
import { FcrApi } from '@/services/api/master-data';
|
||||||
|
import { FcrWithStandards, FcrStandard } from '@/types/api/master-data/fcr';
|
||||||
import { LocationApi } from '@/services/api/master-data';
|
import { LocationApi } from '@/services/api/master-data';
|
||||||
import { ProductWarehouseApi } from '@/services/api/inventory';
|
import { ProductWarehouseApi } from '@/services/api/inventory';
|
||||||
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||||
@@ -76,6 +80,24 @@ interface RecordingFormProps {
|
|||||||
initialValues?: Recording;
|
initialValues?: Recording;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fcrStandardColumns: ColumnDef<FcrStandard>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'weight',
|
||||||
|
header: 'Weight',
|
||||||
|
cell: (props) => formatNumber(props.getValue() as number),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'fcr_number',
|
||||||
|
header: 'FCR Number',
|
||||||
|
cell: (props) => formatNumber(props.getValue() as number),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'mortality',
|
||||||
|
header: 'Mortality',
|
||||||
|
cell: (props) => formatNumber(props.getValue() as number),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||||
// ===== HOOKS & ROUTER =====
|
// ===== HOOKS & ROUTER =====
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -124,6 +146,42 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const fcrStandardModal = useModal();
|
const fcrStandardModal = useModal();
|
||||||
const productionStandardModal = useModal();
|
const productionStandardModal = useModal();
|
||||||
|
|
||||||
|
const [fcrStandards, setFcrStandards] = useState<FcrStandard[]>([]);
|
||||||
|
|
||||||
|
const [isFcrModalOpen, setIsFcrModalOpen] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkFcrModalOpen = () => {
|
||||||
|
const isOpen = fcrStandardModal.ref.current?.open || false;
|
||||||
|
setIsFcrModalOpen(isOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
checkFcrModalOpen();
|
||||||
|
|
||||||
|
const observer = new MutationObserver(checkFcrModalOpen);
|
||||||
|
if (fcrStandardModal.ref.current) {
|
||||||
|
observer.observe(fcrStandardModal.ref.current, {
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['open'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [fcrStandardModal.ref]);
|
||||||
|
|
||||||
|
const { data: fcr, isLoading: isLoadingFcrStandards } = useSWR(
|
||||||
|
isFcrModalOpen && initialValues?.project_flock?.fcr?.id
|
||||||
|
? `fcr-detail-${initialValues.project_flock.fcr.id}`
|
||||||
|
: null,
|
||||||
|
() => FcrApi.getSingle(initialValues!.project_flock!.fcr!.id!)
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (fcr?.status === 'success') {
|
||||||
|
setFcrStandards((fcr.data as FcrWithStandards).fcr_standards || []);
|
||||||
|
}
|
||||||
|
}, [fcr]);
|
||||||
|
|
||||||
const isRecordingApproved = useCallback((recording?: Recording) => {
|
const isRecordingApproved = useCallback((recording?: Recording) => {
|
||||||
return (
|
return (
|
||||||
recording?.approval?.action === 'APPROVED' &&
|
recording?.approval?.action === 'APPROVED' &&
|
||||||
@@ -2735,23 +2793,33 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<Icon icon='heroicons:x-mark' width={20} height={20} />
|
<Icon icon='heroicons:x-mark' width={20} height={20} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className='space-y-4 px-4 pb-4'>
|
<div className='px-4 pb-4'>
|
||||||
<div>
|
{isLoadingFcrStandards ? (
|
||||||
<span className='text-sm text-gray-600'>Nama Standard</span>
|
<div className='flex justify-center py-8'>
|
||||||
<p className='font-semibold'>
|
<span className='loading loading-spinner loading-lg'></span>
|
||||||
{initialValues?.project_flock?.fcr?.name || '-'}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
) : fcrStandards.length > 0 ? (
|
||||||
<span className='text-sm text-gray-600'>FCR Standard</span>
|
<Table<FcrStandard>
|
||||||
<p className='font-semibold'>
|
data={fcrStandards}
|
||||||
{initialValues?.project_flock?.fcr?.fcr_std != null
|
columns={fcrStandardColumns}
|
||||||
? formatNumber(
|
className={{
|
||||||
initialValues?.project_flock?.fcr?.fcr_std || 0
|
tableWrapperClassName: 'overflow-x-auto',
|
||||||
)
|
tableClassName: 'w-full table-auto text-sm',
|
||||||
: '-'}
|
headerRowClassName: 'border-b border-b-gray-200',
|
||||||
|
headerColumnClassName:
|
||||||
|
'px-4 py-3 text-xs font-semibold text-gray-500 whitespace-nowrap border-l border-l-gray-200 border-r border-r-gray-200 border-t border-t-gray-200 border-gray-200 border-b-0',
|
||||||
|
bodyRowClassName:
|
||||||
|
'hover:bg-gray-50 transition-colors border-b border-gray-200 first:border-t first:border-t-gray-200 border-l border-l-gray-200 border-r border-r-gray-200',
|
||||||
|
bodyColumnClassName:
|
||||||
|
'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
|
||||||
|
paginationClassName: 'hidden',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p className='text-sm text-gray-500'>
|
||||||
|
Tidak ada data FCR standards
|
||||||
</p>
|
</p>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user