From c308e0fd583bbdc01203bf3c5b0bd5cd4a2fe7a0 Mon Sep 17 00:00:00 2001 From: M1kola Date: Thu, 13 Jul 2023 03:42:12 +0300 Subject: [PATCH] file --- .../Modal/Tracker/ModalTicket/ModalTicket.jsx | 38 ++++++++----------- .../Tracker/ModalTicket/modalTicket.scss | 10 +++++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx b/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx index 1a6d3406..aa1c82e7 100644 --- a/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx +++ b/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx @@ -68,9 +68,9 @@ export const ModalTiсket = ({ const [executor, setExecutor] = useState(task.executor); const [members, setMembers] = useState(task.taskUsers); const [users, setUsers] = useState([]); - const [selectedFile, setSelectedFile] = useState(""); const [timerStart, setTimerStart] = useState(false); const [timerInfo, setTimerInfo] = useState({}); + const [uploadedFile, setUploadedFile] = useState(null) const [currentTimerCount, setCurrentTimerCount] = useState({ hours: 0, minute: 0, @@ -308,31 +308,18 @@ export const ModalTiсket = ({ } }, []); - function handleChange(event) { - setSelectedFile(event.target.files[0]); - } - - async function handleUpload() { + async function handleUpload(event) { const formData = new FormData(); - formData.append("uploadFile", selectedFile); - const headers = { - "Access-Control-Allow-Origin": "*", - "Content-Type": "application/json", - }; - const fullHeaders = { ...headers, ...getToken() }; + formData.append("uploadFile", event.target.files[0]); const res = await fetch("https://itguild.info/api/file/upload", { method: "POST", body: formData, - headers: { ...fullHeaders }, + headers: { ...getToken() }, }); - console.log(fullHeaders); - console.log(res); - // apiRequest('/file/upload', { - // method: 'POST', - // body: formData - // }).then((res) => { - // }) + const data = await res.json() + + setUploadedFile(data) } function startTimer() { @@ -468,6 +455,14 @@ export const ModalTiсket = ({ )} {/**/} + {uploadedFile && +
+ {uploadedFile.map((file) => { + return img + }) + } +
+ }
{/*

*/} {/*

-

Отправить

{0} {caseOfNum(0, "files")} diff --git a/src/components/Modal/Tracker/ModalTicket/modalTicket.scss b/src/components/Modal/Tracker/ModalTicket/modalTicket.scss index 7686f9a3..68b17618 100644 --- a/src/components/Modal/Tracker/ModalTicket/modalTicket.scss +++ b/src/components/Modal/Tracker/ModalTicket/modalTicket.scss @@ -315,6 +315,16 @@ } } + .fileLoaded { + display: flex; + margin: 10px 0 0; + + img { + max-width: 250px; + object-fit: contain; + } + } + &__communication { display: flex; flex-direction: row;