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 type { AnyTypedQuizQuestion } from "@frontend/squzanswerer";
import { useCurrentQuiz } from "@/stores/quizes/hooks";
interface CardAnswerProps {
isNew: boolean;
@ -47,6 +48,7 @@ export const CardAnswer: FC<CardAnswerProps> = ({
const [questionsResultState, setQuestionsResultState] = useState<AnyTypedQuizQuestion[]>([]);
const { editQuizId } = useQuizStore();
const { questions } = useQuestionsStore();
const quiz = useCurrentQuiz();
const openResults = async () => {
setIsOpen(!isOpen);
if (!isOpen) {
@ -295,17 +297,22 @@ export const CardAnswer: FC<CardAnswerProps> = ({
}}
>
{resultsAnswer.map((answer, id) => {
// console.log(answer)
// console.log(answer.content)
let titleQuestion;
let typeOuestion;
let typeQuestionFile;
let qid
let quest = questions; //массив с вопросами
let i;
let idAnswer = answer.question_id; //айди вопроса у ответа
for (i in quest) {
if (quest[i].backendId === idAnswer) {
console.log(quest[i])
titleQuestion = quest[i].title;
typeOuestion = quest[i].type;
typeQuestionFile = quest[i].content.type;
qid = quest[i].backendId
}
}
return (
@ -316,6 +323,7 @@ export const CardAnswer: FC<CardAnswerProps> = ({
alignItems: "center",
gap: "13px",
}}
onClick={(e) => e.stopPropagation()}
>
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
{id + 1}. {titleQuestion}.
@ -323,23 +331,23 @@ export const CardAnswer: FC<CardAnswerProps> = ({
{typeOuestion === "file" && (
<Link
download
href={answer.content}
href={timewebContentFile(quiz?.qid, answer.content, qid)}
style={{
color: "#7E2AEA",
display: "flex",
gap: "10px",
}}
>
{typeQuestionFile === "video" && (
{typeQuestionFile === "video" && answer.content && (
<video
src={answer.content}
src={timewebContentFile(quiz?.qid, answer.content, qid)}
width={40}
height={40}
></video>
)}
{typeQuestionFile === "picture" && (
{typeQuestionFile === "picture" && answer.content && (
<img
src={answer.content}
src={timewebContentFile(quiz?.qid, answer.content, qid)}
width={40}
height={40}
/>
@ -347,15 +355,15 @@ export const CardAnswer: FC<CardAnswerProps> = ({
клик для скачивания
</Link>
)}
{(typeOuestion === "images" || typeOuestion === "varimg") && (
{(typeOuestion === "images" || typeOuestion === "varimg") && answer.content && (
<>
<img
width={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") && (
@ -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?.includes("insufficient funds")) {
if (payError?.includes("insufficient funds") || payError?.includes("Payment Required")) {
let cashDif = Number(payError.split(":")[1]);
console.log(payError)
console.log(cashDif)
var link = document.createElement("a");
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${cashDif}&data=${token}&userid=${userId}`;
document.body.appendChild(link);
link.click();
console.log(link)
// link.click();
return;
}
@ -388,14 +391,14 @@ export const Tariffs = withErrorBoundary(TariffPage, {
const LoadingPage = () => (
<Box
sx={{
height: "100%",
height: "100vh",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<Typography sx={{ textAlign: "center" }}>
{"Подождите, пожалуйста, идёт загрузка :)"}
{"Подождите, пожалуйста, идёт загрузка"}
</Typography>
</Box>
);
@ -433,7 +436,7 @@ const outCart = (cart: string[]) => {
return;
}
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]");
let saveCart = JSON.parse(localStorage.getItem("saveCart") || "[]") || [];
saveCart = saveCart.push(id);
localStorage.setItem("saveCart", JSON.stringify(saveCart));
});

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