import { MembershipRole } from "@prisma/client"; import { useState } from "react"; import React, { SyntheticEvent, useEffect } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import Button from "@calcom/ui/Button"; import { TeamWithMembers } from "@lib/queries/teams"; import { trpc } from "@lib/trpc"; import ModalContainer from "@components/ui/ModalContainer"; import Select from "@components/ui/form/Select"; type MembershipRoleOption = { value: MembershipRole; label?: string; }; const options: MembershipRoleOption[] = [{ value: "MEMBER" }, { value: "ADMIN" }, { value: "OWNER" }]; export default function MemberChangeRoleModal(props: { isOpen: boolean; team: TeamWithMembers; memberId: number; teamId: number; initialRole: MembershipRole; onExit: () => void; }) { useEffect(() => { options.forEach((option, i) => { options[i].label = t(option.value.toLowerCase()); }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const [role, setRole] = useState( options.find((option) => option.value === 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); }, }); const memberRole = props.team?.membership.role; function changeRole(e: SyntheticEvent) { e.preventDefault(); changeRoleMutation.mutate({ teamId: props.teamId, memberId: props.memberId, role: role.value, }); } return ( <>
{/* - needs dialog to confirm change of ownership */}