import { UserIcon } from "@heroicons/react/outline"; import { InformationCircleIcon } from "@heroicons/react/solid"; import { MembershipRole } from "@prisma/client"; import { useState } from "react"; import React, { SyntheticEvent } from "react"; import { useLocale } from "@lib/hooks/useLocale"; import { TeamWithMembers } from "@lib/queries/teams"; import { trpc } from "@lib/trpc"; import { TextField } from "@components/form/fields"; import Button from "@components/ui/Button"; export default function MemberInvitationModal(props: { team: TeamWithMembers | null; onExit: () => void }) { const [errorMessage, setErrorMessage] = useState(""); const { t, i18n } = useLocale(); const utils = trpc.useContext(); 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 (

{t("invite_new_team_member")}

{errorMessage && (

Error: {errorMessage}

)}
); }