mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 07:15:44 +00:00
Merge branch 'fix/recording' into 'development'
[FIX/FE] Fixing Recording Form See merge request mbugroup/lti-web-client!208
This commit is contained in:
@@ -79,6 +79,7 @@ import {
|
|||||||
GROWING_RECORDING_APPROVAL_LINE,
|
GROWING_RECORDING_APPROVAL_LINE,
|
||||||
LAYING_RECORDING_APPROVAL_LINE,
|
LAYING_RECORDING_APPROVAL_LINE,
|
||||||
} from '@/config/approval-line';
|
} from '@/config/approval-line';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
|
||||||
interface RecordingFormProps {
|
interface RecordingFormProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
@@ -227,7 +228,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const [, setApprovalNotes] = useState('');
|
const [, setApprovalNotes] = useState('');
|
||||||
const [recordingFormErrorMessage, setRecordingFormErrorMessage] =
|
const [recordingFormErrorMessage, setRecordingFormErrorMessage] =
|
||||||
useState('');
|
useState('');
|
||||||
const [formErrorList, setFormErrorList] = useState<string[]>([]);
|
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
const [, setNewRecordingData] = useState<Recording | null>(null);
|
const [, setNewRecordingData] = useState<Recording | null>(null);
|
||||||
const [nextDayRecording, setNextDayRecording] =
|
const [nextDayRecording, setNextDayRecording] =
|
||||||
@@ -905,10 +905,58 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
baseValues = getRecordingGrowingFormInitialValues(initialValues);
|
baseValues = getRecordingGrowingFormInitialValues(initialValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === 'add') {
|
||||||
|
baseValues.location = selectedLocation
|
||||||
|
? {
|
||||||
|
value: Number(selectedLocation.value),
|
||||||
|
label: selectedLocation.label,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
baseValues.location_id = selectedLocation
|
||||||
|
? Number(selectedLocation.value)
|
||||||
|
: 0;
|
||||||
|
baseValues.project_flock = selectedProjectFlock
|
||||||
|
? {
|
||||||
|
value: Number(selectedProjectFlock.value),
|
||||||
|
label: selectedProjectFlock.label,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
baseValues.project_flock_id = selectedProjectFlock
|
||||||
|
? Number(selectedProjectFlock.value)
|
||||||
|
: 0;
|
||||||
|
baseValues.kandang = selectedKandang
|
||||||
|
? {
|
||||||
|
value: Number(selectedKandang.value),
|
||||||
|
label: selectedKandang.label,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
baseValues.kandang_id = selectedKandang
|
||||||
|
? Number(selectedKandang.value)
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (projectFlockKandangDetail && (type === 'edit' || type === 'detail')) {
|
if (projectFlockKandangDetail && (type === 'edit' || type === 'detail')) {
|
||||||
baseValues.project_flock_kandang = {
|
baseValues = {
|
||||||
value: projectFlockKandangDetail.project_flock.id,
|
...baseValues,
|
||||||
label: projectFlockKandangDetail.project_flock.flock_name || '',
|
project_flock_kandang: {
|
||||||
|
value: projectFlockKandangDetail.project_flock?.id,
|
||||||
|
label: projectFlockKandangDetail.project_flock?.flock_name || '',
|
||||||
|
},
|
||||||
|
project_flock: {
|
||||||
|
value: projectFlockKandangDetail.project_flock?.id,
|
||||||
|
label: projectFlockKandangDetail.project_flock?.flock_name || '',
|
||||||
|
},
|
||||||
|
project_flock_id: projectFlockKandangDetail.project_flock?.id,
|
||||||
|
location: {
|
||||||
|
value: projectFlockKandangDetail.project_flock?.location?.id,
|
||||||
|
label: projectFlockKandangDetail.project_flock?.location?.name || '',
|
||||||
|
},
|
||||||
|
location_id: projectFlockKandangDetail.project_flock?.location?.id,
|
||||||
|
kandang: {
|
||||||
|
value: projectFlockKandangDetail.kandang?.id,
|
||||||
|
label: projectFlockKandangDetail.kandang?.name || '',
|
||||||
|
},
|
||||||
|
kandang_id: projectFlockKandangDetail.kandang?.id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -995,22 +1043,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleValidateForm = async () => {
|
|
||||||
const errors = await formik.validateForm();
|
|
||||||
|
|
||||||
if (Object.keys(errors).length > 0) {
|
|
||||||
const errorMessages = getUniqueFormikErrors(errors);
|
|
||||||
setFormErrorList(errorMessages);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
|
||||||
e.preventDefault();
|
|
||||||
handleValidateForm();
|
|
||||||
formik.handleSubmit(e);
|
|
||||||
};
|
|
||||||
|
|
||||||
// ===== HELPER FUNCTIONS =====
|
// ===== HELPER FUNCTIONS =====
|
||||||
const getAvailableStock = useCallback(
|
const getAvailableStock = useCallback(
|
||||||
(productWarehouseId: number) => {
|
(productWarehouseId: number) => {
|
||||||
@@ -1266,6 +1298,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
[formik, duplicateErrorShown]
|
[formik, duplicateErrorShown]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { formErrorList, handleFormSubmit, close } = useFormikErrorList(formik);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (projectFlockKandangLookup?.project_flock_kandang_id) {
|
if (projectFlockKandangLookup?.project_flock_kandang_id) {
|
||||||
const projectFlockKandangId =
|
const projectFlockKandangId =
|
||||||
@@ -1655,12 +1689,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
|
|
||||||
{/* Error List Alert */}
|
{/* Error List Alert */}
|
||||||
{formErrorList.length > 0 && (
|
{formErrorList.length > 0 && (
|
||||||
<AlertErrorList
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
formErrorList={formErrorList}
|
|
||||||
onClose={() => setFormErrorList([])}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className='text-xs text-error'>
|
||||||
|
{JSON.stringify(formik.errors)}
|
||||||
|
</div>
|
||||||
|
<div className='text-xs text-success'>
|
||||||
|
{JSON.stringify(formik.values)}
|
||||||
|
</div>
|
||||||
{/* Basic Info Card */}
|
{/* Basic Info Card */}
|
||||||
{(type === 'add' || type === 'edit') && (
|
{(type === 'add' || type === 'edit') && (
|
||||||
<Card
|
<Card
|
||||||
|
|||||||
Reference in New Issue
Block a user