import { App_RoutingForms_Form } from "@prisma/client"; import { useEffect } from "react"; import { useForm, UseFormReturn } from "react-hook-form"; import useApp from "@calcom/lib/hooks/useApp"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Icon } from "@calcom/ui"; import { Form } from "@calcom/ui/form/fields"; import { showToast, DropdownMenuSeparator } from "@calcom/ui/v2"; import { ButtonGroup, TextAreaField, TextField, Tooltip, Button, VerticalDivider } from "@calcom/ui/v2"; import Meta from "@calcom/ui/v2/core/Meta"; import { ShellMain } from "@calcom/ui/v2/core/Shell"; import Banner from "@calcom/ui/v2/core/banner"; import { SerializableForm } from "../types/types"; import { FormAction, FormActionsDropdown, FormActionsProvider } from "./FormActions"; import RoutingNavBar from "./RoutingNavBar"; type RoutingForm = SerializableForm; type RoutingFormWithResponseCount = RoutingForm & { _count: { responses: number; }; }; const Actions = ({ form, mutation, }: { form: RoutingFormWithResponseCount; mutation: { isLoading: boolean; }; }) => { const { t } = useLocale(); const { data: typeformApp } = useApp("typeform"); return (
{typeformApp?.isInstalled ? ( {t("Copy Typeform Redirect Url")} ) : null}
{t("preview")} {t("copy_link_to_form")} {t("download_responses")} {t("embed")} {typeformApp ? ( {t("Copy Typeform Redirect Url")} ) : null} {t("delete")}
); }; type SingleFormComponentProps = { form: RoutingFormWithResponseCount; appUrl: string; Page: React.FC<{ form: RoutingFormWithResponseCount; appUrl: string; hookForm: UseFormReturn; }>; }; function SingleForm({ form, appUrl, Page }: SingleFormComponentProps) { const utils = trpc.useContext(); const hookForm = useForm({ defaultValues: form, }); useEffect(() => { hookForm.reset(form); }, [form, hookForm]); const mutation = trpc.useMutation("viewer.app_routing_forms.formMutation", { onSuccess() { showToast("Form updated successfully.", "success"); }, onError() { showToast(`Something went wrong`, "error"); }, onSettled() { utils.invalidateQueries(["viewer.app_routing_forms.formQuery", { id: form.id }]); }, }); return (
{ // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore mutation.mutate({ ...data, }); }}> }>
{!form._count?.responses && ( console.log("dismissed")} /> )}
); } export default function SingleFormWrapper({ form: _form, ...props }: SingleFormComponentProps) { const { data: form, isLoading } = trpc.useQuery(["viewer.app_routing_forms.formQuery", { id: _form.id }], { initialData: _form, }); const { t } = useLocale(); if (isLoading) { // It shouldn't be possible because we are passing the data from SSR to it as initialData. So, no need for skeleton here return null; } if (!form) { throw new Error(t("something_went_wrong")); } return ; }