import Stack from "@mui/material/Stack"; import { TextInput } from "@/Components/v2/Inputs/TextInput"; import { AutoCompleteInput } from "@/Components/v2/Inputs/AutoComplete"; import { ConfigBox, BasePage } from "@/Components/v2/DesignElements"; import RadioGroup from "@mui/material/RadioGroup"; import FormControl from "@mui/material/FormControl"; import { RadioWithDescription } from "@/Components/v2/Inputs/RadioInput"; import { Button } from "@/Components/v2/Inputs"; import DeleteOutlineRoundedIcon from "@mui/icons-material/DeleteOutlineRounded"; import { Typography } from "@mui/material"; import { useTranslation } from "react-i18next"; import { monitorSchema } from "@/Validation/v2/zod"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm, Controller, useWatch, type SubmitHandler } from "react-hook-form"; import { useTheme } from "@mui/material/styles"; import { useInitForm } from "@/Hooks/v2/useInitMonitorForm"; type FormValues = z.infer; export const UptimeForm = ({ initialData, onSubmit, notificationOptions, loading, }: { initialData?: Partial; onSubmit: SubmitHandler; notificationOptions: any[]; loading: boolean; }) => { const { t } = useTranslation(); const theme = useTheme(); const { defaults } = useInitForm({ initialData: initialData }); const { handleSubmit, control, setValue, formState: { errors }, } = useForm({ resolver: zodResolver(monitorSchema) as any, defaultValues: defaults, mode: "onChange", }); const selectedType = useWatch({ control, name: "type", }); const notificationChannels = useWatch({ control, name: "notificationChannels", }); return ( ( )} /> } /> ( )} /> ( )} /> } /> ( { const target = e.target as HTMLInputElement; field.onChange(target.valueAsNumber); }} /> )} /> } /> ( option.name} value={notificationOptions.filter((o: any) => (field.value || []).includes(o._id) )} onChange={(_, newValue) => { field.onChange(newValue.map((o: any) => o._id)); }} /> )} /> {notificationChannels.map((notificationId) => { const option = notificationOptions.find( (o: any) => o._id === notificationId ); if (!option) return null; return ( {option.name} { const updated = notificationChannels.filter( (id) => id !== notificationId ); setValue("notificationChannels", updated); }} sx={{ cursor: "pointer" }} /> ); })} } /> ( )} /> } /> ); };