import { useEffect, useState } from "react"; import { Typography, TextField, Button, RadioGroup, Radio, FormControlLabel, Select, } from "@mui/material"; import { Formik, Field, Form } from "formik"; import { DesktopDatePicker } from "@mui/x-date-pickers/DesktopDatePicker"; import MenuItem from "@mui/material/MenuItem"; import theme from "../../../../theme"; import { requestPrivileges } from "@root/services/privilegies.service"; import { usePrivilegeStore } from "@root/stores/privilegesStore"; import { useCartStore } from "@root/stores/cart"; import type { TextFieldProps } from "@mui/material"; type BonusType = "discount" | "privilege"; type LayerType = "privilege" | "service"; type FormValues = { codeword: string; description: string; greetings: string; dueTo: string; activationCount: string; privilegeId: string; amount: string; layer: string; factor: string; target: string; threshold: string; }; type CustomTextFieldProps = { name: string; label: string; required?: boolean; }; const CustomTextField = ({ name, label, required = false, }: CustomTextFieldProps) => ( ); export const CreatePromocodeForm = () => { const [dueTo, setDueTo] = useState(new Date()); const [bonusType, setBonusType] = useState("discount"); const [layerType, setLayerType] = useState("privilege"); const { privileges } = usePrivilegeStore(); const { cartData } = useCartStore(); const initialValues: FormValues = { codeword: "", description: "", greetings: "", dueTo: "", activationCount: "", privilegeId: "", amount: "", layer: "", factor: "", target: "", threshold: "", }; useEffect(() => { requestPrivileges(); }, []); const createPromocode = (values: FormValues) => { console.log(values); }; return ( {(props) => (
Время существования промокода { if (date) { setDueTo(date); } }} renderInput={(params: TextFieldProps) => } InputProps={{ sx: { height: "40px", color: theme.palette.secondary.main, border: "1px solid", borderColor: theme.palette.secondary.main, "& .MuiSvgIcon-root": { color: theme.palette.secondary.main }, }, }} /> ) => { setBonusType(target.value as BonusType); }} onBlur={props.handleBlur} > } label="Скидка" /> } label="Привилегия" /> {bonusType === "discount" && ( <> ) => { setLayerType(target.value as LayerType); }} onBlur={props.handleBlur} > } label="Привилегия" /> } label="Сервис" /> {layerType === "privilege" ? "Выбор привилегии" : "Выбор сервиса"} ( {name} )) : cartData?.services.map(({ serviceKey }) => ( {serviceKey} )) } /> )} {bonusType === "privilege" && ( <> Выбор привилегии ( {name} ))} /> )} )}
); };