From ff15c7cf95fadcf33f75d08474ef920097a95981 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 Apr 2024 10:32:25 +0200 Subject: [PATCH 1/5] :sparkles: handle change manage collaborators --- .../SubscriptionManageCollaborators/index.tsx | 151 +++++++++++------- 1 file changed, 90 insertions(+), 61 deletions(-) diff --git a/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx b/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx index ac418a9d..066e33f5 100644 --- a/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx +++ b/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx @@ -5,21 +5,97 @@ import Form from "@Front/Components/DesignSystem/Form"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import { useCallback, useEffect, useState } from "react"; -import { Subscription } from "le-coffre-resources/dist/Admin"; +import User, { Subscription } from "le-coffre-resources/dist/Admin"; import JwtService from "@Front/Services/JwtService/JwtService"; import Subscriptions from "@Front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions"; export default function SubscriptionManageCollaborators() { const [subscription, setSubscription] = useState(null); + const [availableCollaborators, setAvailableCollaborators] = useState([ + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "1", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "2", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "3", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "4", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + ]); + const [selectedCollaborators, setSelectedCollaborators] = useState([]); const loadSubscription = useCallback(async () => { const jwt = JwtService.getInstance().decodeJwt(); const subscription = await Subscriptions.getInstance().get({ where: { office: { uid: jwt?.office_Id } } }); console.log(subscription); if (!subscription[0]) return; + subscription[0].seats?.forEach((seat) => setSelectedCollaborators((prev) => [...prev, seat.user.uid!])); setSubscription(subscription[0]); }, []); + const handleChange = useCallback( + (event: React.ChangeEvent) => { + if (!subscription) return; + const value = event.target.value; + if (selectedCollaborators.includes(value)) { + setSelectedCollaborators((prev) => prev.filter((collaborator) => collaborator !== value)); + } else { + if (selectedCollaborators.length <= subscription.nb_seats!) { + setSelectedCollaborators((prev) => [...prev, value]); + } + } + }, + [selectedCollaborators, subscription], + ); + useEffect(() => { loadSubscription(); }, [loadSubscription]); @@ -36,68 +112,21 @@ export default function SubscriptionManageCollaborators() {
- - - - - - - - + {availableCollaborators.map((collaborator) => ( + + ))}
- 7 collaborateurs sélectionnés + {selectedCollaborators.length} collaborateurs sélectionnés
-
From 82d10c8f9c08dd13deafcee5dfe167c89041c61e Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 Apr 2024 10:53:38 +0200 Subject: [PATCH 4/5] :bug: fixing console log --- src/front/Api/Auth/IdNot/index.ts | 33 ++++++++++--------- .../DesignSystem/DepositDocument/index.tsx | 1 - .../DesignSystem/DepositRib/index.tsx | 2 -- .../DesignSystem/Header/Navigation/index.tsx | 2 +- .../ToastsContainer/ToastElement/index.tsx | 1 - .../DocumentTypeListContainer/index.tsx | 1 - .../DeedTypes/DeedTypesCreate/index.tsx | 4 +-- .../DocumentTypes/DocumentTypesEdit/index.tsx | 3 +- .../Folder/AddClientToFolder/index.tsx | 1 - .../Layouts/Folder/UpdateClient/index.tsx | 1 - .../Layouts/Folder/ViewDocuments/index.tsx | 2 +- .../Layouts/LoginCallback/index.tsx | 1 - .../Layouts/LoginCallbackCustomer/index.tsx | 4 +-- .../Layouts/Roles/RolesCreate/index.tsx | 10 +++--- .../Components/Layouts/SelectFolder/index.tsx | 5 ++- .../SubscriptionManageCollaborators/index.tsx | 1 - .../Subscription/SubscriptionError/index.tsx | 1 - .../SubscriptionFacturation/index.tsx | 1 - .../SubscriptionSuccess/index.tsx | 1 - src/front/Services/JwtService/JwtService.ts | 9 +++-- 20 files changed, 36 insertions(+), 48 deletions(-) diff --git a/src/front/Api/Auth/IdNot/index.ts b/src/front/Api/Auth/IdNot/index.ts index b358b6c8..e073cae8 100644 --- a/src/front/Api/Auth/IdNot/index.ts +++ b/src/front/Api/Auth/IdNot/index.ts @@ -19,7 +19,7 @@ export default class Auth extends BaseApiService { try { return await fetch(url); } catch (err) { - console.log(err); + console.error(err); this.onError(err); return Promise.reject(err); } @@ -27,25 +27,28 @@ export default class Auth extends BaseApiService { public async loginWithIdNot() { const variables = FrontendVariables.getInstance(); - const url = new URL(`${variables.IDNOT_BASE_URL + variables.IDNOT_AUTHORIZE_ENDPOINT}?client_id=${variables.IDNOT_CLIENT_ID}&redirect_uri=${variables.FRONT_APP_HOST}/authorized-client&scope=openid,profile&response_type=code`); + const url = new URL( + `${variables.IDNOT_BASE_URL + variables.IDNOT_AUTHORIZE_ENDPOINT}?client_id=${variables.IDNOT_CLIENT_ID}&redirect_uri=${ + variables.FRONT_APP_HOST + }/authorized-client&scope=openid,profile&response_type=code`, + ); try { return await this.getRequest(url); - } catch (err) { - this.onError(err); - return Promise.reject(err); - } - } - - public async getIdnotJwt(autorizationCode: string | string[]): Promise<{accessToken: string, refreshToken: string}> { - const variables = FrontendVariables.getInstance(); - const baseBackUrl = variables.BACK_API_PROTOCOL + variables.BACK_API_HOST; - const url = new URL(`${baseBackUrl}/api/v1/idnot/user/${autorizationCode}`); - try { - return await this.postRequest<{accessToken: string, refreshToken: string}>(url); } catch (err) { this.onError(err); return Promise.reject(err); } } - + + public async getIdnotJwt(autorizationCode: string | string[]): Promise<{ accessToken: string; refreshToken: string }> { + const variables = FrontendVariables.getInstance(); + const baseBackUrl = variables.BACK_API_PROTOCOL + variables.BACK_API_HOST; + const url = new URL(`${baseBackUrl}/api/v1/idnot/user/${autorizationCode}`); + try { + return await this.postRequest<{ accessToken: string; refreshToken: string }>(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/DesignSystem/DepositDocument/index.tsx b/src/front/Components/DesignSystem/DepositDocument/index.tsx index be8b8184..21d47e1c 100644 --- a/src/front/Components/DesignSystem/DepositDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositDocument/index.tsx @@ -421,7 +421,6 @@ export default class DepositDocument extends React.Component { } } catch (e) { this.setState({ loading: false }); - console.log(e); } } diff --git a/src/front/Components/DesignSystem/DepositRib/index.tsx b/src/front/Components/DesignSystem/DepositRib/index.tsx index 4c27cb15..99e147b9 100644 --- a/src/front/Components/DesignSystem/DepositRib/index.tsx +++ b/src/front/Components/DesignSystem/DepositRib/index.tsx @@ -85,14 +85,12 @@ export default class DepositRib extends React.Component { // formData.append("file", this.state.documents[0]!, this.state.documents[0]!.name); // const sentFile = await Bucket.getInstance().post(formData); - // console.log("Sent file:", sentFile); // // Reset documents state // this.setState({ documents: [] }); // }; // handleCancel = () => { - // console.log("Cancel:", this.state.documents); // // Reset documents state // this.setState({ documents: [] }); // }; diff --git a/src/front/Components/DesignSystem/Header/Navigation/index.tsx b/src/front/Components/DesignSystem/Header/Navigation/index.tsx index e07a45ab..52c49323 100644 --- a/src/front/Components/DesignSystem/Header/Navigation/index.tsx +++ b/src/front/Components/DesignSystem/Header/Navigation/index.tsx @@ -29,7 +29,7 @@ export default function Navigation() { await OfficeFolderAnchors.getInstance().getByUid(anchor.folder?.uid as string); } } catch (e) { - console.log(e); + console.error(e); } }, []); diff --git a/src/front/Components/DesignSystem/Toasts/ToastsContainer/ToastElement/index.tsx b/src/front/Components/DesignSystem/Toasts/ToastsContainer/ToastElement/index.tsx index f0f61287..f13a04a5 100644 --- a/src/front/Components/DesignSystem/Toasts/ToastsContainer/ToastElement/index.tsx +++ b/src/front/Components/DesignSystem/Toasts/ToastsContainer/ToastElement/index.tsx @@ -38,7 +38,6 @@ class ToastElementClass extends React.Component { } public override render(): JSX.Element { - console.log(this.props); const toast = this.props.toast; const style = { "--data-duration": `${toast.time}ms`, diff --git a/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/DocumentTypeListContainer/index.tsx b/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/DocumentTypeListContainer/index.tsx index 85fd9422..ada6b7a7 100644 --- a/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/DocumentTypeListContainer/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/DocumentTypeListContainer/index.tsx @@ -33,7 +33,6 @@ export default function DocumentTypeListContainer(props: IProps) { const onSelectedBlock = useCallback( (block: IBlock) => { props.onCloseLeftSide && props.onCloseLeftSide(); - console.log("Block selected :", block); const redirectPath = Module.getInstance().get().modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path; router.push(redirectPath.replace("[uid]", block.id)); }, diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx index c12e2529..826bdcbc 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx @@ -36,7 +36,6 @@ export default function DeedTypesCreate(props: IProps) { try { await validateOrReject(deedType, { groups: ["createDeedType"], forbidUnknownValues: true }); } catch (validationErrors: Array | any) { - console.log(validationErrors); setValidationError(validationErrors as ValidationError[]); return; } @@ -57,12 +56,11 @@ export default function DeedTypesCreate(props: IProps) { .modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeCreated.uid!), ); } catch (validationErrors: Array | any) { - console.log(validationErrors); setValidationError(validationErrors as ValidationError[]); return; } }, - [router, validationError], + [router], ); const closeConfirmModal = useCallback(() => { diff --git a/src/front/Components/Layouts/DocumentTypes/DocumentTypesEdit/index.tsx b/src/front/Components/Layouts/DocumentTypes/DocumentTypesEdit/index.tsx index 0dfc5f3b..afe43b5a 100644 --- a/src/front/Components/Layouts/DocumentTypes/DocumentTypesEdit/index.tsx +++ b/src/front/Components/Layouts/DocumentTypes/DocumentTypesEdit/index.tsx @@ -42,7 +42,6 @@ export default function DocumentTypesEdit() { try { await validateOrReject(documentToUpdate, { groups: ["updateDocumentType"] }); } catch (validationErrors: Array | any) { - console.log(validationErrors); if (!Array.isArray(validationErrors)) return; setValidationError(validationErrors as ValidationError[]); return; @@ -63,7 +62,7 @@ export default function DocumentTypesEdit() { return; } }, - [documentTypeUid, router, validationError], + [documentTypeUid, router], ); return ( diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx index 5da5c5bc..e40e08a9 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx @@ -242,7 +242,6 @@ class AddClientToFolderClass extends BasePage { const contactToCreate = Contact.hydrate(values); await contactToCreate.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false }); } catch (validationErrors) { - console.log(validationErrors); this.setState({ validationError: validationErrors as ValidationError[], }); diff --git a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx index 7cc6b833..6f7c27d6 100644 --- a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx @@ -200,7 +200,6 @@ class UpdateClientClass extends BasePage { try { await contact.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false }); } catch (validationErrors) { - console.log(validationErrors); this.setState({ validationError: validationErrors as ValidationError[], }); diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index b49f3482..9469d218 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -200,7 +200,7 @@ class ViewDocumentsClass extends BasePage { fileBlob, }); } catch (e) { - console.log(e); + console.error(e); } } diff --git a/src/front/Components/Layouts/LoginCallback/index.tsx b/src/front/Components/Layouts/LoginCallback/index.tsx index 911cf3a6..9198b9e2 100644 --- a/src/front/Components/Layouts/LoginCallback/index.tsx +++ b/src/front/Components/Layouts/LoginCallback/index.tsx @@ -28,7 +28,6 @@ export default function LoginCallBack() { await UserStore.instance.connect(token.accessToken, token.refreshToken); return router.push(Module.getInstance().get().modules.pages.Folder.props.path); } catch (e: any) { - console.log("Log error : ", e); if (e.http_status === 401 && e.message === "Email not found") { return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=3"); } diff --git a/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx b/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx index 1db7b577..be49e601 100644 --- a/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx +++ b/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx @@ -26,7 +26,7 @@ export default function LoginCallBackCustomer() { try { token = await Customers.getInstance().loginCallback(tokenid360); } catch (e) { - console.log(e); + console.error(e); router.push(Module.getInstance().get().modules.pages.CustomersLogin.props.path + "?error=1"); return; } @@ -34,7 +34,7 @@ export default function LoginCallBackCustomer() { router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path); } const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken"); - if(!refreshToken) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); + if (!refreshToken) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); const isTokenRefreshed = await JwtService.getInstance().refreshToken(refreshToken); if (isTokenRefreshed) { return router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path); diff --git a/src/front/Components/Layouts/Roles/RolesCreate/index.tsx b/src/front/Components/Layouts/Roles/RolesCreate/index.tsx index 57ab2b14..450a3caa 100644 --- a/src/front/Components/Layouts/Roles/RolesCreate/index.tsx +++ b/src/front/Components/Layouts/Roles/RolesCreate/index.tsx @@ -35,7 +35,6 @@ export default function RolesCreate(props: IProps) { try { await officeRole.validateOrReject?.({ groups: ["createOfficeRole"], forbidUnknownValues: true }); } catch (validationErrors: Array | any) { - console.log(validationErrors); if (!Array.isArray(validationErrors)) return; setValidationError(validationErrors as ValidationError[]); return; @@ -52,13 +51,12 @@ export default function RolesCreate(props: IProps) { router.push(Module.getInstance().get().modules.pages.Roles.pages.RolesInformations.props.path.replace("[uid]", role.uid!)); } catch (validationErrors: Array | any) { - console.log(validationErrors); if (!Array.isArray(validationErrors)) return; setValidationError(validationErrors as ValidationError[]); return; } }, - [router, validationError], + [router], ); const closeConfirmModal = useCallback(() => { @@ -96,7 +94,11 @@ export default function RolesCreate(props: IProps) { Créer un rôle - error.property === "name")}/> + error.property === "name")} + />