quivr/frontend/lib/components/UserToInvite.tsx
Mamadou DICKO a30042f0fc
feat: add new actions modal (#1870)
Issue: https://github.com/StanGirard/quivr/issues/1861
- Update Quivr font
- Add Actions modal
- Update Popover component
- Move Chat config to Actions modal

Demo:


https://github.com/StanGirard/quivr/assets/63923024/df3ac138-6950-46fe-8e40-6276005c7ef1
2023-12-13 08:54:35 +01:00

79 lines
2.3 KiB
TypeScript

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 "./BrainUsers/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<BrainRoleType>(
roleAssignation.role
);
const [email, setEmail] = useState(roleAssignation.email);
const { currentBrain } = useBrainContext();
useEffect(() => {
onChange({
...roleAssignation,
email,
role: selectedRole,
});
}, [email, selectedRole]);
if (currentBrain === undefined) {
return <div />;
}
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 (
<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={t("email")}
onChange={(e) => setEmail(e.target.value)}
value={email}
onBlur={() => email === "" && removeCurrentInvitation?.()}
data-testid="role-assignation-email-input"
/>
</div>
<Select
onChange={setSelectedRole}
value={selectedRole}
options={translatedOptions}
popoverSide="bottom"
popoverClassName="w-36"
/>
</div>
);
};