diff --git a/src/components/pages/report/sale/tab/HppPerKandangTab.tsx b/src/components/pages/report/sale/tab/HppPerKandangTab.tsx index 22d80220..df2f2ddc 100644 --- a/src/components/pages/report/sale/tab/HppPerKandangTab.tsx +++ b/src/components/pages/report/sale/tab/HppPerKandangTab.tsx @@ -40,6 +40,9 @@ const HppPerKandangTab = () => { // ===== SUBMISSION STATE ===== const [isSubmitted, setIsSubmitted] = useState(false); + // ===== VALIDATION STATE ===== + const [weightMaxError, setWeightMaxError] = useState(''); + // ===== TABLE FILTER STATE ===== const { state: tableFilterState, updateFilter } = useTableFilter({ initial: { @@ -127,8 +130,12 @@ const HppPerKandangTab = () => { const val = e.target.value; updateFilter('weight_min', val ? String(parseFloat(val) || 0) : ''); setIsSubmitted(false); + + if (weightMaxError) { + setWeightMaxError(''); + } }, - [updateFilter] + [updateFilter, weightMaxError] ); const weightMaxChangeHandler = useCallback< @@ -136,10 +143,22 @@ const HppPerKandangTab = () => { >( (e) => { const val = e.target.value; - updateFilter('weight_max', val ? String(parseFloat(val) || 0) : ''); + const weightMax = val ? parseFloat(val) || 0 : 0; + const weightMin = tableFilterState.weight_min + ? parseFloat(tableFilterState.weight_min) + : 0; + + if (weightMax < weightMin) { + setWeightMaxError('Rentang bobot max tidak boleh lebih kecil dari min'); + toast.error('Rentang bobot max tidak boleh lebih kecil dari min'); + return; + } + + setWeightMaxError(''); + updateFilter('weight_max', val ? String(weightMax) : ''); setIsSubmitted(false); }, - [updateFilter] + [updateFilter, tableFilterState.weight_min] ); const periodChangeHandler = useCallback>( @@ -792,6 +811,8 @@ const HppPerKandangTab = () => { placeholder='Masukkan bobot maximum' value={tableFilterState.weight_max} onChange={weightMaxChangeHandler} + isError={!!weightMaxError} + errorMessage={weightMaxError} /> {
-