убрал редактирование приема

This commit is contained in:
Андрей Дувакин 2025-06-01 17:24:41 +05:00
parent 6add3821c7
commit 2a1f6a9989
3 changed files with 29 additions and 55 deletions

View File

@ -1,2 +1,9 @@
import {ComponentPreviews, useInitial} from "../dev/index.js"; import {StrictMode} from 'react'
import {DevSupport} from "@react-buddy/ide-toolbox"; import {createRoot} from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App/>
</StrictMode>
)

View File

@ -89,19 +89,9 @@ const AppointmentFormModal = ({onCancel}) => {
<Form <Form
form={appointmentFormModalUI.form} form={appointmentFormModalUI.form}
onFinish={appointmentFormModalUI.handleOk} onFinish={appointmentFormModalUI.handleOk}
initialValues={ initialValues={{
appointmentFormModalUI.selectedAppointment patient_id: appointmentFormModalUI.selectedPatient?.id,
? { }}
patient_id: appointmentFormModalUI.selectedAppointment.patient_id,
type_id: appointmentFormModalUI.selectedAppointment.type_id,
appointment_datetime: appointmentFormModalUI.appo,
days_until_the_next_appointment: appointmentFormModalUI.selectedAppointment.days_until_the_next_appointment,
results: appointmentFormModalUI.selectedAppointment.results,
}
: {
patient_id: appointmentFormModalUI.selectedPatient?.id,
}
}
layout="vertical" layout="vertical"
> >
<Form.Item <Form.Item
@ -205,7 +195,7 @@ const AppointmentFormModal = ({onCancel}) => {
<LoadingIndicator/> <LoadingIndicator/>
) : ( ) : (
<Modal <Modal
title={appointmentFormModalUI.selectedAppointment ? "Редактировать прием" : "Создать прием"} title={"Создать прием"}
open={appointmentFormModalUI.modalVisible} open={appointmentFormModalUI.modalVisible}
onCancel={appointmentFormModalUI.handleCancel} onCancel={appointmentFormModalUI.handleCancel}
footer={null} footer={null}

View File

@ -10,7 +10,7 @@ const {useBreakpoint} = Grid;
const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointment, patients) => { const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointment, patients) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const {modalVisible, selectedAppointment} = useSelector(state => state.appointmentsUI); const {modalVisible} = useSelector(state => state.appointmentsUI);
const [form] = Form.useForm(); const [form] = Form.useForm();
const screens = useBreakpoint(); const screens = useBreakpoint();
@ -52,26 +52,12 @@ const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointmen
setCurrentStep(0); setCurrentStep(0);
setSearchPatientString(""); setSearchPatientString("");
setFormValues({}); setFormValues({});
if (selectedAppointment) {
const patient = appointments.find(p => p.id === selectedAppointment.patient_id); form.setFieldsValue({
setSelectedPatient(patient); appointment_datetime: dayjs(new Date()),
setCurrentStep(1); })
form.setFieldsValue({
patient_id: selectedAppointment.patient_id,
type_id: selectedAppointment.type_id,
appointment_datetime: selectedAppointment.appointment_datetime
? dayjs(selectedAppointment.appointment_datetime)
: dayjs(new Date()),
days_until_the_next_appointment: selectedAppointment.days_until_the_next_appointment,
results: selectedAppointment.results,
});
} else {
form.setFieldsValue({
appointment_datetime: dayjs(new Date()),
})
}
} }
}, [modalVisible, selectedAppointment, form, appointments]); }, [modalVisible, form, appointments]);
const handleResultsChange = (newContent) => { const handleResultsChange = (newContent) => {
setResults(newContent); setResults(newContent);
@ -114,10 +100,10 @@ const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointmen
const values = await form.validateFields(); const values = await form.validateFields();
setFormValues(values); setFormValues(values);
setCurrentStep(2); setCurrentStep(2);
} catch (_) { } catch (error) {
notification.error({ notification.error({
message: 'Ошибка валидации', message: 'Ошибка валидации',
description: 'Пожалуйста, заполните все обязательные поля.', description: error.message || 'Пожалуйста, заполните все обязательные поля.',
placement: 'topRight', placement: 'topRight',
}); });
} }
@ -138,7 +124,6 @@ const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointmen
const appointmentTime = values.appointment_datetime; const appointmentTime = values.appointment_datetime;
const hasConflict = appointments.some(app => const hasConflict = appointments.some(app =>
app.id !== selectedAppointment?.id &&
dayjs(app.appointment_datetime).isSame(appointmentTime, 'minute') dayjs(app.appointment_datetime).isSame(appointmentTime, 'minute')
); );
@ -159,21 +144,13 @@ const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointmen
results: results, results: results,
}; };
if (selectedAppointment) {
await updateAppointment({id: selectedAppointment.id, data}).unwrap(); await createAppointment(data).unwrap();
notification.success({ notification.success({
message: 'Прием обновлен', message: 'Прием создан',
description: 'Прием успешно обновлен.', description: 'Прием успешно создан.',
placement: 'topRight', placement: 'topRight',
}); });
} else {
await createAppointment(data).unwrap();
notification.success({
message: 'Прием создан',
description: 'Прием успешно создан.',
placement: 'topRight',
});
}
dispatch(closeModal()); dispatch(closeModal());
form.resetFields(); form.resetFields();
@ -200,7 +177,7 @@ const useAppointmentFormModalUI = (onCancel, createAppointment, updateAppointmen
const disableBackButton = currentStep === 0; const disableBackButton = currentStep === 0;
const disableNextButton = currentStep === 0 && !selectedPatient; const disableNextButton = currentStep === 0 && !selectedPatient;
const nextButtonText = currentStep === 2 ? (selectedAppointment ? 'Сохранить' : 'Создать') : 'Далее'; const nextButtonText = currentStep === 2 ? 'Создать' : 'Далее';
return { return {
form, form,