diff --git a/src/components/pages/production/recording/grading/form/GradingForm.tsx b/src/components/pages/production/recording/grading/form/GradingForm.tsx index 5a8fb1b3..b986a555 100644 --- a/src/components/pages/production/recording/grading/form/GradingForm.tsx +++ b/src/components/pages/production/recording/grading/form/GradingForm.tsx @@ -307,6 +307,21 @@ const GradingForm = ({ type = 'add', initialValues }: GradingFormProps) => { setFormSteps(steps); }, []); + // Show toast when grading exceeds available eggs + useEffect(() => { + if (isGradingExceedsAvailable && currentGradingTotal > 0) { + toast.error( + `Total grading (${currentGradingTotal}) melebihi telur yang tersedia (${totalKonsumsiBaikEggs})!`, + { + id: 'grading-exceeds', + duration: 3000, + } + ); + } else { + toast.dismiss('grading-exceeds'); + } + }, [isGradingExceedsAvailable, currentGradingTotal, totalKonsumsiBaikEggs]); + useEffect(() => { if (formik.values.eggs_grading && formik.values.eggs_grading.length === 0) { let recordingEggId: number | undefined = initialValues?.id; @@ -404,52 +419,113 @@ const GradingForm = ({ type = 'add', initialValues }: GradingFormProps) => {
- {type === 'detail' && initialValues ? ( - <> - Recording Egg ID#{initialValues.id} - - ) : ( - <> - Recording Egg ID# - {formik.values.eggs_grading?.[0]?.recording_egg_id || '-'} - - )} + {/* Recording Egg ID */} +
+
+
+

Recording ID

+

+ #{type === 'detail' && initialValues ? + initialValues.id : + (formik.values.eggs_grading?.[0]?.recording_egg_id || '-') + } +

+
+
+ +
+
+
{/* Total Telur Konsumsi Baik Info */} -
- - Total Telur Konsumsi Baik - -
-

- {totalKonsumsiBaikEggs} -

- telur -
-
- Total yang digrading: - - {currentGradingTotal} / {totalKonsumsiBaikEggs} - -
- {isGradingExceedsAvailable && ( -
- ⚠️ Total grading melebihi available telur! +
+
+
+

+ Total Telur Konsumsi Baik +

+
+

+ {totalKonsumsiBaikEggs} +

+ + telur + +
- )} +
+ +
+
+ + {/* Progress Bar */} +
+
+ Total yang digrading: + + {currentGradingTotal} / {totalKonsumsiBaikEggs} + +
+
+
+
+ {isGradingExceedsAvailable && ( +
+ + Melebihi batas tersedia +
+ )} +
@@ -596,7 +672,7 @@ const GradingForm = ({ type = 'add', initialValues }: GradingFormProps) => { isRepeaterInputError('eggs_grading', 'qty', idx) .errorMessage || (isGradingExceedsAvailable - ? `Total grading melebihi available telur (${totalKonsumsiBaikEggs})` + ? `Total grading melebihi telur yang tersedia (${totalKonsumsiBaikEggs})` : undefined) } readOnly={type === 'detail'} @@ -723,12 +799,6 @@ const GradingForm = ({ type = 'add', initialValues }: GradingFormProps) => { > Submit - {isGradingExceedsAvailable && ( -
- Total grading ({currentGradingTotal}) melebihi available - telur ({totalKonsumsiBaikEggs}) -
- )}
)}