import JoditEditor from "jodit-react"; import dayjs from "dayjs"; import { Button, Collapse, DatePicker, Form, Input, InputNumber, Modal, Result, Row, Select, Spin, Steps, Typography, Drawer, Upload, List, } from "antd"; import { UploadOutlined } from '@ant-design/icons'; import useAppointmentFormModal from "./useAppointmentFormModal.js"; import useAppointmentFormModalUI from "./useAppointmentFormModalUI.js"; import LoadingIndicator from "../../Widgets/LoadingIndicator/LoadingIndicator.jsx"; import {useMemo, useCallback, useRef} from "react"; const AppointmentFormModal = () => { const appointmentFormModalData = useAppointmentFormModal(); const appointmentFormModalUI = useAppointmentFormModalUI( appointmentFormModalData.createAppointment, appointmentFormModalData.patients, appointmentFormModalData.cancelAppointment, appointmentFormModalData.useGetByPatientIdQuery ); const cursorPositionRef = useRef(null); const saveCursorPosition = useCallback(() => { if (appointmentFormModalUI.editor.current) { const editor = appointmentFormModalUI.editor.current.editor; const selection = editor.selection; if (selection) { cursorPositionRef.current = selection.getBookmark(); } } }, [appointmentFormModalUI.editor]); const restoreCursorPosition = useCallback(() => { if (appointmentFormModalUI.editor.current && cursorPositionRef.current) { const editor = appointmentFormModalUI.editor.current.editor; const selection = editor.selection; if (selection && cursorPositionRef.current) { selection.moveToBookmark(cursorPositionRef.current); } } }, [appointmentFormModalUI.editor]); const handleEditorBlur = useCallback( (newContent) => { saveCursorPosition(); appointmentFormModalUI.form.setFieldsValue({results: newContent}); setTimeout(restoreCursorPosition, 0); }, [appointmentFormModalUI.form, saveCursorPosition, restoreCursorPosition] ); const patientsItems = useMemo(() => appointmentFormModalUI.filteredPatients.map((patient) => ({ key: patient.id, label: `${patient.last_name} ${patient.first_name} (${appointmentFormModalUI.getDateString(patient.birthday)})`, children: (

Пациент: {patient.last_name} {patient.first_name}

Дата рождения: {appointmentFormModalUI.getDateString(patient.birthday)}

Диагноз: {patient.diagnosis || "Не указан"}

Email: {patient.email || "Не указан"}

Телефон: {patient.phone || ""}

), })), [appointmentFormModalUI.filteredPatients, appointmentFormModalUI.getDateString, appointmentFormModalUI.setSelectedPatient] ); const SelectPatientStep = useMemo(() => { return appointmentFormModalUI.selectedPatient ? (
{appointmentFormModalUI.selectedPatient.last_name} {appointmentFormModalUI.selectedPatient.first_name}

Дата рождения: {appointmentFormModalUI.getSelectedPatientBirthdayString()}

Email: {appointmentFormModalUI.selectedPatient.email || "Не указан"}

Телефон: {appointmentFormModalUI.selectedPatient.phone || ""}

) : ( <>
); }, [ appointmentFormModalUI.selectedPatient, appointmentFormModalUI.searchPatientString, appointmentFormModalUI.blockStepStyle, appointmentFormModalUI.chooseContainerStyle, appointmentFormModalUI.searchInputStyle, appointmentFormModalUI.getSelectedPatientBirthdayString, appointmentFormModalUI.resetPatient, appointmentFormModalUI.handleSetSearchPatientString, patientsItems, ]); const AppointmentStep = useMemo(() => { return (
{ appointmentFormModalUI.handleAddFile(file); return false; // Prevent auto-upload }} onRemove={(file) => appointmentFormModalUI.handleRemoveFile(file)} accept=".pdf,.doc,.docx,.jpg,.jpeg,.png" multiple >
); }, [ appointmentFormModalUI.form, appointmentFormModalUI.selectedPatient, appointmentFormModalUI.showDrawer, appointmentFormModalUI.editor, appointmentFormModalUI.draftFiles, appointmentFormModalUI.handleAddFile, appointmentFormModalUI.handleRemoveFile, appointmentFormModalData.appointmentTypes, appointmentFormModalUI.joditConfig, handleEditorBlur, ]); const ConfirmStep = useMemo(() => { const values = appointmentFormModalUI.form.getFieldsValue(); const patient = appointmentFormModalData.patients.find((p) => p.id === values.patient_id); const appointmentType = appointmentFormModalData.appointmentTypes.find((t) => t.id === values.type_id); return (
Подтверждение

Пациент: {patient ? `${patient.last_name} ${patient.first_name}` : "Не указан"}

Тип приема: {appointmentType ? appointmentType.title : "Не указан"}

Время приема:{" "} {values.appointment_datetime ? dayjs(values.appointment_datetime).format("DD.MM.YYYY HH:mm") : "Не указано"}

Дней до следующего приема: {values.days_until_the_next_appointment || "Не указано"}

Результаты приема:

Прикрепленные файлы:

{appointmentFormModalUI.draftFiles.length > 0 ? ( ( {file.name} ({(file.size / 1024 / 1024).toFixed(2)} MB) )} /> ) : (

Файлы не прикреплены

)}
); }, [appointmentFormModalUI.form, appointmentFormModalData.patients, appointmentFormModalData.appointmentTypes, appointmentFormModalUI.draftFiles, appointmentFormModalUI.blockStepStyle]); const steps = useMemo(() => [ { title: "Выбор пациента", content: SelectPatientStep, }, { title: "Заполнение информации о приеме", content: AppointmentStep, }, { title: "Подтверждение", content: ConfirmStep, }, ], [SelectPatientStep, AppointmentStep, ConfirmStep]); if (appointmentFormModalData.isError) { return ( ); } return ( <> {appointmentFormModalData.isLoading ? ( ) : ( <> {appointmentFormModalData.isLoading ? (
) : (
{steps[appointmentFormModalUI.currentStep].content}
)} {!appointmentFormModalUI.screenXS && ( )}
({ key: appointment.id, label: `Прием ${dayjs(appointment.appointment_datetime).format("DD.MM.YYYY HH:mm")}`, children:
, }))} /> )} ); }; export default AppointmentFormModal;