mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat(FE): adding alert errors message for project flock and fixing bug approval status in chickin
This commit is contained in:
@@ -64,9 +64,9 @@ export const ProjectFlockBudgetsSchema: Yup.ObjectSchema<ProjectFlockBudgetsSche
|
||||
.min(1, 'Harga minimal 1!')
|
||||
.required('Harga wajib diisi!'),
|
||||
total_price: Yup.number()
|
||||
.typeError('Harga harus berupa angka!')
|
||||
.min(1, 'Harga minimal 1!')
|
||||
.required('Harga wajib diisi!'),
|
||||
.typeError('Total Harga harus berupa angka!')
|
||||
.min(1, 'Total Harga minimal 1!')
|
||||
.required('Total Harga wajib diisi!'),
|
||||
});
|
||||
|
||||
export const ProjectFlockFormSchema: Yup.ObjectSchema<ProjectFlockFormSchemaType> =
|
||||
|
||||
@@ -6,6 +6,8 @@ import SelectInput, {
|
||||
useSelect,
|
||||
} from '@/components/input/SelectInput';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
import { getUniqueFormikErrors } from '@/lib/formik-helper';
|
||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||
import {
|
||||
AreaApi,
|
||||
FcrApi,
|
||||
@@ -64,6 +66,7 @@ const ProjectFlockForm = ({
|
||||
|
||||
const [projectFlockFormErrorMessage, setProjectFlockFormErrorMessage] =
|
||||
useState('');
|
||||
const [formErrorList, setFormErrorList] = useState<string[]>([]);
|
||||
const [selectedArea, setSelectedArea] = useState('');
|
||||
const [selectedLocation, setSelectedLocation] = useState('');
|
||||
const [selectedCategory, setSelectedCategory] = useState('');
|
||||
@@ -134,6 +137,7 @@ const ProjectFlockForm = ({
|
||||
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||
search: '',
|
||||
location_id: selectedLocation == '' ? '0' : selectedLocation,
|
||||
limit: 'limit',
|
||||
}).toString()}`;
|
||||
const {
|
||||
data: kandang,
|
||||
@@ -638,6 +642,17 @@ const ProjectFlockForm = ({
|
||||
return !isNonstockAlreadyInBudgets;
|
||||
});
|
||||
|
||||
const handleValidateForm = async () => {
|
||||
const errors = await formik.validateForm();
|
||||
|
||||
if (Object.keys(errors).length > 0) {
|
||||
// Parse and display errors
|
||||
const errorMessages = getUniqueFormikErrors(errors);
|
||||
setFormErrorList(errorMessages);
|
||||
return; // Stop submission
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className='w-full'>
|
||||
@@ -697,7 +712,11 @@ const ProjectFlockForm = ({
|
||||
|
||||
<form
|
||||
className='w-auto h-auto'
|
||||
onSubmit={formik.handleSubmit}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleValidateForm();
|
||||
formik.handleSubmit(e);
|
||||
}}
|
||||
onReset={formik.handleReset}
|
||||
>
|
||||
{/* Form Informasi Umum */}
|
||||
@@ -1063,6 +1082,14 @@ const ProjectFlockForm = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error List Alert */}
|
||||
{formErrorList.length > 0 && (
|
||||
<AlertErrorList
|
||||
formErrorList={formErrorList}
|
||||
onClose={() => setFormErrorList([])}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className='flex flex-row justify-center gap-2 flex-wrap my-6 px-4'>
|
||||
{formType !== 'detail' && (
|
||||
<RequirePermission
|
||||
|
||||
Reference in New Issue
Block a user