mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE): Use local state for record date and disable
reinitialization
This commit is contained in:
@@ -197,6 +197,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
// ===== STATE MANAGEMENT =====
|
// ===== STATE MANAGEMENT =====
|
||||||
|
const [selectedRecordDate, setSelectedRecordDate] = useState<string>(
|
||||||
|
initialValues?.record_datetime
|
||||||
|
? new Date(initialValues.record_datetime).toISOString().split('T')[0]
|
||||||
|
: new Date().toISOString().split('T')[0]
|
||||||
|
);
|
||||||
const [selectedStocks, setSelectedStocks] = useState<number[]>([]);
|
const [selectedStocks, setSelectedStocks] = useState<number[]>([]);
|
||||||
const [selectedDepletions, setSelectedDepletions] = useState<number[]>([]);
|
const [selectedDepletions, setSelectedDepletions] = useState<number[]>([]);
|
||||||
const [selectedEggs, setSelectedEggs] = useState<number[]>([]);
|
const [selectedEggs, setSelectedEggs] = useState<number[]>([]);
|
||||||
@@ -911,6 +916,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
baseValues = getRecordingGrowingFormInitialValues(initialValues);
|
baseValues = getRecordingGrowingFormInitialValues(initialValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseValues.record_date = selectedRecordDate;
|
||||||
|
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
baseValues.location = selectedLocation
|
baseValues.location = selectedLocation
|
||||||
? {
|
? {
|
||||||
@@ -967,13 +974,22 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return baseValues;
|
return baseValues;
|
||||||
}, [initialValues, isLayingCategory, projectFlockKandangDetail, type]);
|
}, [
|
||||||
|
initialValues,
|
||||||
|
isLayingCategory,
|
||||||
|
projectFlockKandangDetail,
|
||||||
|
type,
|
||||||
|
selectedRecordDate,
|
||||||
|
selectedLocation,
|
||||||
|
selectedProjectFlock,
|
||||||
|
selectedKandang,
|
||||||
|
]);
|
||||||
|
|
||||||
const formik = useFormik<
|
const formik = useFormik<
|
||||||
RecordingGrowingFormValues | RecordingLayingFormValues
|
RecordingGrowingFormValues | RecordingLayingFormValues
|
||||||
>({
|
>({
|
||||||
initialValues: formikInitialValues,
|
initialValues: formikInitialValues,
|
||||||
enableReinitialize: true,
|
enableReinitialize: false,
|
||||||
validationSchema: (() => {
|
validationSchema: (() => {
|
||||||
let schema;
|
let schema;
|
||||||
if (isLayingCategory) {
|
if (isLayingCategory) {
|
||||||
@@ -1333,6 +1349,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const newDate = e.target.value;
|
const newDate = e.target.value;
|
||||||
formik.setFieldValue('record_date', newDate);
|
formik.setFieldValue('record_date', newDate);
|
||||||
|
setSelectedRecordDate(newDate);
|
||||||
setCurrentRecordDate(newDate);
|
setCurrentRecordDate(newDate);
|
||||||
if (duplicateErrorShown) {
|
if (duplicateErrorShown) {
|
||||||
toast.dismiss();
|
toast.dismiss();
|
||||||
|
|||||||
Reference in New Issue
Block a user