import { useMemo } from "react"; import { Controller, useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc"; import { Button, Dialog, DialogContent, DialogFooter, Form, Label, Select, showToast } from "@calcom/ui"; type InvitationLinkSettingsModalProps = { isOpen: boolean; teamId: number; token: string; expiresInDays?: number; onExit: () => void; }; export interface LinkSettingsForm { expiresInDays: number | undefined; } export default function InviteLinkSettingsModal(props: InvitationLinkSettingsModalProps) { const { t } = useLocale(); const trpcContext = trpc.useContext(); const deleteInviteMutation = trpc.viewer.teams.deleteInvite.useMutation({ onSuccess: () => { showToast(t("invite_link_deleted"), "success"); trpcContext.viewer.teams.get.invalidate(); trpcContext.viewer.teams.list.invalidate(); props.onExit(); }, onError: (e) => { showToast(e.message, "error"); }, }); const setInviteExpirationMutation = trpc.viewer.teams.setInviteExpiration.useMutation({ onSuccess: () => { showToast(t("invite_link_updated"), "success"); trpcContext.viewer.teams.get.invalidate(); trpcContext.viewer.teams.list.invalidate(); }, onError: (e) => { showToast(e.message, "error"); }, }); const expiresInDaysOption = useMemo(() => { return [ { value: 1, label: t("one_day") }, { value: 7, label: t("seven_days") }, { value: 30, label: t("thirty_days") }, { value: undefined, label: t("never_expires") }, ]; }, [t]); const linkSettingsFormMethods = useForm(); const handleSubmit = (values: LinkSettingsForm) => { setInviteExpirationMutation.mutate({ token: props.token, expiresInDays: values.expiresInDays, }); }; return ( { props.onExit(); linkSettingsFormMethods.reset(); }}>
(