From 6022ff2daefed6f73c820d07ca1317a88e5181e3 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Tue, 18 Nov 2025 10:48:41 +0700 Subject: [PATCH] feat(FE-170,174,175): add tooltip for grading button based on consumable eggs validation --- .../recording/form/RecordingForm.tsx | 233 ++++++++++++------ 1 file changed, 153 insertions(+), 80 deletions(-) diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 4a5c9760..e1f2a3b4 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -15,6 +15,7 @@ import SelectInput, { OptionType } from '@/components/input/SelectInput'; import CheckboxInput from '@/components/input/CheckboxInput'; import ConfirmationModal from '@/components/modal/ConfirmationModal'; import { useModal } from '@/components/Modal'; +import Tooltip from '@/components/Tooltip'; import { ProjectFlockKandangApi, @@ -950,6 +951,54 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { ); }, [formik.values.stocks, getStockUsageError, type]); + const hasConsumableEggs = useMemo(() => { + if (!isLayingCategory) return false; + const layingValues = formik.values as RecordingLayingFormValues; + if (!layingValues.eggs || layingValues.eggs.length === 0) return false; + + return layingValues.eggs.some((egg) => { + if (!egg.product_warehouse_id || Number(egg.qty) <= 0) return false; + + const product = eggProducts.find( + (opt) => opt.value === egg.product_warehouse_id + ); + + if (!product) return false; + + const productName = product.label.toLowerCase(); + return ( + productName.includes('konsumsi') && + productName.includes('baik') && + Number(egg.qty) > 0 + ); + }); + }, [isLayingCategory, formik.values, eggProducts]); + + const hasConsumableEggsInRecording = useCallback((recording?: Recording) => { + if (!recording || !recording.eggs || recording.eggs.length === 0) + return false; + + return recording.eggs.some((egg) => { + if (!egg.product_warehouse || !egg.product_warehouse.product) + return false; + if (Number(egg.qty) <= 0) return false; + + const productName = egg.product_warehouse.product.name.toLowerCase(); + return ( + productName.includes('konsumsi') && + productName.includes('baik') && + Number(egg.qty) > 0 + ); + }); + }, []); + + const hasConsumableEggsInCurrentRecording = useMemo(() => { + return ( + hasConsumableEggsInRecording(initialValues) || + hasConsumableEggsInRecording(newRecordingData || undefined) + ); + }, [initialValues, newRecordingData, hasConsumableEggsInRecording]); + const isRepeaterInputError = ( arrayName: 'body_weights' | 'stocks' | 'depletions' | 'eggs', column: string, @@ -2606,29 +2655,42 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{type === 'detail' && isLayingCategory && ( - + + )} {type === 'edit' && ( @@ -2683,66 +2745,77 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { Submit {isLayingCategory && ( - + + )} )}