From fbb6025512674a4625e964e93a9a56a8418d00fe Mon Sep 17 00:00:00 2001 From: Nastya Date: Mon, 2 Jun 2025 01:02:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B8=D1=82=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/PersonalizationAI/AuditoryLink.tsx | 5 +- .../GenderAndAgeSelector.tsx | 374 ++++++++++-------- .../PersonalizationAI/PersonalizationAI.tsx | 12 +- 3 files changed, 218 insertions(+), 173 deletions(-) diff --git a/src/pages/PersonalizationAI/AuditoryLink.tsx b/src/pages/PersonalizationAI/AuditoryLink.tsx index e0cbe976..9264d420 100644 --- a/src/pages/PersonalizationAI/AuditoryLink.tsx +++ b/src/pages/PersonalizationAI/AuditoryLink.tsx @@ -2,6 +2,7 @@ import { AuditoryItem } from "@/api/auditory"; import CopyIcon from "@/assets/icons/CopyIcon"; import Trash from "@/assets/icons/trash"; import { InfoPopover } from "@/ui_kit/InfoPopover"; +import TooltipClickInfo from "@/ui_kit/Toolbars/TooltipClickInfo"; import { useDomainDefine } from "@/utils/hooks/useDomainDefine"; import { IconButton, ListItem, Typography, useTheme } from "@mui/material"; @@ -42,7 +43,7 @@ export const AuditoryLink = ({ item, index, onDelete }: AuditoryLinkProps) => { display: 'flex', alignItems: 'center', gap: '12px', - width: "60px", + width: "70px", justifyContent: "space-between", }, }} @@ -61,7 +62,7 @@ export const AuditoryLink = ({ item, index, onDelete }: AuditoryLinkProps) => { }} /> - + void; + handleAdd: (item: any) => void; } - -export default function GenderAndAgeSelector({ gender, setGender }: GenderAndAgeSelectorProps) { +export default function GenderAndAgeSelector({ handleAdd }: GenderAndAgeSelectorProps) { const theme = useTheme(); + const [age, setAge] = useState(''); + const [gender, setGender] = useState(''); + const quiz = useCurrentQuiz(); + const { enqueueSnackbar } = useSnackbar(); + + const isFormValid = gender && age; + + const addItem = async () => { + if (!quiz?.backendId) { + enqueueSnackbar('Ошибка: не выбран квиз', { variant: 'error' }); + return; + } + + try { + const [result, error] = await auditoryAdd({ + quizId: quiz.backendId, + body: { + sex: gender === "male", + age + } + }); + + if (error) { + enqueueSnackbar('Не удалось добавить ссылку', { variant: 'error' }); + return; + } + + if (result) { + handleAdd({ + id: result.ID, + quiz_id: quiz.backendId, + sex: gender === "male", + age, + deleted: false, + }); + enqueueSnackbar('Ссылка успешно добавлена', { variant: 'success' }); + // Очищаем форму + setGender(''); + setAge(''); + } + } catch (error) { + enqueueSnackbar('Произошла ошибка при добавлении', { variant: 'error' }); + } + }; + return ( - + + - - - - - + + Пол + + + setGender(e.target.value)} + > + } checkedIcon={} />} + label="М" + /> + } checkedIcon={} />} + label="Ж" + /> + + + + + + Пол - - - setGender(e.target.value)}> - - Возраст + + + + + - value="male" control={} checkedIcon={} />} label="М" /> - } checkedIcon={} />} label="Ж" /> - - - - - - - - Возраст - - - - - + ); } \ No newline at end of file diff --git a/src/pages/PersonalizationAI/PersonalizationAI.tsx b/src/pages/PersonalizationAI/PersonalizationAI.tsx index 9330b162..b2686e52 100644 --- a/src/pages/PersonalizationAI/PersonalizationAI.tsx +++ b/src/pages/PersonalizationAI/PersonalizationAI.tsx @@ -1,11 +1,8 @@ import { Box, Container, Typography, TextField, Button, List, ListItem, IconButton, Modal } from "@mui/material"; import { InfoPopover } from '@ui_kit/InfoPopover'; -import CopyIcon from "@/assets/icons/CopyIcon"; import GenderAndAgeSelector from "./GenderAndAgeSelector"; import { useEffect, useState } from "react"; import CustomTextField from "@ui_kit/CustomTextField"; -import Collapse from '@mui/material/Collapse'; -import { ArrowDownIcon } from "../../assets/icons/questionsPage/ArrowDownIcon"; import { useTheme } from "@mui/material"; import { AuditoryItem, auditoryAdd, auditoryDelete, auditoryGet } from "@/api/auditory"; import { useCurrentQuiz } from "@/stores/quizes/hooks"; @@ -15,7 +12,6 @@ import { useSnackbar } from "notistack"; export default function PersonalizationAI() { const theme = useTheme(); - const [gender, setGender] = useState(''); const [auditory, setAuditory] = useState([]); const [deleteModal, setDeleteModal] = useState(0); const quiz = useCurrentQuiz(); @@ -75,9 +71,13 @@ export default function PersonalizationAI() { } } + const handleAdd = (item:AuditoryItem) => { + setAuditory(old => ([...old, item])) + } + return ( <> - + Персонализация вопросов с помощью AI @@ -100,7 +100,7 @@ export default function PersonalizationAI() { boxShadow: "none", maxWidth: "796px" }}> - + {/* Ссылка */}