diff --git a/client/src/api/upload/index.js b/client/src/api/upload/index.js index dacf459..ac603c4 100644 --- a/client/src/api/upload/index.js +++ b/client/src/api/upload/index.js @@ -1,4 +1,5 @@ -import { resolve } from "../../helpers/resolve-response"; +import { resolve } from "@helpers/resolve-response"; +import axios from "@api"; export async function uploadSignature(id, type, file) { const authResponse = await resolve( @@ -15,3 +16,10 @@ export async function uploadSignature(id, type, file) { ); return authResponse.data; } + +export async function removeDocumentSignature(id, type) { + const authResponse = await resolve( + axios.delete(`/upload/signature?id=${id}&type=${type}`), + ); + return authResponse.data; +} diff --git a/client/src/redux/thunks/upload-thunk.js b/client/src/redux/thunks/upload-thunk.js index 780ccd3..020b4e5 100644 --- a/client/src/redux/thunks/upload-thunk.js +++ b/client/src/redux/thunks/upload-thunk.js @@ -1,4 +1,4 @@ -import { uploadSignature } from "@/api/upload"; +import { uploadSignature, removeDocumentSignature } from "@/api/upload"; import { createAsyncThunk } from "@reduxjs/toolkit"; export const uploadSignatureThunk = createAsyncThunk( @@ -12,3 +12,16 @@ export const uploadSignatureThunk = createAsyncThunk( } }, ); + +export const deleteDocumentSignatureThunk = createAsyncThunk( + "signature/delete", + async ({ id, endpoint, onSuccess }) => { + try { + const response = await removeDocumentSignature(id, endpoint); + if (onSuccess) onSuccess(); + return response; + } catch (error) { + throw error; + } + }, +); diff --git a/client/src/routes/sub-routes/create/save-and-check/index.jsx b/client/src/routes/sub-routes/create/save-and-check/index.jsx index c1524d7..c6bb612 100644 --- a/client/src/routes/sub-routes/create/save-and-check/index.jsx +++ b/client/src/routes/sub-routes/create/save-and-check/index.jsx @@ -2,11 +2,15 @@ import { EMPTY_DOCUMENT, SIMILAR_DOCUMENT_TYPES } from "@/constants/document"; import { removeDataFromLocalStorage } from "@/helpers/localStorageActions"; import { getDocumentsLoading } from "@/redux/selectors/documents"; import { createDocumentThunk } from "@/redux/thunks/documents-thunks"; -import { updateDocumentThunk } from "@/redux/thunks/single-document-thunk"; +import { + fetchSingleDocumentByIdThunk, + updateDocumentThunk, +} from "@/redux/thunks/single-document-thunk"; import { Badge, Button, Descriptions, message } from "antd"; import { useDispatch, useSelector } from "react-redux"; import ReactToPrint from "react-to-print"; -import { useCallback, useRef, useState } from "react"; +import { useCallback, useRef } from "react"; +import { deleteDocumentSignatureThunk } from "@thunks/upload-thunk"; import { DownloadOutlined } from "@ant-design/icons"; import AdrCertificate from "@/components/documents/adr"; import DriverCertificate from "@/components/documents/driver"; @@ -14,6 +18,7 @@ import { removeCurrentDocumentId } from "@/redux/slices/documents"; import { removeCurrentDocument } from "@/redux/slices/single-document"; import { updateUI } from "@/helpers/update-ui"; import { checkCertificateStatus } from "@/helpers/check-certificate-status"; +import { fetchDocumentStatusDataThunk } from "@/redux/thunks/document-status"; const SaveAndCheck = ({ document, @@ -154,6 +159,18 @@ const SaveAndCheck = ({ message.success("Havola nusxalandi"); }; + const handleRemoveSignature = () => { + dispatch( + deleteDocumentSignatureThunk({ + id: document._id, + endpoint: documentType, + onSuccess: () => { + message.success("Imzo o'chirildi"); + }, + }), + ); + }; + return (
@@ -196,6 +213,16 @@ const SaveAndCheck = ({ > Imzo qo'yish uchun havola + {document?.signature && ( + + )}
{actionType && (