Sending votes working

This commit is contained in:
Maxime Lalo 2023-07-27 11:53:04 +02:00
parent 49c6119722
commit 1c3460ffeb
5 changed files with 110 additions and 52 deletions

42
package-lock.json generated
View File

@ -22,7 +22,7 @@
"eslint-config-next": "13.2.4", "eslint-config-next": "13.2.4",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.58", "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.66",
"next": "13.2.4", "next": "13.2.4",
"prettier": "^2.8.7", "prettier": "^2.8.7",
"react": "18.2.0", "react": "18.2.0",
@ -328,9 +328,9 @@
} }
}, },
"node_modules/@eslint-community/regexpp": { "node_modules/@eslint-community/regexpp": {
"version": "4.6.1", "version": "4.6.2",
"resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.1.tgz", "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.2.tgz",
"integrity": "sha512-O7x6dMstWLn2ktjcoiNLDkAGG2EjveHL+Vvc+n0fXumkJYAcSqcVYKtwDU+hDZ0uDUsnUagSYaZrOLAYE8un1A==", "integrity": "sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==",
"engines": { "engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0" "node": "^12.0.0 || ^14.0.0 || >=16.0.0"
} }
@ -441,22 +441,22 @@
} }
}, },
"node_modules/@mui/core-downloads-tracker": { "node_modules/@mui/core-downloads-tracker": {
"version": "5.14.1", "version": "5.14.2",
"resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-5.14.1.tgz", "resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-5.14.2.tgz",
"integrity": "sha512-mIa1WmDmNr1LoupV1Rbxt9bTFKMbIn10RHG1bnZ/FJCkAYpuU/D4n+R+ttiycgcZNngU++zyh/OQeJblzbQPzg==", "integrity": "sha512-x+c/MgDL1t/IIy5lDbMlrDouFG5DYZbl3DP4dbbuhlpPFBnE9glYwmJEee/orVHQpOPwLxCAIWQs+2DKSaBVWQ==",
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",
"url": "https://opencollective.com/mui" "url": "https://opencollective.com/mui"
} }
}, },
"node_modules/@mui/material": { "node_modules/@mui/material": {
"version": "5.14.1", "version": "5.14.2",
"resolved": "https://registry.npmjs.org/@mui/material/-/material-5.14.1.tgz", "resolved": "https://registry.npmjs.org/@mui/material/-/material-5.14.2.tgz",
"integrity": "sha512-WtsgYuageTunLfxH3Ri+o1RuQTFImtRHxMcVNyD0Hhd2/znjW6KODNz0XfjvLRnNCAynBxZNiflcoIBW40h9PQ==", "integrity": "sha512-TgNR4/YRL11RifsnMWNhITNCkGJYVz20SCvVJBBoU5Y/KhUNSSJxjDpEB8VrnY+sUsV0NigLCkHZJglfsiS3Pw==",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.22.6", "@babel/runtime": "^7.22.6",
"@mui/base": "5.0.0-beta.8", "@mui/base": "5.0.0-beta.8",
"@mui/core-downloads-tracker": "^5.14.1", "@mui/core-downloads-tracker": "^5.14.2",
"@mui/system": "^5.14.1", "@mui/system": "^5.14.1",
"@mui/types": "^7.2.4", "@mui/types": "^7.2.4",
"@mui/utils": "^5.14.1", "@mui/utils": "^5.14.1",
@ -2386,9 +2386,9 @@
} }
}, },
"node_modules/execa": { "node_modules/execa": {
"version": "7.1.1", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-7.1.1.tgz", "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz",
"integrity": "sha512-wH0eMf/UXckdUYnO21+HDztteVv05rq2GXksxT4fCGeHkBhw1DROXh40wcjMcRqDOWE7iPJ4n3M7e2+YFP+76Q==", "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==",
"dependencies": { "dependencies": {
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"get-stream": "^6.0.1", "get-stream": "^6.0.1",
@ -3340,7 +3340,7 @@
} }
}, },
"node_modules/le-coffre-resources": { "node_modules/le-coffre-resources": {
"resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#5c506e8b49401240b8decee77f9b7e34694f490a", "resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#e7916d516fe434c93ef13e765d8d63a7ce3c56b2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
@ -3361,9 +3361,9 @@
} }
}, },
"node_modules/libphonenumber-js": { "node_modules/libphonenumber-js": {
"version": "1.10.37", "version": "1.10.38",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.37.tgz", "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.38.tgz",
"integrity": "sha512-Z10PCaOCiAxbUxLyR31DNeeNugSVP6iv/m7UrSKS5JHziEMApJtgku4e9Q69pzzSC9LnQiM09sqsGf2ticZnMw==" "integrity": "sha512-4NjVXVUmpZ9Zsqq6FXa2+MKI+KAI3tOqA0pxXgXGluhpj4ge5didmbWJpMBqGB3AVGv1SnEtKdGTbxjSEG1kCQ=="
}, },
"node_modules/lines-and-columns": { "node_modules/lines-and-columns": {
"version": "1.2.4", "version": "1.2.4",
@ -4847,9 +4847,9 @@
} }
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.6.0", "version": "2.6.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz",
"integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig=="
}, },
"node_modules/tsutils": { "node_modules/tsutils": {
"version": "3.21.0", "version": "3.21.0",

View File

@ -24,7 +24,7 @@
"eslint-config-next": "13.2.4", "eslint-config-next": "13.2.4",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.58", "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.66",
"next": "13.2.4", "next": "13.2.4",
"prettier": "^2.8.7", "prettier": "^2.8.7",
"react": "18.2.0", "react": "18.2.0",

View File

@ -0,0 +1,44 @@
import { Appointment, Vote } from "le-coffre-resources/dist/SuperAdmin";
import BaseSuperAdmin from "../BaseSuperAdmin";
// TODO Type get query params -> Where + inclue + orderby
export interface IGetLiveVotessparams {
where?: {};
include?: {};
select?: {};
}
export type IPostLiveVotesParams = {
appointment: Appointment;
};
export default class LiveVotes extends BaseSuperAdmin {
private static instance: LiveVotes;
private readonly baseURl = this.namespaceUrl.concat("/live-votes");
private constructor() {
super();
}
public static getInstance() {
if (!this.instance) {
return new this();
} else {
return this.instance;
}
}
/**
* @description : Create a LiveVotes
*/
public async post(body: IPostLiveVotesParams): Promise<Vote> {
const url = new URL(this.baseURl);
try {
return await this.postRequest<Vote>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
}

View File

@ -18,7 +18,7 @@ export default function Login() {
const redirectUserOnConnection = useCallback(() => { const redirectUserOnConnection = useCallback(() => {
async function getUser() { async function getUser() {
try { try {
await UserStore.instance.connect(process.env["NEXT_PUBLIC_ADMIN_ID"] as string); await UserStore.instance.connect("jelkvelknvlkn");
await JwtService.getInstance().checkJwt(); await JwtService.getInstance().checkJwt();
router.push(Module.getInstance().get().modules.pages.Folder.props.path); router.push(Module.getInstance().get().modules.pages.Folder.props.path);
} catch (e) { } catch (e) {

View File

@ -1,13 +1,14 @@
import WarningIcon from "@Assets/images/warning.png"; import WarningIcon from "@Assets/images/warning.png";
import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles";
import LiveVotes from "@Front/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes";
import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users";
import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField";
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
import Switch from "@Front/Components/DesignSystem/Switch"; import Switch from "@Front/Components/DesignSystem/Switch";
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
import DefaultUserDashboard from "@Front/Components/LayoutTemplates/DefaultUserDashboard"; import DefaultUserDashboard from "@Front/Components/LayoutTemplates/DefaultUserDashboard";
import Toasts from "@Front/Stores/Toasts"; import User, { Appointment, Vote } from "le-coffre-resources/dist/SuperAdmin";
import User from "le-coffre-resources/dist/Notary"; import { EAppointmentStatus, EVote } from "le-coffre-resources/dist/SuperAdmin/Appointment";
import Image from "next/image"; import Image from "next/image";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
@ -30,6 +31,13 @@ export default function UserInformations(props: IProps) {
const [isAdminChecked, setIsAdminChecked] = useState<boolean>(false); const [isAdminChecked, setIsAdminChecked] = useState<boolean>(false);
const [isAdminModalOpened, setIsAdminModalOpened] = useState<boolean>(false); const [isAdminModalOpened, setIsAdminModalOpened] = useState<boolean>(false);
const [currentAppointment, setCurrentAppointment] = useState<Appointment | null>(null);
useEffect(() => {
if (!userSelected) return;
setCurrentAppointment(userSelected?.appointment?.find((appointment) => appointment.status === EAppointmentStatus.OPEN) ?? null);
}, [userSelected]);
/** Functions for the admin modal */ /** Functions for the admin modal */
const openAdminModal = () => { const openAdminModal = () => {
setIsAdminModalOpened(true); setIsAdminModalOpened(true);
@ -74,21 +82,21 @@ export default function UserInformations(props: IProps) {
const handleSuperAdminModalAccepted = useCallback(async () => { const handleSuperAdminModalAccepted = useCallback(async () => {
if (!userSelected) return; if (!userSelected) return;
if (superAdminModalType === "add") {
Toasts.getInstance().open({ let vote = Vote.hydrate<Vote>({
title: "Vote attribué", appointment:
text: "Vous avez voté pour attribuer le titre de Super Admin à " + userSelected.contact?.first_name, currentAppointment ??
Appointment.hydrate<Appointment>({
targeted_user: User.hydrate<User>({
uid: userSelected.uid,
}),
choice: superAdminModalType === "add" ? EVote.NOMINATE : EVote.DISMISS,
}),
}); });
// add super admin
} else { await LiveVotes.getInstance().post(vote);
Toasts.getInstance().open({
title: "Vote attribué",
text: "Vous avez voté pour supprimer le titre de Super Admin à " + userSelected.contact?.first_name,
});
// remove super admin
}
setIsSuperAdminModalOpened(false); setIsSuperAdminModalOpened(false);
}, [userSelected, superAdminModalType]); }, [userSelected, currentAppointment, superAdminModalType]);
/** Reset switch state when userSelect change */ /** Reset switch state when userSelect change */
useEffect(() => { useEffect(() => {
@ -107,10 +115,13 @@ export default function UserInformations(props: IProps) {
office_role: true, office_role: true,
office_membership: true, office_membership: true,
role: true, role: true,
appointment: true,
votes: true,
}, },
}); });
if (!user) return; if (!user) return;
console.log(user);
const roles = await OfficeRoles.getInstance().get(); const roles = await OfficeRoles.getInstance().get();
if (!roles) return; if (!roles) return;
setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name }))); setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name })));
@ -180,6 +191,7 @@ export default function UserInformations(props: IProps) {
<div className={classes["second-line"]}> <div className={classes["second-line"]}>
<Switch label="Admin de son office" checked={isAdminChecked} onChange={handleAdminChanged} /> <Switch label="Admin de son office" checked={isAdminChecked} onChange={handleAdminChanged} />
<Switch label="Super-admin LeCoffre.io" checked={isSuperAdminChecked} onChange={handleSuperAdminChanged} /> <Switch label="Super-admin LeCoffre.io" checked={isSuperAdminChecked} onChange={handleSuperAdminChanged} />
{currentAppointment && (
<div className={classes["votes-block"]}> <div className={classes["votes-block"]}>
<div className={classes["left"]}> <div className={classes["left"]}>
<Image src={WarningIcon} alt="warning" width={28} height={28} /> <Image src={WarningIcon} alt="warning" width={28} height={28} />
@ -190,12 +202,14 @@ export default function UserInformations(props: IProps) {
</div> </div>
<div> <div>
<Typography typo={ITypo.CAPTION_14}> <Typography typo={ITypo.CAPTION_14}>
Vous avez voté pour attribuer le titre de Super Admin. Il manque 2 votes pour que le {currentAppointment.choice === EVote.NOMINATE
collaborateur se voit attribuer le titre. ? `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 retirer le titre de Super Admin. Il manque 2 votes pour que le collaborateur se voit retirer le titre.`}
</Typography> </Typography>
</div> </div>
</div> </div>
</div> </div>
)}
</div> </div>
</div> </div>
</div> </div>