2023-12-21 16:22:40 +00:00
|
|
|
|
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";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import {
|
|
|
|
|
|
FieldSettingsDrawerState,
|
|
|
|
|
|
FormContactFieldName,
|
|
|
|
|
|
} from "@model/quizSettings";
|
|
|
|
|
|
import CloseIcon from "@mui/icons-material/Close";
|
2023-12-21 16:22:40 +00:00
|
|
|
|
import { Typography, useTheme } from "@mui/material";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import Box from "@mui/material/Box";
|
|
|
|
|
|
import Button from "@mui/material/Button";
|
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2023-12-21 16:22:40 +00:00
|
|
|
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import { useEffect, useState } from "react";
|
2023-12-21 16:22:40 +00:00
|
|
|
|
import SwitchNewField from "./SwitchNewField";
|
2023-04-17 02:27:22 +00:00
|
|
|
|
|
2023-12-21 16:22:40 +00:00
|
|
|
|
interface Props {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
drawerState: FieldSettingsDrawerState;
|
|
|
|
|
|
closeDrawer: () => void;
|
2023-12-21 16:22:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function WindowNewField({ drawerState, closeDrawer }: Props) {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const [switchState, setSwitchState] = useState("");
|
2023-12-21 16:22:40 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!quiz) return;
|
2023-12-21 16:22:40 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
if (drawerState.isEdit) {
|
|
|
|
|
|
return setSwitchState(drawerState.field);
|
|
|
|
|
|
}
|
2023-12-21 16:22:40 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
for (let val in quiz.config.formContact.fields) {
|
|
|
|
|
|
if (!quiz.config.formContact.fields[val as FormContactFieldName].used) {
|
|
|
|
|
|
setSwitchState(val);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
2023-12-21 16:22:40 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
if (!quiz) return null;
|
2023-12-16 04:20:07 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
|
};
|
2023-12-21 16:22:40 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const buttonSetting: {
|
|
|
|
|
|
icon: JSX.Element;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
value: FormContactFieldName;
|
|
|
|
|
|
}[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
icon: (
|
|
|
|
|
|
<NameIcon
|
|
|
|
|
|
color={switchState === "name" ? "#ffffff" : theme.palette.grey3.main}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
title: "Имя",
|
|
|
|
|
|
value: "name",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
icon: (
|
|
|
|
|
|
<EmailIcon
|
|
|
|
|
|
color={switchState === "email" ? "#ffffff" : theme.palette.grey3.main}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
title: "Email",
|
|
|
|
|
|
value: "email",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
icon: (
|
|
|
|
|
|
<PhoneIcon
|
|
|
|
|
|
color={switchState === "phone" ? "#ffffff" : theme.palette.grey3.main}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
title: "Телефон",
|
|
|
|
|
|
value: "phone",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
icon: (
|
|
|
|
|
|
<TextIcon
|
|
|
|
|
|
color={switchState === "text" ? "#ffffff" : theme.palette.grey3.main}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
title: "Текст",
|
|
|
|
|
|
value: "text",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
icon: (
|
|
|
|
|
|
<AddressIcon
|
|
|
|
|
|
color={
|
|
|
|
|
|
switchState === "address" ? "#ffffff" : theme.palette.grey3.main
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
title: "Адрес",
|
|
|
|
|
|
value: "address",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2023-04-17 02:27:22 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
padding: "10px 10px 10px 20px",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
background: theme.palette.background.default,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography>Новое поле</Typography>
|
|
|
|
|
|
<Button onClick={closeDrawer} sx={{ padding: 0 }}>
|
|
|
|
|
|
<CloseIcon fontSize="large" />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
padding: "20px",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
gap: "10px",
|
2024-01-05 05:21:39 +00:00
|
|
|
|
flexWrap: "wrap"
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{buttonSetting.flatMap((e, i) =>
|
|
|
|
|
|
drawerState.field === e.value || drawerState.field === "all" ? (
|
|
|
|
|
|
<MiniButtonSetting
|
|
|
|
|
|
disabled={quiz.config.formContact.fields[e.value].used}
|
|
|
|
|
|
key={i}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
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}
|
|
|
|
|
|
</MiniButtonSetting>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
[]
|
|
|
|
|
|
),
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<SwitchNewField switchState={switchState} closeDrawer={closeDrawer} />
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-12-21 16:22:40 +00:00
|
|
|
|
}
|