import type { App_RoutingForms_Form } from "@prisma/client"; import type { NextRouter } from "next/router"; import { useRouter } from "next/router"; import { createContext, forwardRef, useContext, useState } from "react"; import { useForm } from "react-hook-form"; import { Controller } from "react-hook-form"; import { v4 as uuidv4 } from "uuid"; import { z } from "zod"; import { classNames } from "@calcom/lib"; import { CAL_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import type { ButtonProps } from "@calcom/ui"; import { Button, ConfirmationDialogContent, Dialog, DialogClose, DialogContent, Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Form, showToast, Switch, TextAreaField, TextField, SettingsToggle, } from "@calcom/ui"; import { FiMoreHorizontal } from "@calcom/ui/components/icon"; import { EmbedButton, EmbedDialog } from "@components/Embed"; import getFieldIdentifier from "../lib/getFieldIdentifier"; import type { SerializableForm } from "../types/types"; type RoutingForm = SerializableForm; const newFormModalQuerySchema = z.object({ action: z.string(), target: z.string().optional(), }); const openModal = (router: NextRouter, option: { target?: string; action: string }) => { const query = { ...router.query, dialog: "new-form", ...option, }; router.push( { pathname: router.pathname, query, }, undefined, { shallow: true } ); }; function NewFormDialog({ appUrl }: { appUrl: string }) { const { t } = useLocale(); const router = useRouter(); const utils = trpc.useContext(); const mutation = trpc.viewer.appRoutingForms.formMutation.useMutation({ onSuccess: (_data, variables) => { router.push(`${appUrl}/form-edit/${variables.id}`); }, onError: () => { showToast(t("something_went_wrong"), "error"); }, onSettled: () => { utils.viewer.appRoutingForms.forms.invalidate(); }, }); const hookForm = useForm<{ name: string; description: string; shouldConnect: boolean; }>(); const { action, target } = router.query as z.infer; const { register } = hookForm; return (

{t("form_description")}

{ const formId = uuidv4(); mutation.mutate({ id: formId, ...values, addFallback: true, duplicateFrom: action === "duplicate" ? target : null, }); }}>
{action === "duplicate" && ( { return ( { onChange(checked); }} /> ); }} /> )}
); } const dropdownCtx = createContext<{ dropdown: boolean }>({ dropdown: false }); export const FormActionsDropdown = ({ form, children }: { form: RoutingForm; children: React.ReactNode }) => { const { disabled } = form; return (