2023-07-12 15:56:25 +03:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { MdOutlineRemoveCircle } from "react-icons/md";
|
|
|
|
|
|
|
|
import Field from "@/lib/components/ui/Field";
|
|
|
|
import { Select } from "@/lib/components/ui/Select";
|
2023-07-20 16:15:32 +03:00
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
2023-07-12 15:56:25 +03:00
|
|
|
|
2023-07-25 11:13:00 +03:00
|
|
|
import { userRoleToAssignableRoles } from "./NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/types";
|
|
|
|
import {
|
|
|
|
BrainRoleAssignation,
|
|
|
|
BrainRoleType,
|
|
|
|
} from "./NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types";
|
2023-07-12 15:56:25 +03:00
|
|
|
|
2023-07-17 16:45:18 +03:00
|
|
|
type UserToInviteProps = {
|
2023-07-12 15:56:25 +03:00
|
|
|
onChange: (newRole: BrainRoleAssignation) => void;
|
|
|
|
removeCurrentInvitation?: () => void;
|
|
|
|
roleAssignation: BrainRoleAssignation;
|
|
|
|
};
|
|
|
|
|
2023-07-17 16:45:18 +03:00
|
|
|
export const UserToInvite = ({
|
2023-07-12 15:56:25 +03:00
|
|
|
onChange,
|
|
|
|
removeCurrentInvitation,
|
|
|
|
roleAssignation,
|
2023-07-17 16:45:18 +03:00
|
|
|
}: UserToInviteProps): JSX.Element => {
|
2023-07-12 15:56:25 +03:00
|
|
|
const [selectedRole, setSelectedRole] = useState<BrainRoleType>(
|
2023-07-20 19:17:55 +03:00
|
|
|
roleAssignation.role
|
2023-07-12 15:56:25 +03:00
|
|
|
);
|
|
|
|
const [email, setEmail] = useState(roleAssignation.email);
|
2023-07-20 16:15:32 +03:00
|
|
|
const { currentBrain } = useBrainContext();
|
|
|
|
|
2023-07-12 15:56:25 +03:00
|
|
|
useEffect(() => {
|
|
|
|
onChange({
|
|
|
|
...roleAssignation,
|
|
|
|
email,
|
2023-07-20 19:17:55 +03:00
|
|
|
role: selectedRole,
|
2023-07-12 15:56:25 +03:00
|
|
|
});
|
|
|
|
}, [email, selectedRole]);
|
|
|
|
|
2023-07-25 11:13:00 +03:00
|
|
|
if (currentBrain === undefined) {
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2023-07-12 15:56:25 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
data-testid="assignation-row"
|
|
|
|
className="flex flex-row align-center my-2 gap-3 items-center"
|
|
|
|
>
|
|
|
|
<div className="cursor-pointer" onClick={removeCurrentInvitation}>
|
|
|
|
<MdOutlineRemoveCircle />
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-1">
|
|
|
|
<Field
|
|
|
|
name="email"
|
|
|
|
required
|
|
|
|
type="email"
|
|
|
|
placeholder="Email"
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
value={email}
|
|
|
|
onBlur={() => email === "" && removeCurrentInvitation?.()}
|
|
|
|
data-testid="role-assignation-email-input"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Select
|
|
|
|
onChange={setSelectedRole}
|
|
|
|
value={selectedRole}
|
2023-07-20 19:17:55 +03:00
|
|
|
options={userRoleToAssignableRoles[currentBrain.role]}
|
2023-07-12 15:56:25 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|