import { zodResolver } from "@hookform/resolvers/zod"; import { Dispatch, SetStateAction } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { EventLocationType, getEventLocationType } from "@calcom/app-store/locations"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { showToast, Dialog, DialogContent, Form, TextField, DialogFooter, Button, DialogClose, } from "@calcom/ui"; import { FiAlertCircle } from "@calcom/ui/components/icon"; type LocationTypeSetLinkDialogFormProps = { link?: string; type: EventLocationType["type"]; }; export function AppSetDefaultLinkDailog({ locationType, setLocationType, }: { locationType: EventLocationType & { slug: string }; setLocationType: Dispatch>; }) { const utils = trpc.useContext(); const { t } = useLocale(); const eventLocationTypeOptions = getEventLocationType(locationType.type); const form = useForm({ resolver: zodResolver( z.object({ link: z.string().regex(new RegExp(eventLocationTypeOptions?.urlRegExp ?? "")) }) ), }); const updateDefaultAppMutation = trpc.viewer.updateUserDefaultConferencingApp.useMutation({ onSuccess: () => { showToast("Default app updated successfully", "success"); utils.viewer.getUsersDefaultConferencingApp.invalidate(); }, onError: () => { showToast(`Invalid App Link Format`, "error"); }, }); return ( setLocationType(undefined)}>
{ updateDefaultAppMutation.mutate({ appSlug: locationType.slug, appLink: values.link, }); setLocationType(undefined); }}> <>
); }