Merge branch 'dev' into 'staging'

Dev

See merge request frontend/squiz!350
This commit is contained in:
Nastya 2024-07-06 11:34:26 +00:00
commit 3fa473b9be
3 changed files with 46 additions and 16 deletions

@ -15,6 +15,7 @@ import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
import { DeleteModal } from "./DeleteModal"; import { DeleteModal } from "./DeleteModal";
import type { AnyTypedQuizQuestion } from "@frontend/squzanswerer"; import type { AnyTypedQuizQuestion } from "@frontend/squzanswerer";
import { useCurrentQuiz } from "@/stores/quizes/hooks";
interface CardAnswerProps { interface CardAnswerProps {
isNew: boolean; isNew: boolean;
@ -47,6 +48,7 @@ export const CardAnswer: FC<CardAnswerProps> = ({
const [questionsResultState, setQuestionsResultState] = useState<AnyTypedQuizQuestion[]>([]); const [questionsResultState, setQuestionsResultState] = useState<AnyTypedQuizQuestion[]>([]);
const { editQuizId } = useQuizStore(); const { editQuizId } = useQuizStore();
const { questions } = useQuestionsStore(); const { questions } = useQuestionsStore();
const quiz = useCurrentQuiz();
const openResults = async () => { const openResults = async () => {
setIsOpen(!isOpen); setIsOpen(!isOpen);
if (!isOpen) { if (!isOpen) {
@ -295,17 +297,22 @@ export const CardAnswer: FC<CardAnswerProps> = ({
}} }}
> >
{resultsAnswer.map((answer, id) => { {resultsAnswer.map((answer, id) => {
// console.log(answer)
// console.log(answer.content)
let titleQuestion; let titleQuestion;
let typeOuestion; let typeOuestion;
let typeQuestionFile; let typeQuestionFile;
let qid
let quest = questions; //массив с вопросами let quest = questions; //массив с вопросами
let i; let i;
let idAnswer = answer.question_id; //айди вопроса у ответа let idAnswer = answer.question_id; //айди вопроса у ответа
for (i in quest) { for (i in quest) {
if (quest[i].backendId === idAnswer) { if (quest[i].backendId === idAnswer) {
console.log(quest[i])
titleQuestion = quest[i].title; titleQuestion = quest[i].title;
typeOuestion = quest[i].type; typeOuestion = quest[i].type;
typeQuestionFile = quest[i].content.type; typeQuestionFile = quest[i].content.type;
qid = quest[i].backendId
} }
} }
return ( return (
@ -316,6 +323,7 @@ export const CardAnswer: FC<CardAnswerProps> = ({
alignItems: "center", alignItems: "center",
gap: "13px", gap: "13px",
}} }}
onClick={(e) => e.stopPropagation()}
> >
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}> <Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
{id + 1}. {titleQuestion}. {id + 1}. {titleQuestion}.
@ -323,23 +331,23 @@ export const CardAnswer: FC<CardAnswerProps> = ({
{typeOuestion === "file" && ( {typeOuestion === "file" && (
<Link <Link
download download
href={answer.content} href={timewebContentFile(quiz?.qid, answer.content, qid)}
style={{ style={{
color: "#7E2AEA", color: "#7E2AEA",
display: "flex", display: "flex",
gap: "10px", gap: "10px",
}} }}
> >
{typeQuestionFile === "video" && ( {typeQuestionFile === "video" && answer.content && (
<video <video
src={answer.content} src={timewebContentFile(quiz?.qid, answer.content, qid)}
width={40} width={40}
height={40} height={40}
></video> ></video>
)} )}
{typeQuestionFile === "picture" && ( {typeQuestionFile === "picture" && answer.content && (
<img <img
src={answer.content} src={timewebContentFile(quiz?.qid, answer.content, qid)}
width={40} width={40}
height={40} height={40}
/> />
@ -347,15 +355,15 @@ export const CardAnswer: FC<CardAnswerProps> = ({
клик для скачивания клик для скачивания
</Link> </Link>
)} )}
{(typeOuestion === "images" || typeOuestion === "varimg") && ( {(typeOuestion === "images" || typeOuestion === "varimg") && answer.content && (
<> <>
<img <img
width={40} width={40}
height={40} height={40}
src={answer.content.split("<")[1].split('src="')[1].split('"/>')[0]} src={timewebContent(quiz?.qid, answer.content, qid)}
/> />
<Typography sx={{ fontSize: "18px" }}>{answer.content.split("<")[0]}</Typography> {/* <Typography sx={{ fontSize: "18px" }}>{answer.content.split("<")[0]}</Typography> */}
</> </>
)} )}
{!(typeOuestion === "file" || typeOuestion === "images" || typeOuestion === "varimg") && ( {!(typeOuestion === "file" || typeOuestion === "images" || typeOuestion === "varimg") && (
@ -428,3 +436,22 @@ export const CardAnswer: FC<CardAnswerProps> = ({
</> </>
); );
}; };
function timewebContentFile(editQuizId: string, content: string, qid: string) {
if (content.includes("<img")) {
//Старая версия: контент лежит в теге
//<img style="width:100%; max-width:250px; max-height:250px" src="https://s3.timeweb.cloud/3c580be9-30c7959dc17b/squizimages/03520c507b35e8/cq39gn7o73evdd30"/>
return content.split("<")[1].split('src="')[1].split('"/>')[0]
}
//Новая версия: контент просто записан с указанием расширения файла
return `https://s3.timeweb.cloud/3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b/squizanswer/${editQuizId}/${qid}/${content}`
}
function timewebContent(editQuizId: string, content: string, qid: string) {
if (content.includes("<img")) {
//Старая версия: контент лежит в теге
//<img style="width:100%; max-width:250px; max-height:250px" src="https://s3.timeweb.cloud/3c580be9-30c7959dc17b/squizimages/03520c507b35e8/cq39gn7o73evdd30"/>
return content.split("<")[1].split('src="')[1].split('"/>')[0]
}
//Новая версия: контент просто записан с указанием расширения файла
return `https://s3.timeweb.cloud/3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b/squizimages/${editQuizId}/${content}`
}

@ -137,12 +137,15 @@ function TariffPage() {
if (payError || !data) { if (payError || !data) {
//если денег не хватило //если денег не хватило
if (payError?.includes("insufficient funds")) { if (payError?.includes("insufficient funds") || payError?.includes("Payment Required")) {
let cashDif = Number(payError.split(":")[1]); let cashDif = Number(payError.split(":")[1]);
console.log(payError)
console.log(cashDif)
var link = document.createElement("a"); var link = document.createElement("a");
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${cashDif}&data=${token}&userid=${userId}`; link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${cashDif}&data=${token}&userid=${userId}`;
document.body.appendChild(link); document.body.appendChild(link);
link.click(); console.log(link)
// link.click();
return; return;
} }
@ -388,14 +391,14 @@ export const Tariffs = withErrorBoundary(TariffPage, {
const LoadingPage = () => ( const LoadingPage = () => (
<Box <Box
sx={{ sx={{
height: "100%", height: "100vh",
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
}} }}
> >
<Typography sx={{ textAlign: "center" }}> <Typography sx={{ textAlign: "center" }}>
{"Подождите, пожалуйста, идёт загрузка :)"} {"Подождите, пожалуйста, идёт загрузка"}
</Typography> </Typography>
</Box> </Box>
); );
@ -433,7 +436,7 @@ const outCart = (cart: string[]) => {
return; return;
} }
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]"); let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]") || [];
saveCart = saveCart.push(id); saveCart = saveCart.push(id);
localStorage.setItem("saveCart", JSON.stringify(saveCart)); localStorage.setItem("saveCart", JSON.stringify(saveCart));
}); });

@ -32,9 +32,9 @@ export const parseAxiosError = (nativeError: unknown): [string, number?] => {
const serverError = error.response.data as ServerError; const serverError = error.response.data as ServerError;
let SEMessage; let SEMessage;
if (error.response.statusText) { // if (error.response.statusText) {
return [error.response.statusText]; // return [error.response.statusText];
} // }
if ("statusCode" in serverError) { if ("statusCode" in serverError) {
SEMessage = serverError?.message.toLowerCase() || ""; SEMessage = serverError?.message.toLowerCase() || "";