From c22f26f6fe59a46bafc42eff3143bd937cb0efd7 Mon Sep 17 00:00:00 2001 From: Gubar Nikita Date: Fri, 9 Aug 2024 15:43:51 +0300 Subject: [PATCH] fix timer(Tracker/ModalTicket) fix fileUpload (Tracker/ModalTicket) fix tgToken(PartnerSettings) --- .../Modal/Tracker/ModalTicket/ModalTicket.jsx | 35 ++++++---- .../TicketFullScreen/TicketFullScreen.jsx | 34 ++++++---- src/pages/PartnerSettings/PartnerSettings.jsx | 67 ++++++++++++++----- .../PartnerSettings/partnerSettings.scss | 3 +- src/pages/roles/PartnerPage.jsx | 2 + 5 files changed, 96 insertions(+), 45 deletions(-) diff --git a/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx b/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx index c3e3fad8..0c6f64aa 100644 --- a/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx +++ b/src/components/Modal/Tracker/ModalTicket/ModalTicket.jsx @@ -490,18 +490,27 @@ export const ModalTiсket = ({ }, [taskTags]); async function handleUpload(event) { - const formData = new FormData(); - formData.append("uploadFile", event.target.files[0]); - const res = await fetch("https://itguild.info/api/file/upload", { - method: "POST", - body: formData, - headers: { ...getToken() } - }); + try { + const formData = new FormData(); + formData.append("uploadFile", event.target.files[0]); - const data = await res.json(); + const res = await fetch("https://itguild.info/api/file/upload", { + method: "POST", + body: formData, + headers: { ...getToken() } + }); - // setUploadedFile(data); - attachFile(data[0].id); + const data = await res.json(); + + // setUploadedFile(data); + attachFile(data[0].id); + } catch { + showNotification({ + show: true, + text: "Неверный формат файла", + type: "error" + }); + } } // function deleteLoadedFile() { @@ -543,7 +552,7 @@ export const ModalTiсket = ({ function run() { updateTimerSec++; - if (updateTimerSec > 60) { + if (updateTimerSec > 59) { updateTimerMinute++; updateTimerSec = 0; } @@ -561,7 +570,7 @@ export const ModalTiсket = ({ function correctTimerTime(time) { if (time < 10) return `0${time}`; - if (time > 10) return time; + if (time >= 10) return time; } useEffect(() => { @@ -800,7 +809,7 @@ export const ModalTiсket = ({ name="file" id="input__file" type="file" - accept="image/*,.png,.jpg,.svg,.jpeg" + accept="image/*,.png,.jpg,.svg,.jpeg,.doc,.docx,.xls,.xlsx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" className="input__file" onChange={handleUpload} /> diff --git a/src/components/Modal/Tracker/TicketFullScreen/TicketFullScreen.jsx b/src/components/Modal/Tracker/TicketFullScreen/TicketFullScreen.jsx index be52aee7..972b3635 100644 --- a/src/components/Modal/Tracker/TicketFullScreen/TicketFullScreen.jsx +++ b/src/components/Modal/Tracker/TicketFullScreen/TicketFullScreen.jsx @@ -381,7 +381,7 @@ export const TicketFullScreen = () => { function run() { updateTimerSec++; - if (updateTimerSec > 60) { + if (updateTimerSec > 59) { updateTimerMinute++; updateTimerSec = 0; } @@ -399,7 +399,7 @@ export const TicketFullScreen = () => { function correctTimerTime(time) { if (time < 10) return `0${time}`; - if (time > 10) return time; + if (time >= 10) return time; } function deleteTaskExecutor() { @@ -479,17 +479,27 @@ export const TicketFullScreen = () => { } async function handleUpload(event) { - const formData = new FormData(); - formData.append("uploadFile", event.target.files[0]); - const res = await fetch("https://itguild.info/api/file/upload", { - method: "POST", - body: formData, - headers: { ...getToken() } - }); + try { + const formData = new FormData(); + formData.append("uploadFile", event.target.files[0]); - const data = await res.json(); + const res = await fetch("https://itguild.info/api/file/upload", { + method: "POST", + body: formData, + headers: { ...getToken() } + }); - setUploadedFile(data); + const data = await res.json(); + + // setUploadedFile(data); + attachFile(data[0].id); + } catch { + showNotification({ + show: true, + text: "Неверный формат файла", + type: "error" + }); + } } function attachFile() { @@ -774,7 +784,7 @@ export const TicketFullScreen = () => { name="file" id="input__file" type="file" - accept="image/*,.png,.jpg,.svg,.jpeg" + accept="image/*,.png,.jpg,.svg,.jpeg,.doc,.docx,.xls,.xlsx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" className="input__file" onChange={handleUpload} /> diff --git a/src/pages/PartnerSettings/PartnerSettings.jsx b/src/pages/PartnerSettings/PartnerSettings.jsx index e23dd8c1..a5b27dae 100644 --- a/src/pages/PartnerSettings/PartnerSettings.jsx +++ b/src/pages/PartnerSettings/PartnerSettings.jsx @@ -34,13 +34,13 @@ export const PartnerSettings = () => { const [loader, setLoader] = useState(false); const [tgLoader, setTgLoader] = useState(false); - useEffect(() => { - apiRequest("/user-tg-bot/get-token", { - method: "GET" - }).then((data) => { - setTgToken(data.token); - }); - }, []); + // useEffect(() => { + // apiRequest("/user-tg-bot/get-token", { + // method: "GET" + // }).then((data) => { + // setTgToken(data.token); + // }); + // }, []); const setSettings = () => { if (inputsValue.name.length < 2) { @@ -92,18 +92,43 @@ export const PartnerSettings = () => { }); }; - const handleCopy = async () => { - try { - await navigator.clipboard.writeText(tgToken); - showNotification({ - show: true, - text: "Телеграм токен успешно скопирован", - type: "success" + const handleGenerate = async () => { + if (tgToken == undefined) { + setTgLoader(true); + apiRequest("/user-tg-bot/get-token", { + method: "GET" + }).then((data) => { + setTgToken(data.token); + showNotification({ + show: true, + text: "Телеграм токен успешно сгенерирован", + type: "success" + }); + setTgLoader(false); }); - } catch (err) { + } + }; + + const handleCopy = async () => { + if (tgToken !== undefined) { + try { + await navigator.clipboard.writeText(tgToken); + showNotification({ + show: true, + text: "Телеграм токен успешно скопирован", + type: "success" + }); + } catch (err) { + showNotification({ + show: true, + text: "Ошибка копирования", + type: "error" + }); + } + } else { showNotification({ show: true, - text: "Ошибка копирования", + text: "Необходимо сгенерировать код", type: "error" }); } @@ -226,12 +251,18 @@ export const PartnerSettings = () => { ) : ( - Скопировать + Сгенерировать )} + + Скопировать +
diff --git a/src/pages/PartnerSettings/partnerSettings.scss b/src/pages/PartnerSettings/partnerSettings.scss index d5ae0f00..55926659 100644 --- a/src/pages/PartnerSettings/partnerSettings.scss +++ b/src/pages/PartnerSettings/partnerSettings.scss @@ -94,8 +94,7 @@ width: 100%; display: flex; flex-direction: row; - justify-content: flex-start; - gap: 20px; + justify-content: space-around; margin: 30px 0 20px; &-cancel, diff --git a/src/pages/roles/PartnerPage.jsx b/src/pages/roles/PartnerPage.jsx index 80b6f73b..c4a2606d 100644 --- a/src/pages/roles/PartnerPage.jsx +++ b/src/pages/roles/PartnerPage.jsx @@ -27,6 +27,7 @@ import { WelcomePage } from "@pages/WelcomePage/WelcomePage"; import { Calendar } from "@components/Calendar/Calendar"; import { Candidate } from "@components/Candidate/Candidate"; +import TicketFullScreen from "@components/Modal/Tracker/TicketFullScreen/TicketFullScreen"; export const PartnerPage = () => { return ( @@ -45,6 +46,7 @@ export const PartnerPage = () => { } /> } /> + } />