import { MembershipRole } from "@prisma/client"; import { useState } from "react"; import React, { SyntheticEvent } from "react"; import { useLocale } from "@lib/hooks/useLocale"; import { trpc } from "@lib/trpc"; import Button from "@components/ui/Button"; import ModalContainer from "@components/ui/ModalContainer"; export default function MemberChangeRoleModal(props: { memberId: number; teamId: number; initialRole: MembershipRole; onExit: () => void; }) { const [role, setRole] = useState(props.initialRole || MembershipRole.MEMBER); const [errorMessage, setErrorMessage] = useState(""); const { t } = useLocale(); const utils = trpc.useContext(); const changeRoleMutation = trpc.useMutation("viewer.teams.changeMemberRole", { async onSuccess() { await utils.invalidateQueries(["viewer.teams.get"]); props.onExit(); }, async onError(err) { setErrorMessage(err.message); }, }); function changeRole(e: SyntheticEvent) { e.preventDefault(); changeRoleMutation.mutate({ teamId: props.teamId, memberId: props.memberId, role, }); } return ( <>
{errorMessage && (

Error: {errorMessage}

)}
); }