Skip to content

Commit 4bda90d

Browse files
feat: added delete functionality to signature
1 parent d5a1c14 commit 4bda90d

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

Diff for: client/src/api/upload/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { resolve } from "../../helpers/resolve-response";
1+
import { resolve } from "@helpers/resolve-response";
2+
import axios from "@api";
23

34
export async function uploadSignature(id, type, file) {
45
const authResponse = await resolve(
@@ -15,3 +16,10 @@ export async function uploadSignature(id, type, file) {
1516
);
1617
return authResponse.data;
1718
}
19+
20+
export async function removeDocumentSignature(id, type) {
21+
const authResponse = await resolve(
22+
axios.delete(`/upload/signature?id=${id}&type=${type}`),
23+
);
24+
return authResponse.data;
25+
}

Diff for: client/src/redux/thunks/upload-thunk.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { uploadSignature } from "@/api/upload";
1+
import { uploadSignature, removeDocumentSignature } from "@/api/upload";
22
import { createAsyncThunk } from "@reduxjs/toolkit";
33

44
export const uploadSignatureThunk = createAsyncThunk(
@@ -12,3 +12,16 @@ export const uploadSignatureThunk = createAsyncThunk(
1212
}
1313
},
1414
);
15+
16+
export const deleteDocumentSignatureThunk = createAsyncThunk(
17+
"signature/delete",
18+
async ({ id, endpoint, onSuccess }) => {
19+
try {
20+
const response = await removeDocumentSignature(id, endpoint);
21+
if (onSuccess) onSuccess();
22+
return response;
23+
} catch (error) {
24+
throw error;
25+
}
26+
},
27+
);

Diff for: client/src/routes/sub-routes/create/save-and-check/index.jsx

+29-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import { EMPTY_DOCUMENT, SIMILAR_DOCUMENT_TYPES } from "@/constants/document";
22
import { removeDataFromLocalStorage } from "@/helpers/localStorageActions";
33
import { getDocumentsLoading } from "@/redux/selectors/documents";
44
import { createDocumentThunk } from "@/redux/thunks/documents-thunks";
5-
import { updateDocumentThunk } from "@/redux/thunks/single-document-thunk";
5+
import {
6+
fetchSingleDocumentByIdThunk,
7+
updateDocumentThunk,
8+
} from "@/redux/thunks/single-document-thunk";
69
import { Badge, Button, Descriptions, message } from "antd";
710
import { useDispatch, useSelector } from "react-redux";
811
import ReactToPrint from "react-to-print";
9-
import { useCallback, useRef, useState } from "react";
12+
import { useCallback, useRef } from "react";
13+
import { deleteDocumentSignatureThunk } from "@thunks/upload-thunk";
1014
import { DownloadOutlined } from "@ant-design/icons";
1115
import AdrCertificate from "@/components/documents/adr";
1216
import DriverCertificate from "@/components/documents/driver";
1317
import { removeCurrentDocumentId } from "@/redux/slices/documents";
1418
import { removeCurrentDocument } from "@/redux/slices/single-document";
1519
import { updateUI } from "@/helpers/update-ui";
1620
import { checkCertificateStatus } from "@/helpers/check-certificate-status";
21+
import { fetchDocumentStatusDataThunk } from "@/redux/thunks/document-status";
1722

1823
const SaveAndCheck = ({
1924
document,
@@ -154,6 +159,18 @@ const SaveAndCheck = ({
154159
message.success("Havola nusxalandi");
155160
};
156161

162+
const handleRemoveSignature = () => {
163+
dispatch(
164+
deleteDocumentSignatureThunk({
165+
id: document._id,
166+
endpoint: documentType,
167+
onSuccess: () => {
168+
message.success("Imzo o'chirildi");
169+
},
170+
}),
171+
);
172+
};
173+
157174
return (
158175
<div className="flex h-[580px] overflow-y-auto">
159176
<div className="w-full">
@@ -196,6 +213,16 @@ const SaveAndCheck = ({
196213
>
197214
Imzo qo'yish uchun havola
198215
</Button>
216+
{document?.signature && (
217+
<Button
218+
type="primary"
219+
onClick={handleRemoveSignature}
220+
danger
221+
disabled={loading}
222+
>
223+
Imzoni o'chirish
224+
</Button>
225+
)}
199226
</div>
200227
{actionType && (
201228
<Button onClick={handleCancelValues} variant="outlined" danger>

Diff for: server/src/routes/upload.js

+17
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ router.post('/signature', upload.single('file'), async (req, res) => {
5555
})
5656
})
5757

58+
router.delete('/signature', async (req, res) => {
59+
const type = req.query.type
60+
const id = req.query.id
61+
62+
if (type === 'driver') {
63+
await DriverCertificate.findByIdAndUpdate(id, {
64+
signature: '',
65+
})
66+
} else if (type === 'adr') {
67+
await AdrCertificate.findByIdAndUpdate(id, {
68+
signature: '',
69+
})
70+
}
71+
72+
res.send('File deleted successfully!')
73+
})
74+
5875
module.exports = router

0 commit comments

Comments
 (0)