refactor: Обновление логики сброса форм в модальных окнах
Добавлен метод resetForm для унификации сброса состояний форм.
This commit is contained in:
parent
c9c2919577
commit
17d877111c
@ -204,6 +204,15 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
|
|||||||
form.setFieldsValue({patient_id: undefined});
|
form.setFieldsValue({patient_id: undefined});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
form.resetFields();
|
||||||
|
setSelectedPatient(null);
|
||||||
|
setCurrentStep(0);
|
||||||
|
setSearchPatientString("");
|
||||||
|
setFormValues({});
|
||||||
|
setIsDrawerVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
const handleSetAppointmentDate = (date) => setAppointmentDate(date);
|
const handleSetAppointmentDate = (date) => setAppointmentDate(date);
|
||||||
const modalWidth = useMemo(() => (screenXS ? 700 : "90%"), [screenXS]);
|
const modalWidth = useMemo(() => (screenXS ? 700 : "90%"), [screenXS]);
|
||||||
|
|
||||||
@ -290,10 +299,7 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
|
|||||||
});
|
});
|
||||||
|
|
||||||
dispatch(closeModal());
|
dispatch(closeModal());
|
||||||
form.resetFields();
|
resetForm();
|
||||||
setSelectedPatient(null);
|
|
||||||
setCurrentStep(0);
|
|
||||||
setFormValues({});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notification.error({
|
notification.error({
|
||||||
message: "Ошибка",
|
message: "Ошибка",
|
||||||
@ -316,12 +322,7 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
form.resetFields();
|
resetForm();
|
||||||
setSelectedPatient(null);
|
|
||||||
setCurrentStep(0);
|
|
||||||
setSearchPatientString("");
|
|
||||||
setFormValues({});
|
|
||||||
setIsDrawerVisible(false);
|
|
||||||
dispatch(closeModal());
|
dispatch(closeModal());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,12 @@ const useScheduledAppointmentFormModalUI = (patients, createScheduledAppointment
|
|||||||
const [selectedDateTime, setSelectedDateTime] = useState(dayjs(new Date()).add(1, 'day'));
|
const [selectedDateTime, setSelectedDateTime] = useState(dayjs(new Date()).add(1, 'day'));
|
||||||
const [selectedAppointmentType, setSelectedAppointmentType] = useState(null);
|
const [selectedAppointmentType, setSelectedAppointmentType] = useState(null);
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
setSelectedPatient(null);
|
||||||
|
setSelectedDateTime(dayjs(new Date()).add(1, 'day'));
|
||||||
|
setSelectedAppointmentType(null);
|
||||||
|
};
|
||||||
|
|
||||||
const handleCreateScheduledAppointment = async () => {
|
const handleCreateScheduledAppointment = async () => {
|
||||||
try {
|
try {
|
||||||
const data = {
|
const data = {
|
||||||
@ -32,9 +38,7 @@ const useScheduledAppointmentFormModalUI = (patients, createScheduledAppointment
|
|||||||
description: 'Прием успешно запланирован.',
|
description: 'Прием успешно запланирован.',
|
||||||
});
|
});
|
||||||
|
|
||||||
setSelectedPatient(null);
|
resetForm();
|
||||||
setSelectedDateTime(dayjs(new Date()).add(1, 'day'));
|
|
||||||
setSelectedAppointmentType(null);
|
|
||||||
|
|
||||||
dispatch(closeScheduledModal());
|
dispatch(closeScheduledModal());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -83,6 +87,7 @@ const useScheduledAppointmentFormModalUI = (patients, createScheduledAppointment
|
|||||||
const modalWidth = 700;
|
const modalWidth = 700;
|
||||||
|
|
||||||
const handleCancelModal = () => {
|
const handleCancelModal = () => {
|
||||||
|
resetForm();
|
||||||
dispatch(closeScheduledModal());
|
dispatch(closeScheduledModal());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user