import { UsersIcon } from "@heroicons/react/outline"; import { useState } from "react"; import React, { SyntheticEvent } from "react"; import { useLocale } from "@lib/hooks/useLocale"; import { Team } from "@lib/team"; import Button from "@components/ui/Button"; export default function MemberInvitationModal(props: { team: Team | undefined | null; onExit: () => void }) { const [errorMessage, setErrorMessage] = useState(""); const { t, i18n } = useLocale(); const handleError = async (res: Response) => { const responseData = await res.json(); if (res.ok === false) { setErrorMessage(responseData.message); throw new Error(responseData.message); } return responseData; }; const inviteMember = (e: SyntheticEvent) => { e.preventDefault(); const target = e.target as typeof e.target & { elements: { role: { value: string }; inviteUser: { value: string }; sendInviteEmail: { checked: boolean }; }; }; const payload = { language: i18n.language, role: target.elements["role"].value, usernameOrEmail: target.elements["inviteUser"].value, sendEmailInvitation: target.elements["sendInviteEmail"].checked, }; return fetch("/api/teams/" + props?.team?.id + "/invite", { method: "POST", body: JSON.stringify(payload), headers: { "Content-Type": "application/json", }, }) .then(handleError) .then(props.onExit) .catch(() => { // do nothing. }); }; return (

{t("invite_new_team_member")}

{errorMessage && (

Error: {errorMessage}

)}
); }