-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:added signature to the certificates
- Loading branch information
1 parent
bfe427c
commit 55fc745
Showing
14 changed files
with
246 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { resolve } from "../../helpers/resolve-response"; | ||
import axios from "@api"; | ||
|
||
export async function uploadSignature(id, type, file) { | ||
console.log("id", id); | ||
console.log("type", type); | ||
console.log("file", file.get("file")); | ||
const authResponse = await resolve( | ||
fetch( | ||
"http://localhost:9000/api/upload/signature?id=" + id + "&type=" + type, | ||
{ | ||
body: file, | ||
method: "POST", | ||
}, | ||
), | ||
); | ||
return authResponse.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { uploadSignature } from "@/api/upload"; | ||
import { createAsyncThunk } from "@reduxjs/toolkit"; | ||
|
||
export const uploadSignatureThunk = createAsyncThunk( | ||
"signature/upload", | ||
async ({ id, type, file, onSuccess }) => { | ||
try { | ||
const response = await uploadSignature(id, type, file); | ||
if (onSuccess) onSuccess(response); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}, | ||
); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useRef, useState } from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import SignatureCanvas from "react-signature-canvas"; | ||
import { Button, message, Spin } from "antd"; | ||
import { uploadSignatureThunk } from "@thunks/upload-thunk"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
const SignatureUpload = () => { | ||
const [loading, setLoading] = useState(false); | ||
const dispatch = useDispatch(); | ||
const signatureRef = useRef(null); | ||
const { id } = useParams(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSave = () => { | ||
const signature = signatureRef.current | ||
.getTrimmedCanvas() | ||
.toDataURL("image/png"); | ||
const imageFromBase64 = signature.split(",")[1]; | ||
const byteCharacters = atob(imageFromBase64); | ||
const byteNumbers = new Array(byteCharacters.length); | ||
|
||
for (let i = 0; i < byteCharacters.length; i++) { | ||
byteNumbers[i] = byteCharacters.charCodeAt(i); | ||
} | ||
|
||
const byteArray = new Uint8Array(byteNumbers); | ||
const blob = new Blob([byteArray], { type: "image/png" }); | ||
const file = new File([blob], "signature.png", { type: "image/png" }); | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
setLoading(true); | ||
dispatch( | ||
uploadSignatureThunk({ | ||
id: id?.split("-")[1], | ||
type: id?.split("-")[0], | ||
file: formData, | ||
onSuccess: () => { | ||
setLoading(false); | ||
message.success("Imzo saqlandi"); | ||
navigate("/"); | ||
}, | ||
}), | ||
); | ||
}; | ||
|
||
const handleReset = () => { | ||
signatureRef.current.clear(); | ||
}; | ||
|
||
return ( | ||
<div className="max-w-[500px] mx-auto h-screen flex flex-col gap-[20px] justify-center items-center"> | ||
{loading ? ( | ||
<Spin /> | ||
) : ( | ||
<> | ||
{" "} | ||
<SignatureCanvas | ||
ref={signatureRef} | ||
penColor="black" | ||
canvasProps={{ | ||
width: 500, | ||
height: 200, | ||
className: "border-2 border-black", | ||
}} | ||
/> | ||
<div className="flex gap-4"> | ||
<Button type="primary" disabled={loading} onClick={handleSave}> | ||
Saqlash | ||
</Button> | ||
<Button type="default" disabled={loading} onClick={handleReset}> | ||
Qaytadan chizish | ||
</Button> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SignatureUpload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.