diff --git a/package-lock.json b/package-lock.json index 8193846b..3fbee2e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "dotenv": "^16.0.3", "eslint": "8.36.0", "eslint-config-next": "13.2.4", - "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.27", + "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.35", "next": "13.2.4", "prettier": "^2.8.7", "react": "18.2.0", @@ -3166,7 +3166,7 @@ } }, "node_modules/le-coffre-resources": { - "resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#84a49150d7e6e2856aa7e6f9337d603487b89594", + "resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#5052051e1d3f56b8f895f7132090c77ff7bdd6bc", "license": "MIT", "dependencies": { "class-transformer": "^0.5.1", diff --git a/package.json b/package.json index 644a3d4a..f7c9576f 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dotenv": "^16.0.3", "eslint": "8.36.0", "eslint-config-next": "13.2.4", - "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.27", + "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.35", "next": "13.2.4", "prettier": "^2.8.7", "react": "18.2.0", diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts index 9d89b518..9cd29a39 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts @@ -1,7 +1,8 @@ -import { Customer } from "le-coffre-resources/dist/SuperAdmin"; +import { Contact, Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Service } from "typedi"; import BaseSuperAdmin from "../BaseSuperAdmin"; +import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; // TODO Type get query params -> Where + inclue + orderby export interface IGetCustomersparams { @@ -16,6 +17,15 @@ export type IPutCustomersParams = { contact?: Customer["contact"]; }; +export interface IPostCustomersParams { + first_name: string; + last_name: string; + email: string; + cell_phone_number: string; + civility: ECivility; + address?: Contact["address"]; +} + @Service() export default class Customers extends BaseSuperAdmin { private static instance: Customers; @@ -44,6 +54,20 @@ export default class Customers extends BaseSuperAdmin { } } + /** + * @description : Create a Customer + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + console.log(body); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + public async getByUid(uid: string, q?: any): Promise { const url = new URL(this.baseURl.concat(`/${uid}`)); const query = { q }; diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts index f99993b1..a181ca1d 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts @@ -1,5 +1,5 @@ import { Service } from "typedi"; -import User, { DeedType, Office, OfficeFolder } from "le-coffre-resources/dist/Notary"; +import User, { Customer, DeedType, Office, OfficeFolder } from "le-coffre-resources/dist/Notary"; import BaseSuperAdmin from "../BaseSuperAdmin"; import { EFolderStatus } from "le-coffre-resources/dist/Customer/OfficeFolder"; @@ -39,6 +39,7 @@ export type IPutFoldersParams = { archived_description?: OfficeFolder["archived_description"]; status?: OfficeFolder["status"]; office_folder_has_stakeholder?: OfficeFolder["office_folder_has_stakeholder"]; + OfficeFolderHasCustomer?: { customer: { uid: Customer["uid"] } }[]; }; @Service() diff --git a/src/front/Components/DesignSystem/Document/DocumentNotary/index.tsx b/src/front/Components/DesignSystem/Document/DocumentNotary/index.tsx index 5fd9e61f..928f22b8 100644 --- a/src/front/Components/DesignSystem/Document/DocumentNotary/index.tsx +++ b/src/front/Components/DesignSystem/Document/DocumentNotary/index.tsx @@ -65,7 +65,7 @@ class DocumentNotaryClass extends React.Component { private onClick() { if (this.props.document.document_status !== "VALIDATED" && this.props.document.document_status !== "PENDING") return; - this.props.router.push(`/folders/${this.props.document.folder.uid}/documents/${this.props.document.uid}`); + this.props.router.push(`/folders/${this.props.document.folder?.uid}/documents/${this.props.document.uid}`); } private renderIcon(): JSX.Element { diff --git a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx index 23796d34..27b61983 100644 --- a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx +++ b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx @@ -71,7 +71,7 @@ export default function FolderBoxInformation(props: IProps) {
Type d'acte - {folder.deed.deed_type.name ?? ""} + {folder.deed?.deed_type?.name ?? ""}
Ouverture du dossier diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 9d7d8090..3a680722 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -60,9 +60,11 @@ export default class SearchBar extends React.Component { const value = event.target.value.toLowerCase(); if (folder.office_folder_has_customers) { - const customerNames = folder.office_folder_has_customers.map((customer) => { - return `${customer.customer.contact.first_name.toLowerCase()} ${customer.customer.contact.last_name.toLowerCase()}`; - }).join(", "); + const customerNames = folder.office_folder_has_customers + .map((customer) => { + return `${customer.customer.contact?.first_name.toLowerCase()} ${customer.customer.contact?.last_name.toLowerCase()}`; + }) + .join(", "); return name.includes(value) || number.includes(value) || customerNames.includes(value); } diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/classes.module.scss b/src/front/Components/Layouts/Folder/AddClientToFolder/classes.module.scss index d576f9ab..6114580a 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/classes.module.scss +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/classes.module.scss @@ -11,16 +11,17 @@ margin-bottom: 24px; } + .radiobox-container { + margin: 32px 0; + + > :not(:last-child) { + margin-bottom: 16px; + } + } + .form { width: 100%; - .radiobox-container { - margin: 32px 0; - - > :not(:last-child) { - margin-bottom: 16px; - } - } .button-container { width: 100%; diff --git a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx index 8d3883a5..3cce7e20 100644 --- a/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/AddClientToFolder/index.tsx @@ -7,25 +7,32 @@ import { IOption } from "@Front/Components/DesignSystem/Select"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; -import { useRouter } from "next/router"; +import { NextRouter, useRouter } from "next/router"; import { ActionMeta, MultiValue } from "react-select"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import Link from "next/link"; import Module from "@Front/Config/Module"; +import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; +import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; +import Customers from "@Front/Api/LeCoffreApi/SuperAdmin/Customers/Customers"; +import { Customer } from "le-coffre-resources/dist/Notary"; -type IProps = { - selectedFolderUid: string; -}; +type IProps = {}; type IState = { selectedFolder: IDashBoardFolder | null; isExistingClientSelected: boolean; isNewClientSelected: boolean; hasNewClientSelected: boolean; }; -class AddClientToFolderClass extends BasePage { - constructor(props: IProps) { + +type IPropsClass = IProps & { + selectedFolderUid: string; + router: NextRouter; +}; +class AddClientToFolderClass extends BasePage { + constructor(props: IPropsClass) { super(props); this.state = { selectedFolder: null, @@ -37,6 +44,7 @@ class AddClientToFolderClass extends BasePage { this.onExistingClientSelected = this.onExistingClientSelected.bind(this); this.onNewClientSelected = this.onNewClientSelected.bind(this); this.onMutiSelectChange = this.onMutiSelectChange.bind(this); + this.onFormSubmit = this.onFormSubmit.bind(this); } public override render(): JSX.Element { const selectOptions = [ @@ -54,24 +62,24 @@ class AddClientToFolderClass extends BasePage {
Associer un ou plusieurs client(s) -
-
- - Client existant - - - Nouveau client - -
+
+ + Client existant + + + Nouveau client + +
+ {this.state.isExistingClientSelected && (
@@ -88,10 +96,10 @@ class AddClientToFolderClass extends BasePage { {this.state.isNewClientSelected && (
- - - - + + + +
@@ -125,11 +133,36 @@ class AddClientToFolderClass extends BasePage { private onNewClientSelected(): void { this.setState({ isExistingClientSelected: false, isNewClientSelected: true }); } + + private async onFormSubmit( + e: React.FormEvent | null, + values: { + [key: string]: any; + }, + ) { + values["civility"] = ECivility.MALE; + const customer = { + contact: values, + }; + console.log(customer); + + console.log("SELECTD >>>", this.props.selectedFolderUid); + const newCustomerCreated: Customer = await Customers.getInstance().post(customer); + + if (newCustomerCreated) { + const query = { + OfficeFolderHasCustomer: [{ customer: { uid: newCustomerCreated.uid } }], + }; + + await Folders.getInstance().put(this.props.selectedFolderUid, query); + this.props.router.push(`/folders/${this.props.selectedFolderUid}`); + } + } } -export default function AddClientToFolder() { +export default function AddClientToFolder(props: IProps) { const router = useRouter(); let { folderUid } = router.query; folderUid = folderUid as string; - return ; + return ; } diff --git a/src/front/Config/Module/development.json b/src/front/Config/Module/development.json index 89ae00f9..ed5d3660 100644 --- a/src/front/Config/Module/development.json +++ b/src/front/Config/Module/development.json @@ -48,7 +48,7 @@ "AddClient": { "enabled": true, "props": { - "path": "/folders/add/clients", + "path": "/folders/[folderUid]/add/clients", "labelKey": "add_client_to_folder" } }, diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index 89ae00f9..ed5d3660 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -48,7 +48,7 @@ "AddClient": { "enabled": true, "props": { - "path": "/folders/add/clients", + "path": "/folders/[folderUid]/add/clients", "labelKey": "add_client_to_folder" } }, diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index 89ae00f9..ed5d3660 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -48,7 +48,7 @@ "AddClient": { "enabled": true, "props": { - "path": "/folders/add/clients", + "path": "/folders/[folderUid]/add/clients", "labelKey": "add_client_to_folder" } }, diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index 89ae00f9..ed5d3660 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -48,7 +48,7 @@ "AddClient": { "enabled": true, "props": { - "path": "/folders/add/clients", + "path": "/folders/[folderUid]/add/clients", "labelKey": "add_client_to_folder" } }, diff --git a/src/pages/folders/add/clients.tsx b/src/pages/folders/[folderUid]/add/clients.tsx similarity index 100% rename from src/pages/folders/add/clients.tsx rename to src/pages/folders/[folderUid]/add/clients.tsx