remove customers calls for customer namespace
This commit is contained in:
parent
7bba9ce8c3
commit
db97b00078
@ -1,67 +0,0 @@
|
|||||||
import Customer, { Contact } from "le-coffre-resources/dist/Customer";
|
|
||||||
|
|
||||||
import BaseCustomer from "../BaseCustomer";
|
|
||||||
import { ECivility } from "le-coffre-resources/dist/Customer/Contact";
|
|
||||||
|
|
||||||
// TODO Type get query params -> Where + inclue + orderby
|
|
||||||
export interface IGetCustomersparams {
|
|
||||||
where?: {};
|
|
||||||
include?: {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Type getbyuid query params
|
|
||||||
|
|
||||||
export type IPutCustomersParams = {
|
|
||||||
uid?: Customer["uid"];
|
|
||||||
contact?: Customer["contact"];
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IPostCustomersParams {
|
|
||||||
first_name: string;
|
|
||||||
last_name: string;
|
|
||||||
email: string;
|
|
||||||
cell_phone_number: string;
|
|
||||||
civility: ECivility;
|
|
||||||
address?: Contact["address"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Customers extends BaseCustomer {
|
|
||||||
private static instance: Customers;
|
|
||||||
private readonly baseURl = this.namespaceUrl.concat("/customers");
|
|
||||||
|
|
||||||
private constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getInstance() {
|
|
||||||
if (!this.instance) {
|
|
||||||
return new this();
|
|
||||||
} else {
|
|
||||||
return this.instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async get(q: IGetCustomersparams): Promise<Customer[]> {
|
|
||||||
const url = new URL(this.baseURl);
|
|
||||||
const query = { q };
|
|
||||||
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
|
||||||
try {
|
|
||||||
return await this.getRequest<Customer[]>(url);
|
|
||||||
} catch (err) {
|
|
||||||
this.onError(err);
|
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getByUid(uid: string, q?: any): Promise<Customer> {
|
|
||||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
|
||||||
const query = { q };
|
|
||||||
if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
|
||||||
try {
|
|
||||||
return await this.getRequest<Customer>(url);
|
|
||||||
} catch (err) {
|
|
||||||
this.onError(err);
|
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
|
||||||
import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents";
|
import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents";
|
||||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
||||||
@ -10,7 +9,7 @@ import React, { useCallback, useEffect, useState } from "react";
|
|||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService";
|
||||||
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
||||||
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
||||||
|
|
||||||
@ -25,15 +24,15 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
|
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
|
||||||
|
|
||||||
const getDocuments = useCallback(async () => {
|
const getDocuments = useCallback(async () => {
|
||||||
let jwt;
|
let jwt: ICustomerJwtPayload | undefined;;
|
||||||
if (typeof document !== "undefined") {
|
if (typeof document !== "undefined") {
|
||||||
jwt = JwtService.getInstance().decodeJwt();
|
jwt = JwtService.getInstance().decodeCustomerJwt();
|
||||||
}
|
}
|
||||||
if (!jwt || !jwt.email) return;
|
|
||||||
const customers = await Customers.getInstance().get({
|
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } });
|
||||||
where: { contact: { email: jwt.email }, office_folders: { some: { uid: folderUid } } },
|
|
||||||
});
|
const actualCustomer = folder?.customers?.find((customer) => customer.uid === jwt?.customerId);
|
||||||
const actualCustomer: Customer = customers[0]!;
|
if(!actualCustomer) throw new Error("Customer not found");
|
||||||
|
|
||||||
const query: IGetDocumentsparams = {
|
const query: IGetDocumentsparams = {
|
||||||
where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string },
|
where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string },
|
||||||
@ -47,7 +46,8 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
|
|
||||||
const documentList = await Documents.getInstance().get(query);
|
const documentList = await Documents.getInstance().get(query);
|
||||||
|
|
||||||
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true } });
|
//const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } });
|
||||||
|
|
||||||
setFolder(folder);
|
setFolder(folder);
|
||||||
setDocuments(documentList);
|
setDocuments(documentList);
|
||||||
setCustomer(actualCustomer);
|
setCustomer(actualCustomer);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
//import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
||||||
import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents";
|
|
||||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
||||||
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
||||||
@ -11,7 +10,6 @@ import Customer, { Document, DocumentType } from "le-coffre-resources/dist/Custo
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
type IState = {
|
type IState = {
|
||||||
@ -109,27 +107,27 @@ export default class ClientDashboard extends Base<IProps, IState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async componentDidMount() {
|
// public override async componentDidMount() {
|
||||||
// TODO Get documents of the current customer according to userStore
|
// // TODO Get documents of the current customer according to userStore
|
||||||
// REMOVE this mock
|
// // REMOVE this mock
|
||||||
|
|
||||||
const jwt = JwtService.getInstance().decodeJwt();
|
// const jwt = JwtService.getInstance().decodeJwt();
|
||||||
const mockedCustomers = await Customers.getInstance().get({
|
// const mockedCustomers = await Customers.getInstance().get({
|
||||||
where: { contact: { email: jwt?.email } },
|
// where: { contact: { email: jwt?.email } },
|
||||||
});
|
// });
|
||||||
const mockedCustomer: Customer = mockedCustomers[0]!;
|
// const mockedCustomer: Customer = mockedCustomers[0]!;
|
||||||
|
|
||||||
const query: IGetDocumentsparams = {
|
// const query: IGetDocumentsparams = {
|
||||||
where: { depositor: { uid: mockedCustomer.uid } },
|
// where: { depositor: { uid: mockedCustomer.uid } },
|
||||||
include: {
|
// include: {
|
||||||
files: true,
|
// files: true,
|
||||||
document_history: true,
|
// document_history: true,
|
||||||
document_type: true,
|
// document_type: true,
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
const documents: Document[] = await Documents.getInstance().get(query);
|
// const documents: Document[] = await Documents.getInstance().get(query);
|
||||||
this.setState({ documents, mockedCustomer });
|
// this.setState({ documents, mockedCustomer });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private onCloseModalAddDocument() {
|
private onCloseModalAddDocument() {
|
||||||
this.setState({ isAddDocumentModalVisible: false });
|
this.setState({ isAddDocumentModalVisible: false });
|
||||||
|
@ -15,7 +15,6 @@ import React from "react";
|
|||||||
|
|
||||||
import BasePage from "../../Base";
|
import BasePage from "../../Base";
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import OcrResult from "./OcrResult";
|
|
||||||
import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
|
import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
|
||||||
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
||||||
|
|
||||||
|
@ -116,10 +116,9 @@ export default class MyAccount extends Base<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async componentDidMount() {
|
public override async componentDidMount() {
|
||||||
const jwtUncoded = JwtService.getInstance().decodeCustomerJwt();
|
const jwtDecoded = JwtService.getInstance().decodeJwt();
|
||||||
console.log(jwtUncoded);
|
if (!jwtDecoded) return;
|
||||||
if (!jwtUncoded) return;
|
const user = await Users.getInstance().getByUid(jwtDecoded.userId, {
|
||||||
const user = await Users.getInstance().getByUid(jwtUncoded.userId, {
|
|
||||||
q: {
|
q: {
|
||||||
office_membership: {
|
office_membership: {
|
||||||
include: {
|
include: {
|
||||||
|
@ -25,7 +25,7 @@ export default function SelectFolder() {
|
|||||||
where: {
|
where: {
|
||||||
customers: {
|
customers: {
|
||||||
some: {
|
some: {
|
||||||
uid: jwt.userId || (jwt as any).customerId,
|
uid: jwt.customerId || (jwt as any).customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ export interface IUserJwtPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ICustomerJwtPayload {
|
export interface ICustomerJwtPayload {
|
||||||
userId: string;
|
customerId: string;
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user