✨ Votes working
This commit is contained in:
parent
1c3460ffeb
commit
98acafb1fd
@ -33,6 +33,37 @@ export default function UserInformations(props: IProps) {
|
|||||||
|
|
||||||
const [currentAppointment, setCurrentAppointment] = useState<Appointment | null>(null);
|
const [currentAppointment, setCurrentAppointment] = useState<Appointment | null>(null);
|
||||||
|
|
||||||
|
/** When page change, get the user of the page */
|
||||||
|
|
||||||
|
const getUser = useCallback(async () => {
|
||||||
|
if (!userUid) return;
|
||||||
|
const user = await Users.getInstance().getByUid(userUid as string, {
|
||||||
|
q: {
|
||||||
|
contact: true,
|
||||||
|
office_role: true,
|
||||||
|
office_membership: true,
|
||||||
|
role: true,
|
||||||
|
appointment: {
|
||||||
|
include: {
|
||||||
|
votes: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
votes: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
console.log(user);
|
||||||
|
const roles = await OfficeRoles.getInstance().get();
|
||||||
|
if (!roles) return;
|
||||||
|
setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name })));
|
||||||
|
setUserSelected(user);
|
||||||
|
}, [userUid]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUser();
|
||||||
|
}, [getUser, userUid]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!userSelected) return;
|
if (!userSelected) return;
|
||||||
setCurrentAppointment(userSelected?.appointment?.find((appointment) => appointment.status === EAppointmentStatus.OPEN) ?? null);
|
setCurrentAppointment(userSelected?.appointment?.find((appointment) => appointment.status === EAppointmentStatus.OPEN) ?? null);
|
||||||
@ -84,9 +115,8 @@ export default function UserInformations(props: IProps) {
|
|||||||
if (!userSelected) return;
|
if (!userSelected) return;
|
||||||
|
|
||||||
let vote = Vote.hydrate<Vote>({
|
let vote = Vote.hydrate<Vote>({
|
||||||
appointment:
|
appointment: Appointment.hydrate<Appointment>({
|
||||||
currentAppointment ??
|
uid: currentAppointment?.uid ?? undefined,
|
||||||
Appointment.hydrate<Appointment>({
|
|
||||||
targeted_user: User.hydrate<User>({
|
targeted_user: User.hydrate<User>({
|
||||||
uid: userSelected.uid,
|
uid: userSelected.uid,
|
||||||
}),
|
}),
|
||||||
@ -94,9 +124,10 @@ export default function UserInformations(props: IProps) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await LiveVotes.getInstance().post(vote);
|
const votes = await LiveVotes.getInstance().post(vote);
|
||||||
|
await getUser();
|
||||||
setIsSuperAdminModalOpened(false);
|
setIsSuperAdminModalOpened(false);
|
||||||
}, [userSelected, currentAppointment, superAdminModalType]);
|
}, [userSelected, currentAppointment, superAdminModalType, getUser]);
|
||||||
|
|
||||||
/** Reset switch state when userSelect change */
|
/** Reset switch state when userSelect change */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -104,33 +135,6 @@ export default function UserInformations(props: IProps) {
|
|||||||
setIsSuperAdminChecked(userSelected.role?.name === "super-admin");
|
setIsSuperAdminChecked(userSelected.role?.name === "super-admin");
|
||||||
setIsAdminChecked(userSelected.role?.name === "admin" && !userSelected.office_role);
|
setIsAdminChecked(userSelected.role?.name === "admin" && !userSelected.office_role);
|
||||||
}, [userSelected]);
|
}, [userSelected]);
|
||||||
|
|
||||||
/** When page change, get the user of the page */
|
|
||||||
useEffect(() => {
|
|
||||||
async function getUser() {
|
|
||||||
if (!userUid) return;
|
|
||||||
const user = await Users.getInstance().getByUid(userUid as string, {
|
|
||||||
q: {
|
|
||||||
contact: true,
|
|
||||||
office_role: true,
|
|
||||||
office_membership: true,
|
|
||||||
role: true,
|
|
||||||
appointment: true,
|
|
||||||
votes: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
console.log(user);
|
|
||||||
const roles = await OfficeRoles.getInstance().get();
|
|
||||||
if (!roles) return;
|
|
||||||
setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name })));
|
|
||||||
setUserSelected(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
getUser();
|
|
||||||
}, [userUid]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultUserDashboard mobileBackText={"Liste des utilisateurs"}>
|
<DefaultUserDashboard mobileBackText={"Liste des utilisateurs"}>
|
||||||
<div className={classes["root"]}>
|
<div className={classes["root"]}>
|
||||||
@ -198,13 +202,17 @@ export default function UserInformations(props: IProps) {
|
|||||||
</div>
|
</div>
|
||||||
<div className={classes["right"]}>
|
<div className={classes["right"]}>
|
||||||
<div>
|
<div>
|
||||||
<Typography typo={ITypo.P_SB_18}>1/3</Typography>
|
<Typography typo={ITypo.P_SB_18}>{currentAppointment.votes?.length}/3</Typography>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Typography typo={ITypo.CAPTION_14}>
|
<Typography typo={ITypo.CAPTION_14}>
|
||||||
{currentAppointment.choice === EVote.NOMINATE
|
{currentAppointment.choice === EVote.NOMINATE
|
||||||
? `Vous avez voté pour attribuer le titre de Super Admin. Il manque 2 votes pour que le collaborateur se voit attribuer le titre.`
|
? `Vous avez voté pour attribuer le titre de Super Admin. Il manque ${
|
||||||
: `Vous avez voté pour retirer le titre de Super Admin. Il manque 2 votes pour que le collaborateur se voit retirer le titre.`}
|
3 - currentAppointment.votes?.length!
|
||||||
|
} vote(s) pour que le collaborateur se voit attribuer le titre.`
|
||||||
|
: `Vous avez voté pour retirer le titre de Super Admin. Il manque ${
|
||||||
|
3 - currentAppointment.votes?.length!
|
||||||
|
} vote(s) pour que le collaborateur se voit retirer le titre.`}
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user