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 MyQrCode from "../MyQrCode.jsx";
const QrCodeToken = ({value}) => {
const QrCodeToken = ({ value }) => {
return (
<div className={classes.main}>
<MyQrCode value={`http://localhost:3000/forms/${value}`}/>
<MyQrCode value={`http://minerva.krbl.ru/forms/${value}`} />
</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 { useCookies } from "react-cookie";
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 { UserData } from "../context/index.js";
import DefaultModal from "../components/DefaultModal.jsx";
@ -10,54 +15,49 @@ import EditToken from "../components/bodyModal/EditToken.jsx";
import QrCodeToken from "../components/bodyModal/QrCodeToken.jsx";
import QRCode from "qrcode";
const TokensForm = () => {
const { formId } = useParams();
const [tokens, setTokens] = useState([]);
const [currentIdToken, setCurrentIdToken] = useState(false);
const [loading, setLoading] = useState(true);
const [titleToken, setTitleToken] = useState("");
const {user, setUser} = useContext(UserData);
const { user, setUser } = useContext(UserData);
const [qrCodeUrl, setQrcodeUrl] = useState("");
const [cookies, _, __] = useCookies(["user"]);
useEffect(() => {
async function listFormsByToken() {
const response = await listFormsByTokenApi(cookies.token, formId)
const response = await listFormsByTokenApi(cookies.token, formId);
if (response.status === 200) {
setTokens(response.data.tokens.filter((item, i) => item.is_active === true && i !== 0))
setLoading(false)
}
else if (
response.status === 401
) {
setTokens(
response.data.tokens.filter(
(item, i) => item.is_active === true && i !== 0
)
);
setLoading(false);
} else if (response.status === 401) {
// navigate("/enter")
setUser(false);
}
else {
console.log(response)
} else {
console.log(response);
}
}
listFormsByToken()
}, [])
listFormsByToken();
}, []);
async function newFormToken() {
const response = await newFormTokenApi(cookies.token, formId, titleToken)
const response = await newFormTokenApi(cookies.token, formId, titleToken);
if (response.status === 200) {
setTokens([...tokens, response.data.token])
}
else if (
response.status === 401
) {
setTokens([...tokens, response.data.token]);
} else if (response.status === 401) {
// navigate("/enter")
setUser(false);
}
else {
console.log(response)
} else {
console.log(response);
}
}
@ -79,19 +79,15 @@ const TokensForm = () => {
// }
async function removeTokenForm(tokenForm) {
const response = await removeTokenFormApi(cookies.token, formId, tokenForm)
const response = await removeTokenFormApi(cookies.token, formId, tokenForm);
if (response.status === 200) {
setTokens(tokens.filter(item => item.id !== tokenForm))
}
else if (
response.status === 401
) {
setTokens(tokens.filter((item) => item.id !== tokenForm));
} else if (response.status === 401) {
// navigate("/enter")
setUser(false);
}
else {
console.log(response)
} else {
console.log(response);
}
}
@ -106,8 +102,8 @@ const TokensForm = () => {
text={"Создать"}
class={"main__green"}
click={() => {
setTitleToken("")
setCurrentIdToken(false)
setTitleToken("");
setCurrentIdToken(false);
}}
target={"#tokenModal"}
toggle={"modal"}
@ -115,20 +111,32 @@ const TokensForm = () => {
</div>
<div className={classes.answers__wrapper__body}>
<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>
{tokens ?
tokens.map((item, i) =>
{tokens ? (
tokens.map((item, i) => (
<div className={classes.answers__wrapper__body__item} key={i}>
<div className={classes.answers__wrapper__body__item__wrapper}>
<div className={classes.answers__wrapper__body__item__wrapper__title}>
<div
className={classes.answers__wrapper__body__item__wrapper}
>
<div
className={
classes.answers__wrapper__body__item__wrapper__title
}
>
{item.name}
</div>
<div className={classes.answers__wrapper__body__item__wrapper__token}>
<div
className={
classes.answers__wrapper__body__item__wrapper__token
}
>
{item.id}
</div>
</div>
@ -146,46 +154,72 @@ const TokensForm = () => {
class="fa-solid fa-qrcode"
onClick={() => {
QRCode.toDataURL(
`http://localhost:3000/forms/${item.id}`,
`http://minerva.krbl.ru/forms/${item.id}`,
{},
(err , url) => {
setQrcodeUrl(url)
(err, url) => {
setQrcodeUrl(url);
}
)
);
}}
data-bs-toggle="modal"
data-bs-target={`#qrModal`}>
</i>
<i class="fa-solid fa-trash" onClick={() => removeTokenForm(item.id)}></i>
data-bs-target={`#qrModal`}
></i>
<i
class="fa-solid fa-trash"
onClick={() => removeTokenForm(item.id)}
></i>
</div>
<DefaultModal
name={"qrModal"}
btn={[
{text: "Скачать", class: "main__green", dismiss: "modal", action: () => {
const aElem = document.createElement('a');
aElem.href = qrCodeUrl
aElem.download = `${item.name}.png`
aElem.click()
}},
{text: "Отмена", class: "main__white", dismiss: "modal", action: () => {}}
{
text: "Скачать",
class: "main__green",
dismiss: "modal",
action: () => {
const aElem = document.createElement("a");
aElem.href = qrCodeUrl;
aElem.download = `${item.name}.png`;
aElem.click();
},
},
{
text: "Отмена",
class: "main__white",
dismiss: "modal",
action: () => {},
},
]}
BodyModal={
<QrCodeToken value={item.id}/>
}
BodyModal={<QrCodeToken value={item.id} />}
/>
</div>
)
:
))
) : (
<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>
</div>
</div>}
</div>
)}
<DefaultModal
name={"tokenModal"}
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={
<EditToken
@ -199,7 +233,7 @@ const TokensForm = () => {
</div>
</div>
</div>
)
}
);
};
export default TokensForm;