2023-02-14 13:19:45 +00:00
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
2023-02-13 22:55:32 +00:00
|
|
|
import { Dispatch, SetStateAction } from "react";
|
|
|
|
import { useForm } from "react-hook-form";
|
2023-02-14 13:19:45 +00:00
|
|
|
import { z } from "zod";
|
2023-02-13 22:55:32 +00:00
|
|
|
|
2023-02-14 13:19:45 +00:00
|
|
|
import { EventLocationType, getEventLocationType } from "@calcom/app-store/locations";
|
2023-02-13 22:55:32 +00:00
|
|
|
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<SetStateAction<(EventLocationType & { slug: string }) | undefined>>;
|
|
|
|
}) {
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
|
|
|
|
const { t } = useLocale();
|
2023-02-14 13:19:45 +00:00
|
|
|
const eventLocationTypeOptions = getEventLocationType(locationType.type);
|
|
|
|
|
|
|
|
const form = useForm<LocationTypeSetLinkDialogFormProps>({
|
|
|
|
resolver: zodResolver(
|
|
|
|
z.object({ link: z.string().regex(new RegExp(eventLocationTypeOptions?.urlRegExp ?? "")) })
|
|
|
|
),
|
|
|
|
});
|
2023-02-13 22:55:32 +00:00
|
|
|
|
|
|
|
const updateDefaultAppMutation = trpc.viewer.updateUserDefaultConferencingApp.useMutation({
|
|
|
|
onSuccess: () => {
|
|
|
|
showToast("Default app updated successfully", "success");
|
|
|
|
utils.viewer.getUsersDefaultConferencingApp.invalidate();
|
|
|
|
},
|
2023-02-14 13:19:45 +00:00
|
|
|
onError: () => {
|
|
|
|
showToast(`Invalid App Link Format`, "error");
|
|
|
|
},
|
2023-02-13 22:55:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog open={!!locationType} onOpenChange={() => setLocationType(undefined)}>
|
|
|
|
<DialogContent
|
|
|
|
title={t("default_app_link_title")}
|
|
|
|
description={t("default_app_link_description")}
|
|
|
|
type="creation"
|
|
|
|
Icon={FiAlertCircle}>
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
updateDefaultAppMutation.mutate({
|
|
|
|
appSlug: locationType.slug,
|
|
|
|
appLink: values.link,
|
|
|
|
});
|
|
|
|
setLocationType(undefined);
|
|
|
|
}}>
|
|
|
|
<>
|
|
|
|
<TextField
|
|
|
|
type="text"
|
|
|
|
required
|
|
|
|
{...form.register("link")}
|
|
|
|
placeholder={locationType.organizerInputPlaceholder ?? ""}
|
|
|
|
label={locationType.label ?? ""}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<DialogFooter>
|
|
|
|
<Button color="primary" type="submit">
|
|
|
|
{t("save")}
|
|
|
|
</Button>
|
|
|
|
<DialogClose />
|
|
|
|
</DialogFooter>
|
|
|
|
</>
|
|
|
|
</Form>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|