diff --git a/src/api/promocode.ts b/src/api/promocode.ts index 51374e1a..1c93dae0 100644 --- a/src/api/promocode.ts +++ b/src/api/promocode.ts @@ -15,7 +15,7 @@ export async function activatePromocode(promocode: string) { contentType: true, body: { codeword: promocode }, }); - console.log(response) + console.log(response); return response.greetings; } catch (nativeError) { diff --git a/src/pages/Tariffs/Tariffs.tsx b/src/pages/Tariffs/Tariffs.tsx index a7a95f16..0e4f9719 100644 --- a/src/pages/Tariffs/Tariffs.tsx +++ b/src/pages/Tariffs/Tariffs.tsx @@ -172,18 +172,18 @@ function TariffPage() { return tariff.privileges[0].privilegeId !== "squizHideBadge"; }); - function handleApplyPromocode () { + function handleApplyPromocode() { if (!promocodeField) return; activatePromocode(promocodeField) .then(async (greetings) => { - enqueueSnackbar(greetings) + enqueueSnackbar(greetings); - const discounts = await makeRequest({ - method: "GET", - url: `${process.env.REACT_APP_DOMAIN}/price/discount/user/${userId}`, - }); - setDiscounts(discounts.Discounts); + const discounts = await makeRequest({ + method: "GET", + url: `${process.env.REACT_APP_DOMAIN}/price/discount/user/${userId}`, + }); + setDiscounts(discounts.Discounts); }) .catch(enqueueSnackbar); } diff --git a/src/utils/deleteFunc.ts b/src/utils/deleteFunc.ts index 580a6ed7..f07db4f1 100644 --- a/src/utils/deleteFunc.ts +++ b/src/utils/deleteFunc.ts @@ -1,4 +1,3 @@ -import { AnyTypedQuizQuestion } from "@model/questionTypes/shared"; import { clearRuleForAll, createResult, @@ -10,6 +9,13 @@ import { useQuestionsStore } from "@root/questions/store"; import { updateRootContentId } from "@root/quizes/actions"; import { getCurrentQuiz } from "@root/quizes/hooks"; +import type { + AnyTypedQuizQuestion, + QuestionBranchingRule, + QuestionBranchingRuleMain, +} from "@model/questionTypes/shared"; +import { QuizQuestionResult } from "@model/questionTypes/result"; + //Всё здесь нужно сделать последовательно. И пусть весь мир ждёт. export const DeleteFunction = async (questionId: string) => { @@ -33,7 +39,9 @@ export const DeleteFunction = async (questionId: string) => { const parentQuestion = getQuestionByContentId( question.content.rule.parentId, ); - let startCountParentChildren = parentQuestion.content.rule.children; + let startCountParentChildren = parentQuestion?.type + ? parentQuestion.content.rule.children + : null; //записываем потомков , а их результаты удаляем const getChildren = (parentQuestion: AnyTypedQuizQuestion) => { @@ -67,8 +75,10 @@ export const DeleteFunction = async (questionId: string) => { }), ); - //чистим rule родителя - const newRule = {}; + if (!parentQuestion?.type) { + return; + } + const parentChildren = [...parentQuestion.content.rule.children]; if (parentChildren.includes(question.content.id)) @@ -77,15 +87,21 @@ export const DeleteFunction = async (questionId: string) => { 1, ); - newRule.main = parentQuestion.content.rule.main.filter( - (data) => data.next !== question.content.id, + const main = parentQuestion.content.rule.main.filter( + (data: QuestionBranchingRuleMain) => data.next !== question.content.id, ); //удаляем условия перехода от родителя к этому вопросу - newRule.parentId = parentQuestion.content.rule.parentId; - newRule.default = + const defaultValue = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId; - newRule.children = parentChildren; + + //чистим rule родителя + const newRule: QuestionBranchingRule = { + main, + default: defaultValue, + children: parentChildren, + parentId: parentQuestion.content.rule.parentId, + }; await updateQuestion(question.content.rule.parentId, (PQ) => { PQ.content.rule = newRule; @@ -101,10 +117,13 @@ export const DeleteFunction = async (questionId: string) => { //сделать результ родителя видимым если у него не осталось потомков if (startCountParentChildren.length === 1) { - if (parentResult) { - await updateQuestion(parentResult.content.id, (q) => { - q.content.usage = true; - }); + if (parentResult?.type) { + await updateQuestion( + parentResult.content.id, + (item) => { + item.content.usage = true; + }, + ); } else { //почему-то не существует результа у родителя. Создаём. Новосозданные результы видны сразу await createResult(quiz.backendId, parentQuestion.content.id);