diff --git a/src/model/quizSettings.ts b/src/model/quizSettings.ts index db37e5c4..4efd2ff7 100644 --- a/src/model/quizSettings.ts +++ b/src/model/quizSettings.ts @@ -40,7 +40,7 @@ export interface QuizConfig { theme: string, reply: string, replname: string, - } + }; startpage: { description: string; button: string; @@ -61,12 +61,8 @@ export interface QuizConfig { formContact: { title: string; desc: string; - name: FCField; - email: FCField; - phone: FCField; - text: FCField; - address: FCField; - button: string + fields: Record; + button: string; }; info: { phonenumber: string; @@ -78,13 +74,20 @@ export interface QuizConfig { meta: string; } -type FCField = { - text: string - innerText: string - key: string - required: boolean - used: boolean -} +export type FormContactFieldName = "name" | "email" | "phone" | "text" | "address"; + +type FormContactFieldData = { + text: string; + innerText: string; + key: string; + required: boolean; + used: boolean; +}; + +export type FieldSettingsDrawerState = { + field: FormContactFieldName | "all" | "", + isEdit: boolean; +}; export const defaultQuizConfig: QuizConfig = { type: null, @@ -127,42 +130,44 @@ export const defaultQuizConfig: QuizConfig = { formContact: { title: "", desc: "", - name: { - text: "", - innerText: "", - key: "", - required: false, - used: true + fields: { + name: { + text: "", + innerText: "", + key: "", + required: false, + used: true + }, + email: { + text: "", + innerText: "", + key: "", + required: false, + used: true + }, + phone: { + text: "", + innerText: "", + key: "", + required: false, + used: true + }, + text: { + text: "", + innerText: "", + key: "", + required: false, + used: false + }, + address: { + text: "", + innerText: "", + key: "", + required: false, + used: false + }, }, - email: { - text: "", - innerText: "", - key: "", - required: false, - used: true - }, - phone: { - text: "", - innerText: "", - key: "", - required: false, - used: true - }, - text: { - text: "", - innerText: "", - key: "", - required: false, - used: false - }, - address: { - text: "", - innerText: "", - key: "", - required: false, - used: false - }, - button: "" + button: "", }, meta: "", }; diff --git a/src/pages/ContactFormPage/ContactFormPage.tsx b/src/pages/ContactFormPage/ContactFormPage.tsx index 44e9f9e9..c225fe0e 100644 --- a/src/pages/ContactFormPage/ContactFormPage.tsx +++ b/src/pages/ContactFormPage/ContactFormPage.tsx @@ -2,7 +2,7 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import { Box, Button, IconButton, Link, Paper, SxProps, TextField, Theme, Typography, useTheme, Popover, useMediaQuery, Divider } from "@mui/material"; import { incrementCurrentStep, updateQuiz } from "@root/quizes/actions"; import CustomTextField from "@ui_kit/CustomTextField"; -import React from "react"; +import React, { ReactNode, useRef, useState } from "react"; import Info from "../../assets/icons/Info"; import Trash from "@icons/trash"; import { OneIcon } from "../../assets/icons/questionsPage/OneIcon"; @@ -17,287 +17,261 @@ import SwitchContactForm from "./switchContactForm"; import GearIcon from "@icons/GearIcon"; import { useQuestionsStore } from "@root/questions/store"; import { useCurrentQuiz } from "@root/quizes/hooks"; +import { FieldSettingsDrawerState, FormContactFieldName } from "@model/quizSettings"; -const buttons = [ - { - name: "Имя", - desc: "Дмитрий", - key: "name" - }, - { - name: "Email", - desc: "mail@example.ru", - key: "email" - }, - { - name: "Номер", - desc: "+7 900 000 00 00", - key: "phone" - }, - { - name: "Фамилия", - desc: "Иванов", - key: "text" - }, - { - name: "Адрес", - desc: "Москва, Лаврушинский пер., 10", - key: "address" - }, -] +const buttons: { key: FormContactFieldName, name: string, desc: string; }[] = [ + { name: "Имя", desc: "Дмитрий", key: "name" }, + { name: "Email", desc: "mail@example.ru", key: "email" }, + { name: "Номер", desc: "+7 900 000 00 00", key: "phone" }, + { name: "Фамилия", desc: "Иванов", key: "text" }, + { name: "Адрес", desc: "Москва, Лаврушинский пер., 10", key: "address" }, +]; export default function ContactFormPage() { - const theme = useTheme(); + const theme = useTheme(); + const quiz = useCurrentQuiz(); + const isTablet = useMediaQuery(theme.breakpoints.down(1000)); + const [drawerNewField, setDrawerNewField] = useState({ field: "", isEdit: false }); + const [drawerMessenger, setDrawerMessenger] = useState(false); - const quiz = useCurrentQuiz() + const drawerMessengerHC = (bool: boolean) => { + setDrawerMessenger(bool); + }; - const isTablet = useMediaQuery(theme.breakpoints.down(1000)) + return ( + + + { - setDrawerNewField(str); - }; - const drawerMessengerHC = (bool: boolean) => { - setDrawerMessenger(bool); - }; - - return ( - - - - - - Как собрать данные посетителя - {" "} - {/* + }} + > + Как собрать данные посетителя + {" "} + {/* */} - - - - - { - !quiz?.config.formContact.name.used && - !quiz?.config.formContact.email.used && - !quiz?.config.formContact.phone.used && - !quiz?.config.formContact.text.used && - !quiz?.config.formContact.address.used ? - - - - : - - - - } - - - - - - + + { + !quiz?.config.formContact.fields.name.used && + !quiz?.config.formContact.fields.email.used && + !quiz?.config.formContact.fields.phone.used && + !quiz?.config.formContact.fields.text.used && + !quiz?.config.formContact.fields.address.used ? + + + + : + + + + } + + + + + + + setDrawerNewField({ field: "", isEdit: false })}> + setDrawerNewField({ field: "", isEdit: false })} /> + - - - - - - - - - ); + ); } interface Props { - outerContainerSx?: SxProps; - children?: React.ReactNode; + outerContainerSx?: SxProps; + children?: ReactNode; } function ContactFormParent({ outerContainerSx: sx, children }: Props) { - const theme = useTheme(); - const isTablet = useMediaQuery(theme.breakpoints.down(1000)) - const quiz = useCurrentQuiz() - return ( - - - - { - updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact.title = target.value - }) - }} - value={quiz.config.formContact.title} - placeholder="Заголовок формы" text={""} /> - { - updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact.desc = target.value - }) - }} - value={quiz.config.formContact.desc} - id="outlined-multiline-static" - multiline - rows={8} - placeholder="Дополнительный текст формы" + if (!quiz) return null; + + return ( + - - - {children} - - - ); + > + + + { + updateQuiz(quiz.id, (quiz) => { + quiz.config.formContact.title = target.value; + }); + }} + value={quiz.config.formContact.title} + placeholder="Заголовок формы" text={""} /> + { + updateQuiz(quiz.id, (quiz) => { + quiz.config.formContact.desc = target.value; + }); + }} + value={quiz.config.formContact.desc} + id="outlined-multiline-static" + multiline + rows={8} + placeholder="Дополнительный текст формы" + sx={{ + backgroundColor: theme.palette.background.default, + + "& .MuiInputBase-root": { + borderRadius: "10px", + alignItems: "start", + color: theme.palette.grey2.main, + color: "black", + }, + }} + /> + + + {children} + + + ); } -const SettingField = ({ name, placeholder, type, drawerNewFieldHC }: { name: string, placeholder: string, type: string; drawerNewFieldHC: any }) => { - const theme = useTheme(); - const quiz = useCurrentQuiz() - return ( - <> - {quiz.config.formContact[type].text || name} - - - {quiz.config.formContact[type].innerText || placeholder} - drawerNewFieldHC(type)} - sx={{ - position: "absolute", - right: "0" - }}> - - - - updateQuiz(quiz?.id, (quiz) => { - quiz.config.formContact[type].used = false - })} - sx={{ - width: "48px", - ml: "5px" - }} - > - +const SettingField = ({ name, placeholder, type, drawerNewFieldHC }: { name: string, placeholder: string, type: FormContactFieldName; drawerNewFieldHC: (state: FieldSettingsDrawerState) => void; }) => { + const theme = useTheme(); + const quiz = useCurrentQuiz(); - - - - ) -} + if (!quiz) return null; -const ButtonsCard = ({ drawerNewFieldHC }: any) => { - const theme = useTheme(); - const quiz = useCurrentQuiz() + return ( + <> + {quiz.config.formContact.fields[type].text || name} + + + {quiz.config.formContact.fields[type].innerText || placeholder} + drawerNewFieldHC({ field: type, isEdit: true })} + sx={{ + position: "absolute", + right: "0" + }}> + + + + updateQuiz(quiz?.id, (quiz) => { + quiz.config.formContact.fields[type].used = false; + })} + sx={{ + width: "48px", + ml: "5px" + }} + > + - return ( - + + + + ); +}; - { - buttons.map((contentData) => { - const content = quiz?.config.formContact[contentData.key] - return content.used ? : <> - }) - } +const ButtonsCard = ({ drawerNewFieldHC }: { drawerNewFieldHC: (state: FieldSettingsDrawerState) => void; }) => { + const theme = useTheme(); + const quiz = useCurrentQuiz(); - { - ( - quiz?.config.formContact.name.used && - quiz?.config.formContact.email.used && - quiz?.config.formContact.phone.used && - quiz?.config.formContact.text.used && - quiz?.config.formContact.address.used - ) ? - <> - : - - } - {/* + {buttons.flatMap((contentData) => { + const content = quiz.config.formContact.fields[contentData.key]; + return content.used ? ( + + ) : []; + })} + {( + quiz.config.formContact.fields.name.used && + quiz.config.formContact.fields.email.used && + quiz.config.formContact.fields.phone.used && + quiz.config.formContact.fields.text.used && + quiz.config.formContact.fields.address.used + ) ? + <> + : + + } + {/* drawerMessengerHC(true)} sx={{ @@ -311,51 +285,51 @@ const ButtonsCard = ({ drawerNewFieldHC }: any) => { Добавить мессенджеры */} - - - ) -} -const EmptyCard = ({ drawerNewFieldHC }: { drawerNewFieldHC: (a: string) => void }) => { - const theme = useTheme(); - const [FC, setFC] = React.useState(false) - const openFC = () => setFC(true) - const closeFC = () => setFC(false) - const popover = React.useRef(null); - - return ( - - - - Будут показаны поля по умолчанию - - + + ); +}; +const EmptyCard = ({ drawerNewFieldHC }: { drawerNewFieldHC: (state: FieldSettingsDrawerState) => void; }) => { + const theme = useTheme(); + const [FC, setFC] = useState(false); + const openFC = () => setFC(true); + const closeFC = () => setFC(false); + const popover = useRef(null); - - - Будут поля:

Имя, Email, Телефон -
+ return ( + + + + Будут показаны поля по умолчанию + + + -
-
- {/* + + Будут поля:

Имя, Email, Телефон +
+ + +
+ {/* void > Добавить мессенджеры */} - - - ) -} + + + ); +}; const PseudoButton = () => { - const quiz = useCurrentQuiz() - return ( - { - updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact.button = target.value - }) - }} - value={quiz.config.formContact.button} - sx={{ - heigth: "44px", - width: "190px", - "& .MuiInputBase-root": { - backgroundColor: "#7E2AEA", - borderRadius: "8px", - color: "white", - }, - "& .MuiInputBase-input": { - padding: "10px 20px", - textAlign: "center" - }, - "& .MuiInputBase-input::placeholder": { - color: "white", - opacity: "1" - } - }} - placeholder="Название кнопки" - > - {quiz?.config.formContact.button || "Название кнопки"} - + const quiz = useCurrentQuiz(); - ) -} \ No newline at end of file + if (!quiz) return null; + + return ( + { + updateQuiz(quiz.id, (quiz) => { + quiz.config.formContact.button = target.value; + }); + }} + value={quiz.config.formContact.button} + sx={{ + heigth: "44px", + width: "190px", + "& .MuiInputBase-root": { + backgroundColor: "#7E2AEA", + borderRadius: "8px", + color: "white", + }, + "& .MuiInputBase-input": { + padding: "10px 20px", + textAlign: "center" + }, + "& .MuiInputBase-input::placeholder": { + color: "white", + opacity: "1" + } + }} + placeholder="Название кнопки" + > + {quiz.config.formContact.button || "Название кнопки"} + + + ); +}; diff --git a/src/pages/ContactFormPage/NewField/ButtonsNewField.tsx b/src/pages/ContactFormPage/NewField/ButtonsNewField.tsx deleted file mode 100644 index 3ca2d7e2..00000000 --- a/src/pages/ContactFormPage/NewField/ButtonsNewField.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import MiniButtonSetting from "@ui_kit/MiniButtonSetting"; -import React from "react"; -import {Box, IconButton, useTheme} from "@mui/material"; -import NameIcon from "@icons/ContactFormIcon/NameIcon"; -import EmailIcon from "@icons/ContactFormIcon/EmailIcon"; -import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon"; -import TextIcon from "@icons/ContactFormIcon/TextIcon"; -import AddressIcon from "@icons/ContactFormIcon/AddressIcon"; -import { useCurrentQuiz } from "@root/quizes/hooks"; - -interface Props { - switchState: string - SSHC: (data:string) => void - type: string -} - -export default function ButtonsNewField ({SSHC, switchState, type}:Props) { - const theme = useTheme(); - const quiz = useCurrentQuiz() - const buttonSetting: {icon: JSX.Element; title: string; value: string} [] =[ - {icon: , title: 'Имя', value: 'name'}, - {icon: , title: 'Email', value: 'email'}, - {icon: , title: 'Телефон', value: 'phone'}, - {icon: , title: 'Текст', value: 'text'}, - {icon: , title: 'Адрес', value: 'address'}, - ] - - return ( - - {buttonSetting.map( (e,i) => ( - type === e.value || type === "all" ? - {SSHC(e.value)}} - sx={{backgroundColor: switchState === e.value ? theme.palette.brightPurple.main : 'transparent', - color: switchState === e.value && type === "all" ? '#ffffff' : theme.palette.grey3.main, - }} - > - {e.icon} - {e.title} - - : - <> - ))} - - ) -} \ No newline at end of file diff --git a/src/pages/ContactFormPage/NewField/NewFieldParent.tsx b/src/pages/ContactFormPage/NewField/NewFieldParent.tsx index 4dc46078..178bf7b4 100644 --- a/src/pages/ContactFormPage/NewField/NewFieldParent.tsx +++ b/src/pages/ContactFormPage/NewField/NewFieldParent.tsx @@ -6,18 +6,22 @@ import Button from "@mui/material/Button"; import * as React from "react"; import { useCurrentQuiz } from "@root/quizes/hooks"; import { updateQuiz } from "@root/quizes/actions"; +import { FormContactFieldName } from "@model/quizSettings"; interface Props { outerContainerSx?: SxProps; children?: React.ReactNode; - defaultValue?: string; + defaultValue: FormContactFieldName; placeholderHelp: string; placeholderField: string; - drawerNewFieldHC:(a:string)=>void + closeDrawer: () => void; } -export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeholderHelp, placeholderField, outerContainerSx: sx, children }: Props) { - const quiz = useCurrentQuiz() +export default function NewFieldParent({ closeDrawer, defaultValue, placeholderHelp, placeholderField, outerContainerSx: sx, children }: Props) { + const quiz = useCurrentQuiz(); + + if (!quiz) return null; + return ( @@ -26,10 +30,10 @@ export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeho { updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact[defaultValue].text = target.value - }) + quiz.config.formContact.fields[defaultValue].text = target.value; + }); }} - value={quiz.config.formContact[defaultValue].text} + value={quiz.config.formContact.fields[defaultValue].text} placeholder={placeholderHelp} text={''} /> @@ -39,10 +43,10 @@ export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeho { updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact[defaultValue].innerText = target.value - }) + quiz.config.formContact.fields[defaultValue].innerText = target.value; + }); }} - value={quiz.config.formContact[defaultValue].innerText} + value={quiz.config.formContact.fields[defaultValue].innerText} placeholder={placeholderField} text={''} /> @@ -50,11 +54,11 @@ export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeho Ключ { updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact[defaultValue].key = target.value - }) + quiz.config.formContact.fields[defaultValue].key = target.value; + }); }} placeholder="text" sx={{ @@ -67,14 +71,13 @@ export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeho backgroundColor: '#EEE4FC', }, }} - /> { updateQuiz(quiz.id, (quiz) => { - quiz.config.formContact[defaultValue].required = target.checked - }) + quiz.config.formContact.fields[defaultValue].required = target.checked; + }); }} label={"Обязательно к заполнению"} /> @@ -88,11 +91,11 @@ export default function NewFieldParent({ drawerNewFieldHC, defaultValue, placeho - ) + ); } diff --git a/src/pages/ContactFormPage/NewField/SwitchNewField.tsx b/src/pages/ContactFormPage/NewField/SwitchNewField.tsx index 2a962539..30c62c32 100644 --- a/src/pages/ContactFormPage/NewField/SwitchNewField.tsx +++ b/src/pages/ContactFormPage/NewField/SwitchNewField.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import NewFieldParent from "./NewFieldParent"; -import {FormControlLabel} from "@mui/material"; +import { FormControlLabel } from "@mui/material"; import SelectMask from "../SelectMask"; import CustomizedSwitch from "@ui_kit/CustomSwitch"; @@ -8,27 +8,25 @@ import CustomizedSwitch from "@ui_kit/CustomSwitch"; interface Props { switchState: string, - drawerNewFieldHC:(a:string)=>void + closeDrawer: () => void; } -export default function SwitchNewField({switchState ='name', drawerNewFieldHC}: Props) { +export default function SwitchNewField({ switchState = 'name', closeDrawer }: Props) { const [SwitchMask, setSwitchMask] = React.useState(false); - const SwitchMaskHC = (bool:boolean) => { - setSwitchMask(bool) - } + const SwitchMaskHC = (bool: boolean) => { + setSwitchMask(bool); + }; switch (switchState) { case 'name': - return (); - break; + return (); case 'email': - return (); - break; + return (); case 'phone': return ( - + {/* } @@ -45,20 +43,17 @@ export default function SwitchNewField({switchState ='name', drawerNewFieldHC}: /> */} {SwitchMask ? - + : <> } ); - break; case 'text': - return (); - break; + return (); case 'address': - return (); - break; + return (); default: - return (<>) + return (<>); } -} \ No newline at end of file +} diff --git a/src/pages/ContactFormPage/NewField/WindowNewField.tsx b/src/pages/ContactFormPage/NewField/WindowNewField.tsx index a7c69458..24fd64d7 100644 --- a/src/pages/ContactFormPage/NewField/WindowNewField.tsx +++ b/src/pages/ContactFormPage/NewField/WindowNewField.tsx @@ -1,39 +1,87 @@ -import * as React from 'react'; +import AddressIcon from "@icons/ContactFormIcon/AddressIcon"; +import EmailIcon from "@icons/ContactFormIcon/EmailIcon"; +import NameIcon from "@icons/ContactFormIcon/NameIcon"; +import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon"; +import TextIcon from "@icons/ContactFormIcon/TextIcon"; +import { FieldSettingsDrawerState, FormContactFieldName } from "@model/quizSettings"; +import CloseIcon from '@mui/icons-material/Close'; +import { Typography, useTheme } from "@mui/material"; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; -import { Typography, useTheme } from "@mui/material"; -import CloseIcon from '@mui/icons-material/Close'; -import ButtonsNewField from "./ButtonsNewField"; -import SwitchNewField from "./SwitchNewField"; import { useCurrentQuiz } from '@root/quizes/hooks'; +import MiniButtonSetting from "@ui_kit/MiniButtonSetting"; +import { useEffect, useState } from 'react'; +import SwitchNewField from "./SwitchNewField"; -export default function WindowNewField({ type, drawerNewFieldHC }: { type: string, drawerNewFieldHC: (a: string) => void }) { - const quiz = useCurrentQuiz() +interface Props { + drawerState: FieldSettingsDrawerState; + closeDrawer: () => void; +} + +export default function WindowNewField({ drawerState, closeDrawer }: Props) { + const quiz = useCurrentQuiz(); const theme = useTheme(); - const [switchState, setSwitchState] = React.useState(""); - React.useEffect(() => { - for (let val in quiz?.config.formContact) { - if (!quiz?.config.formContact[val]?.used && (val !== "title" && val !== "desc" && val !== "button")) { - setSwitchState(val) - return + const [switchState, setSwitchState] = useState(""); + + useEffect(() => { + if (!quiz) return; + + if (drawerState.isEdit) { + return setSwitchState(drawerState.field); + } + + for (let val in quiz.config.formContact.fields) { + if (!quiz.config.formContact.fields[val as FormContactFieldName].used) { + setSwitchState(val); + return; } } - }, []) + }, []); + + if (!quiz) return null; const SSHC = (data: string) => { - setSwitchState(data) - } + setSwitchState(data); + }; + + const buttonSetting: { icon: JSX.Element; title: string; value: FormContactFieldName; }[] = [ + { icon: , title: 'Имя', value: 'name' }, + { icon: , title: 'Email', value: 'email' }, + { icon: , title: 'Телефон', value: 'phone' }, + { icon: , title: 'Текст', value: 'text' }, + { icon: , title: 'Адрес', value: 'address' }, + ]; return ( <> Новое поле - + - - - + + {buttonSetting.flatMap((e, i) => ( + drawerState.field === e.value || drawerState.field === "all" + ? { SSHC(e.value); }} + sx={{ + backgroundColor: switchState === e.value ? theme.palette.brightPurple.main : 'transparent', + color: switchState === e.value && drawerState.field === "all" ? '#ffffff' : theme.palette.grey3.main, + }} + > + {e.icon} + {e.title} + + : [] + ))} + + - ) -} \ No newline at end of file + ); +}