✨ Admin office role add/remove
This commit is contained in:
parent
5b2126460f
commit
406ebeb2cc
@ -26,7 +26,7 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
|
||||
const [roleModalOpened, setRoleModalOpened] = useState<boolean>(false);
|
||||
const [adminModalOpened, setAdminModalOpened] = useState<boolean>(false);
|
||||
|
||||
const [adminRoleType, setAdminRoleType] = useState<"add" | "remove">("add");
|
||||
const [selectedOption, setSelectedOption] = useState<IOption | null>(null);
|
||||
|
||||
const handleRoleChange = useCallback((option: IOption) => {
|
||||
@ -56,25 +56,31 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
}, [selectedOption, userSelected]);
|
||||
|
||||
const changeAdmin = useCallback(async () => {
|
||||
const adminRole = await Roles.getInstance().getOne({
|
||||
where: {
|
||||
name: "admin",
|
||||
},
|
||||
});
|
||||
if (adminRoleType === "add") {
|
||||
const adminRole = await Roles.getInstance().getOne({
|
||||
where: {
|
||||
name: "admin",
|
||||
},
|
||||
});
|
||||
|
||||
if (!adminRole) return;
|
||||
await Users.getInstance().put(
|
||||
userSelected?.uid as string,
|
||||
User.hydrate<User>({
|
||||
uid: userSelected?.uid as string,
|
||||
office_role: undefined,
|
||||
role: adminRole,
|
||||
}),
|
||||
);
|
||||
if (!adminRole) return;
|
||||
await Users.getInstance().put(
|
||||
userSelected?.uid as string,
|
||||
User.hydrate<User>({
|
||||
uid: userSelected?.uid as string,
|
||||
office_role: undefined,
|
||||
role: adminRole,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
// retirer rôle admin
|
||||
}
|
||||
setRoleModalOpened(false);
|
||||
}, [userSelected]);
|
||||
}, [adminRoleType, userSelected]);
|
||||
|
||||
const openAdminModal = useCallback(() => {
|
||||
const openAdminModal = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (e.target.checked) setAdminRoleType("add");
|
||||
else setAdminRoleType("remove");
|
||||
setAdminModalOpened(true);
|
||||
}, []);
|
||||
|
||||
@ -189,7 +195,7 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
cancelText={"Annuler"}>
|
||||
<div className={classes["modal-content"]}>
|
||||
<Typography typo={ITypo.P_16} className={classes["text"]}>
|
||||
Attributer le rôle de <span className={classes["role-name"]}>{selectedOption?.label}</span> à{" "}
|
||||
Attribuer le rôle de <span className={classes["role-name"]}>{selectedOption?.label}</span> à{" "}
|
||||
{userSelected?.contact?.first_name} {userSelected?.contact?.last_name} ?
|
||||
</Typography>
|
||||
</div>
|
||||
@ -204,7 +210,8 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
cancelText={"Annuler"}>
|
||||
<div className={classes["modal-content"]}>
|
||||
<Typography typo={ITypo.P_16} className={classes["text"]}>
|
||||
Attributer le rôle d'administrateur à {userSelected?.contact?.first_name} {userSelected?.contact?.last_name} ?
|
||||
{adminRoleType === "add" ? "Attribuer" : "Retirer"} le rôle d'administrateur à{" "}
|
||||
{userSelected?.contact?.first_name} {userSelected?.contact?.last_name} ?
|
||||
</Typography>
|
||||
</div>
|
||||
</Confirm>
|
||||
|
Loading…
x
Reference in New Issue
Block a user