"use client"; import Link from "next/link"; import { useRef } from "react"; import { Controller } from "react-hook-form"; import type { UseFormReturn } from "react-hook-form"; import { IS_CALCOM } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; import { Badge } from "@calcom/ui/components/badge"; import { Button } from "@calcom/ui/components/button"; import { Switch, TextAreaField, TextField } from "@calcom/ui/components/form"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetFooter } from "@calcom/ui/components/sheet"; import type { RoutingFormWithResponseCount } from "../../types/types"; import { TeamMemberSelect } from "./TeamMemberSelect"; type FormSettingsSlideoverProps = { form: RoutingFormWithResponseCount; hookForm: UseFormReturn; isOpen: boolean; onOpenChange: (open: boolean) => void; appUrl: string; }; export const FormSettingsSlideover = ({ form, hookForm, isOpen, onOpenChange, appUrl, }: FormSettingsSlideoverProps) => { const { t } = useLocale(); const { data: user } = useMeQuery(); const sendUpdatesTo = hookForm.watch("settings.sendUpdatesTo") || []; const sendToAll = hookForm.watch("settings.sendToAll") || false; // Store initial form values const initialValuesRef = useRef({ name: hookForm.getValues("name"), description: hookForm.getValues("description"), settings: { sendUpdatesTo: hookForm.getValues("settings.sendUpdatesTo") || [], sendToAll: hookForm.getValues("settings.sendToAll") || false, emailOwnerOnSubmission: hookForm.getValues("settings.emailOwnerOnSubmission") || false, }, }); const handleCancel = () => { // Revert only the fields we edit const initialValues = initialValuesRef.current; hookForm.setValue("name", initialValues.name); hookForm.setValue("description", initialValues.description); hookForm.setValue("settings.sendUpdatesTo", initialValues.settings.sendUpdatesTo); hookForm.setValue("settings.sendToAll", initialValues.settings.sendToAll); hookForm.setValue("settings.emailOwnerOnSubmission", initialValues.settings.emailOwnerOnSubmission); onOpenChange(false); }; return ( { if (!open) { handleCancel(); } else { onOpenChange(open); } }}> {t("form_settings")}
{form.teamId ? (
{ hookForm.setValue("settings.sendUpdatesTo", memberIds, { shouldDirty: true }); hookForm.setValue("settings.emailOwnerOnSubmission", false, { shouldDirty: true, }); }} onSelectAll={(selectAll) => { hookForm.setValue("settings.sendToAll", selectAll, { shouldDirty: true }); }} selectAllEnabled={true} sendToAll={sendToAll} placeholder={t("select_members")} />
) : ( { return (
{ onChange(val); hookForm.unregister("settings.sendUpdatesTo"); }} />
); }} /> )}
{form.routers.length ? (
{t("routers")}

{t("modifications_in_fields_warning")}

{form.routers.map((router) => { return (
{router.name}
); })}
) : null} {form.connectedForms?.length ? (
{t("connected_forms")}

{t("form_modifications_warning")}

{form.connectedForms.map((router) => { return (
{router.name}
); })}
) : null}
{IS_CALCOM && ( )}
); };