import { MembershipRole } from "@prisma/client"; import React, { useState, SyntheticEvent, useMemo } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { TeamWithMembers } from "@calcom/lib/server/queries/teams"; import { trpc } from "@calcom/trpc/react"; import { Icon } from "@calcom/ui/Icon"; import { Button, Dialog, DialogContent, DialogFooter, Select, TextField } from "@calcom/ui/v2"; type MemberInvitationModalProps = { isOpen: boolean; team: TeamWithMembers | null; currentMember: MembershipRole; onExit: () => void; }; type MembershipRoleOption = { value: MembershipRole; label?: string; }; const _options: MembershipRoleOption[] = [{ value: "MEMBER" }, { value: "ADMIN" }, { value: "OWNER" }]; export default function MemberInvitationModal(props: MemberInvitationModalProps) { const [errorMessage, setErrorMessage] = useState(""); const { t, i18n } = useLocale(); const utils = trpc.useContext(); const options = useMemo(() => { _options.forEach((option, i) => { _options[i].label = t(option.value.toLowerCase()); }); return _options; }, [t]); const inviteMemberMutation = trpc.useMutation("viewer.teams.inviteMember", { async onSuccess() { await utils.invalidateQueries(["viewer.teams.get"]); props.onExit(); }, async onError(err) { setErrorMessage(err.message); }, }); function inviteMember(e: SyntheticEvent) { e.preventDefault(); if (!props.team) return; const target = e.target as typeof e.target & { elements: { role: { value: MembershipRole }; inviteUser: { value: string }; sendInviteEmail: { checked: boolean }; }; }; inviteMemberMutation.mutate({ teamId: props.team.id, language: i18n.language, role: target.elements["role"].value, usernameOrEmail: target.elements["inviteUser"].value, sendEmailInvitation: target.elements["sendInviteEmail"].checked, }); } return ( Note: This will cost an extra seat ($12/m) on your subscription if this invitee does not have a TEAM account. }>
{errorMessage && (

Error: {errorMessage}

)}
); }