wip post folder
This commit is contained in:
parent
250ad7007c
commit
41514453fa
92
src/front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts
Normal file
92
src/front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts
Normal file
@ -0,0 +1,92 @@
|
||||
import { Service } from "typedi";
|
||||
import { Deed, DeedType } from "le-coffre-resources/dist/Notary";
|
||||
import BaseSuperAdmin from "../BaseSuperAdmin";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetDeedTypesParams {
|
||||
q?: {};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
|
||||
export type IPutDeedTypesParams = {
|
||||
uid?: DeedType["uid"];
|
||||
name?: DeedType["name"];
|
||||
description?: DeedType["description"];
|
||||
deed?: DeedType["deed"];
|
||||
office?: DeedType["office"];
|
||||
archived_at?: DeedType["archived_at"];
|
||||
deed_type_has_document_types?: DeedType["deed_type_has_document_types"];
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class DeedTypes extends BaseSuperAdmin {
|
||||
private static instance: DeedTypes;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/deed-types");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this.instance) {
|
||||
return new this();
|
||||
} else {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all DeedTypes
|
||||
*/
|
||||
public async get(q: IGetDeedTypesParams): Promise<DeedType[]> {
|
||||
const url = new URL(this.baseURl);
|
||||
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<DeedType[]>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
*/
|
||||
public async getByUid(uid: string, q?: any): Promise<DeedType> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<DeedType>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a deed
|
||||
*/
|
||||
// public async post(body: IPostDeedTypesParams): Promise<OfficeFolder> {
|
||||
// const url = new URL(this.baseURl);
|
||||
// try {
|
||||
// return await this.postRequest<OfficeFolder>(url, body);
|
||||
// } catch (err) {
|
||||
// this.onError(err);
|
||||
// return Promise.reject(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @description : Update the folder description
|
||||
*/
|
||||
public async put(uid: string, body: IPutDeedTypesParams): Promise<DeedType> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
try {
|
||||
return await this.putRequest<DeedType>(url, body);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
91
src/front/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts
Normal file
91
src/front/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts
Normal file
@ -0,0 +1,91 @@
|
||||
import { Service } from "typedi";
|
||||
import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import BaseSuperAdmin from "../BaseSuperAdmin";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetDeedsParams {
|
||||
q?: {};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
|
||||
export type IPutDeedsParams = {
|
||||
uid?: OfficeFolder["uid"];
|
||||
folder_number?: OfficeFolder["folder_number"];
|
||||
name?: OfficeFolder["name"];
|
||||
description?: OfficeFolder["description"];
|
||||
archived_description?: OfficeFolder["archived_description"];
|
||||
status?: OfficeFolder["status"];
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class Deeds extends BaseSuperAdmin {
|
||||
private static instance: Deeds;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/deeds");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this.instance) {
|
||||
return new this();
|
||||
} else {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all deeds
|
||||
*/
|
||||
public async get(q: IGetDeedsParams): Promise<Deed[]> {
|
||||
const url = new URL(this.baseURl);
|
||||
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<Deed[]>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
*/
|
||||
public async getByUid(uid: string, q?: any): Promise<Deed> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<Deed>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a deed
|
||||
*/
|
||||
// public async post(body: IPostDeedsParams): Promise<OfficeFolder> {
|
||||
// const url = new URL(this.baseURl);
|
||||
// try {
|
||||
// return await this.postRequest<OfficeFolder>(url, body);
|
||||
// } catch (err) {
|
||||
// this.onError(err);
|
||||
// return Promise.reject(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @description : Update the folder description
|
||||
*/
|
||||
public async put(uid: string, body: IPutDeedsParams): Promise<Deed> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
try {
|
||||
return await this.putRequest<Deed>(url, body);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,10 +5,25 @@ import { EFolderStatus } from "le-coffre-resources/dist/Customer/OfficeFolder";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetFoldersParams {
|
||||
q?: {};
|
||||
q?: {
|
||||
where?: {};
|
||||
include?: {};
|
||||
};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
// TODO Type getbyuid query searchParams
|
||||
export type IPostFoldersParams = {
|
||||
folder_number: OfficeFolder["folder_number"];
|
||||
name: OfficeFolder["name"];
|
||||
description: OfficeFolder["description"];
|
||||
archived_description: OfficeFolder["archived_description"];
|
||||
status: OfficeFolder["status"];
|
||||
deed: OfficeFolder["deed"];
|
||||
office: OfficeFolder["office"];
|
||||
office_folder_has_customers?: OfficeFolder["office_folder_has_customers"];
|
||||
office_folder_has_stakeholder?: OfficeFolder["office_folder_has_stakeholder"];
|
||||
documents?: OfficeFolder["documents"];
|
||||
};
|
||||
|
||||
export type IPutFoldersParams = {
|
||||
uid?: OfficeFolder["uid"];
|
||||
@ -67,15 +82,15 @@ export default class Folders extends BaseSuperAdmin {
|
||||
/**
|
||||
* @description : Create a folder
|
||||
*/
|
||||
// public async post(body: IPostFoldersParams): Promise<OfficeFolder> {
|
||||
// const url = new URL(this.baseURl);
|
||||
// try {
|
||||
// return await this.postRequest<OfficeFolder>(url, body);
|
||||
// } catch (err) {
|
||||
// this.onError(err);
|
||||
// return Promise.reject(err);
|
||||
// }
|
||||
// }
|
||||
public async post(body: IPostFoldersParams): Promise<OfficeFolder> {
|
||||
const url = new URL(this.baseURl);
|
||||
try {
|
||||
return await this.postRequest<OfficeFolder>(url, body);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update the folder description
|
||||
|
@ -1,11 +1,27 @@
|
||||
import { Service } from "typedi";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
import BaseSuperAdmin from "../BaseSuperAdmin";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetUsersparams {
|
||||
q?: {};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
|
||||
export type IPutUsersParams = {
|
||||
uid?: User["uid"];
|
||||
idNot?: User["idNot"];
|
||||
contact?: User["contact"];
|
||||
office_membership?: User["office_membership"];
|
||||
office_folder_has_stakeholders?: User["office_folder_has_stakeholders"];
|
||||
documents?: User["documents"];
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class Users extends BaseSuperAdmin {
|
||||
private static instance: Users;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/Users");
|
||||
private readonly baseURl = this.namespaceUrl.concat("/users");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
@ -19,8 +35,12 @@ export default class Users extends BaseSuperAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
public async get(): Promise<User[]> {
|
||||
/**
|
||||
* @description : Get all Users
|
||||
*/
|
||||
public async get(q: IGetUsersparams): Promise<User[]> {
|
||||
const url = new URL(this.baseURl);
|
||||
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<User[]>(url);
|
||||
} catch (err) {
|
||||
@ -29,8 +49,12 @@ export default class Users extends BaseSuperAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
public async getByUid(uid: string): Promise<User> {
|
||||
const url = new URL(this.baseURl.concat("/").concat(uid));
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
*/
|
||||
public async getByUid(uid: string, q?: any): Promise<User> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<User>(url);
|
||||
} catch (err) {
|
||||
@ -38,4 +62,30 @@ export default class Users extends BaseSuperAdmin {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a User
|
||||
*/
|
||||
// public async post(body: IPostDeedsParams): Promise<OfficeFolder> {
|
||||
// const url = new URL(this.baseURl);
|
||||
// try {
|
||||
// return await this.postRequest<OfficeFolder>(url, body);
|
||||
// } catch (err) {
|
||||
// this.onError(err);
|
||||
// return Promise.reject(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @description : Update the folder description
|
||||
*/
|
||||
public async put(uid: string, body: IPutUsersParams): Promise<User> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
try {
|
||||
return await this.putRequest<User>(url, body);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import Header from "@Front/Components/DesignSystem/Header";
|
||||
import Version from "@Front/Components/DesignSystem/Version";
|
||||
import classNames from "classnames";
|
||||
|
@ -1,6 +1,6 @@
|
||||
import RightImage from "@Front/Assets/images/create-folder/right-image.png";
|
||||
import Button from "@Front/Components/DesignSystem/Button";
|
||||
import Form, { IApiFormErrors } from "@Front/Components/DesignSystem/Form";
|
||||
import Form from "@Front/Components/DesignSystem/Form";
|
||||
import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField";
|
||||
import MultiSelect from "@Front/Components/DesignSystem/MultiSelect";
|
||||
import RadioBox from "@Front/Components/DesignSystem/RadioBox";
|
||||
@ -13,11 +13,17 @@ import { ActionMeta, MultiValue } from "react-select";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import classes from "./classes.module.scss";
|
||||
import { Deed, DeedType, OfficeFolder, OfficeFolderHasStakeholder } from "le-coffre-resources/dist/Notary";
|
||||
import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes";
|
||||
import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders";
|
||||
import { EFolderStatus } from "le-coffre-resources/dist/Customer/OfficeFolder";
|
||||
|
||||
type IFormValues = {
|
||||
folder_number: number;
|
||||
entitled: string;
|
||||
act_type: IOption | null;
|
||||
act_typ: IOption | null;
|
||||
personal_note: string;
|
||||
collaborators: MultiValue<IOption>;
|
||||
};
|
||||
@ -26,23 +32,12 @@ type IProps = {};
|
||||
type IState = {
|
||||
folder_access: string;
|
||||
formValues: IFormValues;
|
||||
deedTypes: DeedType[];
|
||||
deedTypesOptions: IOption[];
|
||||
collaborators: User[];
|
||||
collaboratorsOptions: IOption[];
|
||||
};
|
||||
export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
private collaboratorsOptions: IOption[] = [
|
||||
{ label: "John Doe", value: "john_doe" },
|
||||
{ label: "Éric Dupont", value: "eric_dupont" },
|
||||
{ label: "Julien Doe", value: "julien_doe" },
|
||||
{ label: "Nathalie Costa", value: "nathalie_costa" },
|
||||
{ label: "Max Durant", value: "max_durant" },
|
||||
{ label: "Jane Doe", value: "jane_doe" },
|
||||
];
|
||||
|
||||
private actsOptions: IOption[] = [
|
||||
{ label: "Divorce", value: "divorce" },
|
||||
{ label: "Succession", value: "succession" },
|
||||
{ label: "Vente immobilière", value: "vente_immobiliere" },
|
||||
];
|
||||
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
@ -51,10 +46,14 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
formValues: {
|
||||
folder_number: NaN,
|
||||
entitled: "",
|
||||
act_type: null,
|
||||
act_typ: null,
|
||||
personal_note: "",
|
||||
collaborators: [],
|
||||
},
|
||||
deedTypes: [],
|
||||
deedTypesOptions: [],
|
||||
collaborators: [],
|
||||
collaboratorsOptions: [],
|
||||
};
|
||||
|
||||
this.radioOnChange = this.radioOnChange.bind(this);
|
||||
@ -64,6 +63,7 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
this.onPersonalNoteChange = this.onPersonalNoteChange.bind(this);
|
||||
this.onCollaboratorsChange = this.onCollaboratorsChange.bind(this);
|
||||
this.isFormSubmittable = this.isFormSubmittable.bind(this);
|
||||
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||
}
|
||||
|
||||
public override render(): JSX.Element {
|
||||
@ -85,10 +85,10 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
type="number"
|
||||
onChange={this.onFolderNumberChange}
|
||||
/>
|
||||
<InputField name="entitled" fakeplaceholder="Intitulé" onChange={this.onEntitleChange} />
|
||||
<Select options={this.actsOptions} placeholder={"Type d'acte"} onChange={this.onActTypeChange} />
|
||||
<InputField name="name" fakeplaceholder="Intitulé" onChange={this.onEntitleChange} />
|
||||
<Select options={this.state.deedTypesOptions} placeholder={"Type d’acte"} onChange={this.onActTypeChange} />
|
||||
<InputField
|
||||
name="personal_note"
|
||||
name="description"
|
||||
fakeplaceholder="Note du dossier"
|
||||
textarea
|
||||
onChange={this.onPersonalNoteChange}
|
||||
@ -109,7 +109,7 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
{this.state.folder_access === "select_collaborators" && (
|
||||
<div className={classes["collaborators-container"]}>
|
||||
<MultiSelect
|
||||
options={this.collaboratorsOptions}
|
||||
options={this.state.collaboratorsOptions}
|
||||
placeholder="Sélectionner les collaborateurs"
|
||||
onChange={this.onCollaboratorsChange}
|
||||
defaultValue={this.state.formValues.collaborators ?? []}
|
||||
@ -128,6 +128,36 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
);
|
||||
}
|
||||
|
||||
public override async componentDidMount() {
|
||||
const deedTypes = await DeedTypes.getInstance().get({ q: {} });
|
||||
// TODO SETUP userStore and get the user's office membership -> Replace IwJ70M471c by the user's office membership uid
|
||||
const usersMock = await Users.getInstance().get({ q: { include: { office_membership: true } } });
|
||||
const userMock = usersMock[0];
|
||||
const collaborators = await Users.getInstance().get({
|
||||
q: { where: { office_membership: { uid: userMock?.office_membership.uid } }, include: { contact: true } },
|
||||
});
|
||||
this.setState({
|
||||
deedTypes,
|
||||
deedTypesOptions: this.mapDeedOptions(deedTypes),
|
||||
collaborators,
|
||||
collaboratorsOptions: this.mapUsersOptions(collaborators),
|
||||
});
|
||||
}
|
||||
|
||||
private mapDeedOptions(deedTypes: DeedType[]) {
|
||||
return deedTypes.map((deedType) => ({
|
||||
label: deedType.name,
|
||||
value: deedType.uid,
|
||||
})) as IOption[];
|
||||
}
|
||||
|
||||
private mapUsersOptions(collaborators: User[]) {
|
||||
return collaborators.map((collaborator) => ({
|
||||
label: collaborator.contact.last_name.concat(" ", collaborator.contact.first_name),
|
||||
value: collaborator.uid,
|
||||
})) as IOption[];
|
||||
}
|
||||
|
||||
private onFolderNumberChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
this.setState({
|
||||
formValues: {
|
||||
@ -150,7 +180,7 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
this.setState({
|
||||
formValues: {
|
||||
...this.state.formValues,
|
||||
act_type: selectedOption,
|
||||
act_typ: selectedOption,
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -173,20 +203,58 @@ export default class CreateFolder extends BasePage<IProps, IState> {
|
||||
});
|
||||
}
|
||||
|
||||
private onFormSubmit(
|
||||
private async onFormSubmit(
|
||||
e: React.FormEvent<HTMLFormElement> | null,
|
||||
values: {
|
||||
[key: string]: string;
|
||||
[key: string]: any;
|
||||
},
|
||||
onApiErrors: (apiFormErrors: IApiFormErrors | null) => void,
|
||||
) {}
|
||||
) {
|
||||
const selectedDeedType: DeedType | undefined = this.state.deedTypes.find(
|
||||
(deedType) => deedType.uid === this.state.formValues.act_typ?.value,
|
||||
);
|
||||
|
||||
// const selectedCollaborator: User | undefined = this.state.collaborators?.find(
|
||||
// (deedType) => deedType.uid === this.state.formValues.act_typ?.value,
|
||||
// );
|
||||
|
||||
let collaborators: User[] = this.state.collaborators;
|
||||
|
||||
if (!selectedDeedType) return;
|
||||
const deed = Deed.hydrate<Deed>({
|
||||
deed_type: selectedDeedType,
|
||||
});
|
||||
let office_folder_has_stakeholders = collaborators.map((collaborator) => {
|
||||
return OfficeFolderHasStakeholder.hydrate<OfficeFolderHasStakeholder>({
|
||||
office_folder: new OfficeFolder(),
|
||||
user_stakeholder: collaborator,
|
||||
});
|
||||
});
|
||||
|
||||
if (this.state.folder_access === "select_collaborators") {
|
||||
office_folder_has_stakeholders = office_folder_has_stakeholders.filter((collaborator) => {
|
||||
return this.state.formValues.collaborators?.some((selectedCollaborator) => {
|
||||
return selectedCollaborator.value === collaborator.user_stakeholder.uid;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const usersMock = await Users.getInstance().get({ q: { include: { office_membership: true } } });
|
||||
const userMock = usersMock[0];
|
||||
|
||||
values["deed"] = deed;
|
||||
values["archived_description"] = "";
|
||||
values["status"] = EFolderStatus.LIVE;
|
||||
values["office"] = values["office_folder_has_stakeholders"] = office_folder_has_stakeholders;
|
||||
console.log(values);
|
||||
// Folders.getInstance().post(values);
|
||||
}
|
||||
|
||||
private isFormSubmittable(): boolean {
|
||||
if (
|
||||
this.state.formValues.entitled === "" ||
|
||||
this.state.formValues.personal_note === "" ||
|
||||
Number.isNaN(this.state.formValues.folder_number) ||
|
||||
this.state.formValues.act_type === null
|
||||
this.state.formValues.act_typ === null
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user