qrcode temporary fix
All checks were successful
publish-main / release-image (push) Successful in 10m12s

This commit is contained in:
Ivan 2024-07-03 19:35:51 +03:00
parent 2b50f7c332
commit 7bccb29aa6
Signed by untrusted user who does not match committer: ppechenkoo
GPG Key ID: 0C191B86D9582583
2 changed files with 212 additions and 179 deletions

View File

@ -2,13 +2,12 @@ import React from "react";
import classes from "../../assets/styles/components/bodyModal/qrCodeToken.module.scss"; import classes from "../../assets/styles/components/bodyModal/qrCodeToken.module.scss";
import MyQrCode from "../MyQrCode.jsx"; import MyQrCode from "../MyQrCode.jsx";
const QrCodeToken = ({ value }) => { const QrCodeToken = ({ value }) => {
return ( return (
<div className={classes.main}> <div className={classes.main}>
<MyQrCode value={`http://localhost:3000/forms/${value}`}/> <MyQrCode value={`http://minerva.krbl.ru/forms/${value}`} />
</div> </div>
) );
} };
export default QrCodeToken export default QrCodeToken;

View File

@ -2,7 +2,12 @@ import React, { useState, useEffect, useContext } from "react";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { useCookies } from "react-cookie"; import { useCookies } from "react-cookie";
import classes from "../assets/styles/tokensForm.module.scss"; import classes from "../assets/styles/tokensForm.module.scss";
import { listFormsByTokenApi, newFormTokenApi, removeTokenFormApi, editTokenFormApi} from "../hooks/api/listFormsApi"; import {
listFormsByTokenApi,
newFormTokenApi,
removeTokenFormApi,
editTokenFormApi,
} from "../hooks/api/listFormsApi";
import MyButton from "../components/MyButton.jsx"; import MyButton from "../components/MyButton.jsx";
import { UserData } from "../context/index.js"; import { UserData } from "../context/index.js";
import DefaultModal from "../components/DefaultModal.jsx"; import DefaultModal from "../components/DefaultModal.jsx";
@ -10,7 +15,6 @@ import EditToken from "../components/bodyModal/EditToken.jsx";
import QrCodeToken from "../components/bodyModal/QrCodeToken.jsx"; import QrCodeToken from "../components/bodyModal/QrCodeToken.jsx";
import QRCode from "qrcode"; import QRCode from "qrcode";
const TokensForm = () => { const TokensForm = () => {
const { formId } = useParams(); const { formId } = useParams();
const [tokens, setTokens] = useState([]); const [tokens, setTokens] = useState([]);
@ -24,40 +28,36 @@ const TokensForm = () => {
useEffect(() => { useEffect(() => {
async function listFormsByToken() { async function listFormsByToken() {
const response = await listFormsByTokenApi(cookies.token, formId) const response = await listFormsByTokenApi(cookies.token, formId);
if (response.status === 200) { if (response.status === 200) {
setTokens(response.data.tokens.filter((item, i) => item.is_active === true && i !== 0)) setTokens(
setLoading(false) response.data.tokens.filter(
} (item, i) => item.is_active === true && i !== 0
else if ( )
response.status === 401 );
) { setLoading(false);
} else if (response.status === 401) {
// navigate("/enter") // navigate("/enter")
setUser(false); setUser(false);
} } else {
else { console.log(response);
console.log(response)
} }
} }
listFormsByToken() listFormsByToken();
}, []) }, []);
async function newFormToken() { async function newFormToken() {
const response = await newFormTokenApi(cookies.token, formId, titleToken) const response = await newFormTokenApi(cookies.token, formId, titleToken);
if (response.status === 200) { if (response.status === 200) {
setTokens([...tokens, response.data.token]) setTokens([...tokens, response.data.token]);
} } else if (response.status === 401) {
else if (
response.status === 401
) {
// navigate("/enter") // navigate("/enter")
setUser(false); setUser(false);
} } else {
else { console.log(response);
console.log(response)
} }
} }
@ -79,19 +79,15 @@ const TokensForm = () => {
// } // }
async function removeTokenForm(tokenForm) { async function removeTokenForm(tokenForm) {
const response = await removeTokenFormApi(cookies.token, formId, tokenForm) const response = await removeTokenFormApi(cookies.token, formId, tokenForm);
if (response.status === 200) { if (response.status === 200) {
setTokens(tokens.filter(item => item.id !== tokenForm)) setTokens(tokens.filter((item) => item.id !== tokenForm));
} } else if (response.status === 401) {
else if (
response.status === 401
) {
// navigate("/enter") // navigate("/enter")
setUser(false); setUser(false);
} } else {
else { console.log(response);
console.log(response)
} }
} }
@ -106,8 +102,8 @@ const TokensForm = () => {
text={"Создать"} text={"Создать"}
class={"main__green"} class={"main__green"}
click={() => { click={() => {
setTitleToken("") setTitleToken("");
setCurrentIdToken(false) setCurrentIdToken(false);
}} }}
target={"#tokenModal"} target={"#tokenModal"}
toggle={"modal"} toggle={"modal"}
@ -115,20 +111,32 @@ const TokensForm = () => {
</div> </div>
<div className={classes.answers__wrapper__body}> <div className={classes.answers__wrapper__body}>
<div className={classes.answers__wrapper__body__column}> <div className={classes.answers__wrapper__body__column}>
<div className={classes.answers__wrapper__body__column__wrapper}> <div
className={classes.answers__wrapper__body__column__wrapper}
>
<div>Название</div> <div>Название</div>
<div>Токен</div> <div>Токен</div>
</div> </div>
</div> </div>
{tokens ? {tokens ? (
tokens.map((item, i) => tokens.map((item, i) => (
<div className={classes.answers__wrapper__body__item} key={i}> <div className={classes.answers__wrapper__body__item} key={i}>
<div className={classes.answers__wrapper__body__item__wrapper}> <div
<div className={classes.answers__wrapper__body__item__wrapper__title}> className={classes.answers__wrapper__body__item__wrapper}
>
<div
className={
classes.answers__wrapper__body__item__wrapper__title
}
>
{item.name} {item.name}
</div> </div>
<div className={classes.answers__wrapper__body__item__wrapper__token}> <div
className={
classes.answers__wrapper__body__item__wrapper__token
}
>
{item.id} {item.id}
</div> </div>
</div> </div>
@ -146,46 +154,72 @@ const TokensForm = () => {
class="fa-solid fa-qrcode" class="fa-solid fa-qrcode"
onClick={() => { onClick={() => {
QRCode.toDataURL( QRCode.toDataURL(
`http://localhost:3000/forms/${item.id}`, `http://minerva.krbl.ru/forms/${item.id}`,
{}, {},
(err, url) => { (err, url) => {
setQrcodeUrl(url) setQrcodeUrl(url);
} }
) );
}} }}
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target={`#qrModal`}> data-bs-target={`#qrModal`}
</i> ></i>
<i class="fa-solid fa-trash" onClick={() => removeTokenForm(item.id)}></i> <i
class="fa-solid fa-trash"
onClick={() => removeTokenForm(item.id)}
></i>
</div> </div>
<DefaultModal <DefaultModal
name={"qrModal"} name={"qrModal"}
btn={[ btn={[
{text: "Скачать", class: "main__green", dismiss: "modal", action: () => { {
const aElem = document.createElement('a'); text: "Скачать",
aElem.href = qrCodeUrl class: "main__green",
aElem.download = `${item.name}.png` dismiss: "modal",
aElem.click() action: () => {
}}, const aElem = document.createElement("a");
{text: "Отмена", class: "main__white", dismiss: "modal", action: () => {}} aElem.href = qrCodeUrl;
aElem.download = `${item.name}.png`;
aElem.click();
},
},
{
text: "Отмена",
class: "main__white",
dismiss: "modal",
action: () => {},
},
]} ]}
BodyModal={ BodyModal={<QrCodeToken value={item.id} />}
<QrCodeToken value={item.id}/>
}
/> />
</div> </div>
) ))
: ) : (
<div className={classes.loading__wrapper}> <div className={classes.loading__wrapper}>
<div class="spinner-border text-dark" className={classes.loading__wrapper__body} role="status"> <div
class="spinner-border text-dark"
className={classes.loading__wrapper__body}
role="status"
>
<span class="visually-hidden">Загрузка...</span> <span class="visually-hidden">Загрузка...</span>
</div> </div>
</div>} </div>
)}
<DefaultModal <DefaultModal
name={"tokenModal"} name={"tokenModal"}
btn={[ btn={[
{text: "Сохранить", class: "main__green", dismiss: "modal", action: () => newFormToken()}, {
{text: "Отмена", class: "main__white", dismiss: "modal", action: () => {}} text: "Сохранить",
class: "main__green",
dismiss: "modal",
action: () => newFormToken(),
},
{
text: "Отмена",
class: "main__white",
dismiss: "modal",
action: () => {},
},
]} ]}
BodyModal={ BodyModal={
<EditToken <EditToken
@ -199,7 +233,7 @@ const TokensForm = () => {
</div> </div>
</div> </div>
</div> </div>
) );
} };
export default TokensForm; export default TokensForm;