diff --git a/web-app/src/Api/appointmentFilesApi.js b/web-app/src/Api/appointmentFilesApi.js index cfe7274..17fd2e1 100644 --- a/web-app/src/Api/appointmentFilesApi.js +++ b/web-app/src/Api/appointmentFilesApi.js @@ -1,11 +1,33 @@ import { createApi } from "@reduxjs/toolkit/query/react"; import { baseQueryWithAuth } from "./baseQuery.js"; +import { isPlainObject } from "@reduxjs/toolkit"; export const appointmentFilesApi = createApi({ reducerPath: 'appointmentFilesApi', baseQuery: baseQueryWithAuth, tagTypes: ['AppointmentFile'], endpoints: (builder) => ({ + getAppointmentFiles: builder.query({ + query: (appointmentId) => { + console.log(`Fetching files for appointment ID: ${appointmentId}`); + return `/appointment_files/${appointmentId}/`; + }, + providesTags: ['AppointmentFile'], + refetchOnMountOrArgChange: 5, + }), + downloadAppointmentFile: builder.mutation({ + query: (fileId) => ({ + url: `/appointment_files/${fileId}/file/`, + method: 'GET', + }), + }), + deleteAppointmentFile: builder.mutation({ + query: (fileId) => ({ + url: `/appointment_files/${fileId}/`, + method: 'DELETE', + }), + invalidatesTags: ['AppointmentFile'], + }), uploadAppointmentFile: builder.mutation({ query: ({ appointmentId, file }) => { if (!(file instanceof File)) { @@ -24,11 +46,20 @@ export const appointmentFilesApi = createApi({ invalidatesTags: ['AppointmentFile'], }), }), + middleware: (defaultMiddleware) => + defaultMiddleware({ + serializableCheck: { + isSerializable: (value) => { + if (value instanceof Blob) return true; // Игнорируем Blob + return isPlainObject(value) || typeof value !== 'object'; + }, + }, + }), }); export const { useGetAppointmentFilesQuery, - useDownloadAppointmentFileQuery, - useUploadAppointmentFileMutation, + useDownloadAppointmentFileMutation, useDeleteAppointmentFileMutation, + useUploadAppointmentFileMutation, } = appointmentFilesApi; \ No newline at end of file diff --git a/web-app/src/Components/Widgets/AppointmentViewModal/AppointmentViewModal.jsx b/web-app/src/Components/Widgets/AppointmentViewModal/AppointmentViewModal.jsx index e54fb91..d772052 100644 --- a/web-app/src/Components/Widgets/AppointmentViewModal/AppointmentViewModal.jsx +++ b/web-app/src/Components/Widgets/AppointmentViewModal/AppointmentViewModal.jsx @@ -1,4 +1,4 @@ -import {Button, Modal, Row, Typography} from "antd"; +import { Button, Modal, Row, Typography, Spin } from "antd"; import useAppointmentViewUI from "./useAppointmentViewUI.js"; const AppointmentViewModal = () => { @@ -16,6 +16,10 @@ const AppointmentViewModal = () => { getPatientField, getResults, onCancel, + files, + isFilesLoading, + downloadingFiles, + downloadFile, } = useAppointmentViewUI(); if (!selectedAppointment) { @@ -63,8 +67,30 @@ const AppointmentViewModal = () => { {labels.results}

+

+ {labels.files} +

+ {isFilesLoading ? ( + + ) : files.length > 0 ? ( + files.map((file) => ( +
+ {file.file_title || labels.notSpecified} + +
+ )) + ) : ( +

{labels.noFiles}

+ )}