From 38cde6148e19759477f770f98bf5949c8c441618 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Mon, 11 Sep 2023 16:06:07 +0200 Subject: [PATCH] :sparkles: Dynamic my account --- .../Api/LeCoffreApi/Notary/Users/Users.ts | 3 +- .../DeedTypes/DeedTypesInformations/index.tsx | 6 -- .../Components/Layouts/MyAccount/index.tsx | 83 +++++++++++++++++-- src/front/Services/JwtService/JwtService.ts | 2 +- 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Notary/Users/Users.ts b/src/front/Api/LeCoffreApi/Notary/Users/Users.ts index 14f31371..47a368a0 100644 --- a/src/front/Api/LeCoffreApi/Notary/Users/Users.ts +++ b/src/front/Api/LeCoffreApi/Notary/Users/Users.ts @@ -35,8 +35,9 @@ export default class Users extends BaseNotary { } } - public async getByUid(uid: string): Promise { + public async getByUid(uid: string, q?: any): Promise { const url = new URL(this.baseURl.concat("/").concat(uid)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); try { return await this.getRequest(url); } catch (err) { diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index b4a9f32a..631c4585 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -117,12 +117,6 @@ export default function DeedTypesInformations(props: IProps) {
-
- - Nom du type d'acte - - {deedTypeSelected?.name} -
Description diff --git a/src/front/Components/Layouts/MyAccount/index.tsx b/src/front/Components/Layouts/MyAccount/index.tsx index 78c44af4..7b0d4798 100644 --- a/src/front/Components/Layouts/MyAccount/index.tsx +++ b/src/front/Components/Layouts/MyAccount/index.tsx @@ -6,11 +6,23 @@ import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate"; import React from "react"; import classes from "./classes.module.scss"; +import User from "le-coffre-resources/dist/Notary"; +import Users from "@Front/Api/LeCoffreApi/Notary/Users/Users"; +import JwtService from "@Front/Services/JwtService/JwtService"; type IProps = {}; -type IState = {}; +type IState = { + user: User | null; +}; export default class MyAccount extends Base { + constructor(props: IProps) { + super(props); + this.state = { + user: null, + }; + } + public override render(): JSX.Element { return ( @@ -25,19 +37,31 @@ export default class MyAccount extends Base {
- - + + @@ -53,13 +77,35 @@ export default class MyAccount extends Base { + + + - - -
@@ -69,6 +115,25 @@ export default class MyAccount extends Base { ); } + public override async componentDidMount() { + const jwtUncoded = JwtService.getInstance().decodeCustomerJwt(); + console.log(jwtUncoded); + if (!jwtUncoded) return; + const user = await Users.getInstance().getByUid(jwtUncoded.userId, { + q: { + office_membership: { + include: { + address: true, + }, + }, + contact: true, + }, + }); + if (!user) return; + this.setState({ + user, + }); + } private onFormSubmit( e: React.FormEvent | null, values: { diff --git a/src/front/Services/JwtService/JwtService.ts b/src/front/Services/JwtService/JwtService.ts index 37a78e48..3d1d5ac4 100644 --- a/src/front/Services/JwtService/JwtService.ts +++ b/src/front/Services/JwtService/JwtService.ts @@ -20,7 +20,7 @@ export interface IUserJwtPayload { } export interface ICustomerJwtPayload { - customerId: string; + userId: string; email: string; }