diff --git a/src/pages/Questions/OwnTextField/OwnTextField.tsx b/src/pages/Questions/OwnTextField/OwnTextField.tsx index cbb154d4..0d6c0dbc 100644 --- a/src/pages/Questions/OwnTextField/OwnTextField.tsx +++ b/src/pages/Questions/OwnTextField/OwnTextField.tsx @@ -1,19 +1,28 @@ +import { useState } from "react"; import { Box, Typography, useTheme } from "@mui/material"; + +import CustomTextField from "@ui_kit/CustomTextField"; import ButtonsOptions from "../ButtonsOptions"; import SwitchTextField from "./switchTextField"; -import React from "react"; -import CustomTextField from "@ui_kit/CustomTextField"; + +import { questionStore, updateQuestionsList } from "@root/questions"; + import InfoIcon from "../../../assets/icons/InfoIcon"; +import type { ChangeEvent } from "react"; + interface Props { totalIndex: number; } export default function OwnTextField({ totalIndex }: Props) { + const [switchState, setSwitchState] = useState("setting"); + const { listQuestions } = questionStore(); const theme = useTheme(); - const [switchState, setSwitchState] = React.useState("setting"); + const SSHC = (data: string) => { setSwitchState(data); }; + return ( <> - + ) => { + const clonContent = listQuestions[totalIndex].content; + clonContent.placeholder = target.value; + updateQuestionsList(totalIndex, { content: clonContent }); + }} + /> ) => { - setValue((event.target as HTMLInputElement).value); - }; - const theme = useTheme() - return ( - - - Настройки ответов - - - } label="Односточное" /> - } label="Многострочное" /> - } label="Только числа" /> - - - - - Настройки вопросов - - - - - - ); -}; \ No newline at end of file +type SettingTextFieldProps = { + totalIndex: number; +}; + +type Answer = { + name: string; + value: QuestionType; +}; + +const ANSWER_TYPES: Answer[] = [ + { name: "Односточное", value: "single" }, + { name: "Многострочное", value: "multi" }, + { name: "Только числа", value: "number" }, +]; + +export default function SettingTextField({ + totalIndex, +}: SettingTextFieldProps) { + const { listQuestions } = questionStore(); + const theme = useTheme(); + + return ( + + + Настройки ответов + + value === listQuestions[totalIndex].content.type + )} + onChange={({ target }: React.ChangeEvent) => { + const clonContent = listQuestions[totalIndex].content; + clonContent.type = ANSWER_TYPES[Number(target.value)].value; + updateQuestionsList(totalIndex, { content: clonContent }); + }} + > + {ANSWER_TYPES.map(({ name }, index) => ( + } + label={name} + /> + ))} + + + + + Настройки вопросов + + + + + + ); +} diff --git a/src/pages/Questions/OwnTextField/switchTextField.tsx b/src/pages/Questions/OwnTextField/switchTextField.tsx index e7614655..bc715feb 100644 --- a/src/pages/Questions/OwnTextField/switchTextField.tsx +++ b/src/pages/Questions/OwnTextField/switchTextField.tsx @@ -14,7 +14,7 @@ export default function SwitchTextField({ }: Props) { switch (switchState) { case "setting": - return ; + return ; break; case "help": return ; diff --git a/src/stores/questions.ts b/src/stores/questions.ts index 72016042..64636c58 100644 --- a/src/stores/questions.ts +++ b/src/stores/questions.ts @@ -7,6 +7,8 @@ export type Variants = { hints: string; }; +export type QuestionType = "single" | "multi" | "number"; + type Hint = { text: string; video: string; @@ -40,6 +42,8 @@ export interface Question { own: boolean; innerName: string; back: string; + placeholder: string; + type: QuestionType; }; version: number; parent_ids: number[]; @@ -102,6 +106,8 @@ export const createQuestion = (id: number) => { own: false, innerName: "", back: "", + placeholder: "", + type: "single", variants: [ { answer: "",