import { zodResolver } from "@hookform/resolvers/zod"; import type { Dispatch, SetStateAction } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import type { EventLocationType } from "@calcom/app-store/locations"; import { getEventLocationType } from "@calcom/app-store/locations"; import { Dialog } from "@calcom/features/components/controlled-dialog"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Button } from "@calcom/ui/components/button"; import { DialogContent, DialogFooter, DialogClose } from "@calcom/ui/components/dialog"; import { Form } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { showToast } from "@calcom/ui/components/toast"; export type UpdateUsersDefaultConferencingAppParams = { appSlug: string; appLink?: string; onSuccessCallback: () => void; onErrorCallback: () => void; }; type LocationTypeSetLinkDialogFormProps = { link?: string; type: EventLocationType["type"]; }; export function AppSetDefaultLinkDialog({ locationType, setLocationType, onSuccess, handleUpdateUserDefaultConferencingApp, }: { locationType: EventLocationType & { slug: string }; setLocationType: Dispatch>; onSuccess: () => void; handleUpdateUserDefaultConferencingApp: (params: UpdateUsersDefaultConferencingAppParams) => void; }) { const { t } = useLocale(); const eventLocationTypeOptions = getEventLocationType(locationType.type); const form = useForm({ resolver: zodResolver( z.object({ link: z.string().regex(new RegExp(eventLocationTypeOptions?.urlRegExp ?? "")) }) ), }); return ( setLocationType(undefined)}>
{ handleUpdateUserDefaultConferencingApp({ appSlug: locationType.slug, appLink: values.link, onSuccessCallback: () => { onSuccess(); }, onErrorCallback: () => { showToast(`Invalid App Link Format`, "error"); }, }); setLocationType(undefined); }}> <>
); }