mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Validate weight max is not less than min
This commit is contained in:
@@ -40,6 +40,9 @@ const HppPerKandangTab = () => {
|
|||||||
// ===== SUBMISSION STATE =====
|
// ===== SUBMISSION STATE =====
|
||||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||||
|
|
||||||
|
// ===== VALIDATION STATE =====
|
||||||
|
const [weightMaxError, setWeightMaxError] = useState<string>('');
|
||||||
|
|
||||||
// ===== TABLE FILTER STATE =====
|
// ===== TABLE FILTER STATE =====
|
||||||
const { state: tableFilterState, updateFilter } = useTableFilter({
|
const { state: tableFilterState, updateFilter } = useTableFilter({
|
||||||
initial: {
|
initial: {
|
||||||
@@ -127,8 +130,12 @@ const HppPerKandangTab = () => {
|
|||||||
const val = e.target.value;
|
const val = e.target.value;
|
||||||
updateFilter('weight_min', val ? String(parseFloat(val) || 0) : '');
|
updateFilter('weight_min', val ? String(parseFloat(val) || 0) : '');
|
||||||
setIsSubmitted(false);
|
setIsSubmitted(false);
|
||||||
|
|
||||||
|
if (weightMaxError) {
|
||||||
|
setWeightMaxError('');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[updateFilter]
|
[updateFilter, weightMaxError]
|
||||||
);
|
);
|
||||||
|
|
||||||
const weightMaxChangeHandler = useCallback<
|
const weightMaxChangeHandler = useCallback<
|
||||||
@@ -136,10 +143,22 @@ const HppPerKandangTab = () => {
|
|||||||
>(
|
>(
|
||||||
(e) => {
|
(e) => {
|
||||||
const val = e.target.value;
|
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);
|
setIsSubmitted(false);
|
||||||
},
|
},
|
||||||
[updateFilter]
|
[updateFilter, tableFilterState.weight_min]
|
||||||
);
|
);
|
||||||
|
|
||||||
const periodChangeHandler = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
const periodChangeHandler = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
||||||
@@ -792,6 +811,8 @@ const HppPerKandangTab = () => {
|
|||||||
placeholder='Masukkan bobot maximum'
|
placeholder='Masukkan bobot maximum'
|
||||||
value={tableFilterState.weight_max}
|
value={tableFilterState.weight_max}
|
||||||
onChange={weightMaxChangeHandler}
|
onChange={weightMaxChangeHandler}
|
||||||
|
isError={!!weightMaxError}
|
||||||
|
errorMessage={weightMaxError}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<DateInput
|
<DateInput
|
||||||
@@ -818,7 +839,11 @@ const HppPerKandangTab = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-4 flex justify-end gap-2 [&_button]:px-4'>
|
<div className='mt-4 flex justify-end gap-2 [&_button]:px-4'>
|
||||||
<Button color='primary' onClick={handleSubmit}>
|
<Button
|
||||||
|
color='primary'
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={!!weightMaxError}
|
||||||
|
>
|
||||||
<Icon icon='heroicons:magnifying-glass' width={20} height={20} />
|
<Icon icon='heroicons:magnifying-glass' width={20} height={20} />
|
||||||
Cari
|
Cari
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user