import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { MdOutlineRemoveCircle } from "react-icons/md"; import Field from "@/lib/components/ui/Field"; import { Select } from "@/lib/components/ui/Select"; import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; import { BrainRoleAssignation, BrainRoleType, } from "./NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types"; import { userRoleToAssignableRoles } from "./ShareBrain/types"; type UserToInviteProps = { onChange: (newRole: BrainRoleAssignation) => void; removeCurrentInvitation?: () => void; roleAssignation: BrainRoleAssignation; }; export const UserToInvite = ({ onChange, removeCurrentInvitation, roleAssignation, }: UserToInviteProps): JSX.Element => { const { t } = useTranslation("translation"); const [selectedRole, setSelectedRole] = useState( roleAssignation.role ); const [email, setEmail] = useState(roleAssignation.email); const { currentBrain } = useBrainContext(); useEffect(() => { onChange({ ...roleAssignation, email, role: selectedRole, }); }, [email, selectedRole]); if (currentBrain === undefined) { return
; } const assignableRoles = userRoleToAssignableRoles[currentBrain.role]; const translatedOptions = assignableRoles.map((role) => ({ value: role.value, // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment label: t(role.value), })); return (
setEmail(e.target.value)} value={email} onBlur={() => email === "" && removeCurrentInvitation?.()} data-testid="role-assignation-email-input" />