Ask another document that is not existing (#34)
This commit is contained in:
commit
3dc49ec393
3
package-lock.json
generated
3
package-lock.json
generated
@ -19,7 +19,6 @@
|
||||
"dotenv": "^16.0.3",
|
||||
"eslint": "8.36.0",
|
||||
"eslint-config-next": "13.2.4",
|
||||
"form-data": "^4.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.40",
|
||||
"next": "13.2.4",
|
||||
"prettier": "^2.8.7",
|
||||
@ -3204,7 +3203,7 @@
|
||||
}
|
||||
},
|
||||
"node_modules/le-coffre-resources": {
|
||||
"resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#62639b8bfcd0f779357554a04cd40e8a3ba4e62b",
|
||||
"resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#b3d3495c0e65afc0b149d6c07fd5741e144e2aaa",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"class-transformer": "^0.5.1",
|
||||
|
@ -16,6 +16,7 @@ export type IPutDeedsParams = {
|
||||
description?: OfficeFolder["description"];
|
||||
archived_description?: OfficeFolder["archived_description"];
|
||||
status?: OfficeFolder["status"];
|
||||
deed_has_document_types?: Deed["deed_has_document_types"];
|
||||
};
|
||||
|
||||
@Service()
|
||||
|
@ -14,7 +14,14 @@ export interface IGetDocumentTypesparams {
|
||||
export type IPutDocumentTypesParams = {
|
||||
};
|
||||
|
||||
export interface IPostDocumentTypesParams {}
|
||||
export interface IPostDocumentTypesParams {
|
||||
name: string;
|
||||
public_description: string;
|
||||
private_description: string;
|
||||
office: {
|
||||
uid: string;
|
||||
};
|
||||
}
|
||||
|
||||
@Service()
|
||||
export default class DocumentTypes extends BaseSuperAdmin {
|
||||
@ -47,10 +54,10 @@ export default class DocumentTypes extends BaseSuperAdmin {
|
||||
/**
|
||||
* @description : Create a Document
|
||||
*/
|
||||
public async post(body: any): Promise<DocumentType> {
|
||||
public async post(body: IPostDocumentTypesParams): Promise<DocumentType> {
|
||||
const url = new URL(this.baseURl);
|
||||
try {
|
||||
return await this.postRequest<DocumentType>(url, body);
|
||||
return await this.postRequest<DocumentType>(url, body as any);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
|
@ -62,6 +62,7 @@
|
||||
display: inline-grid;
|
||||
justify-items: start;
|
||||
gap: 32px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,11 @@ import React from "react";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import classes from "./classes.module.scss";
|
||||
import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes";
|
||||
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||
import Deeds from "@Front/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds";
|
||||
import DocumentTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes";
|
||||
|
||||
type IProps = {};
|
||||
type IPropsClass = IProps & {
|
||||
@ -31,6 +33,7 @@ type IState = {
|
||||
documentName: string;
|
||||
visibleDescription: string;
|
||||
documentTypes: IOption[];
|
||||
folder: OfficeFolder | null;
|
||||
};
|
||||
|
||||
class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
@ -42,6 +45,7 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
documentName: "",
|
||||
visibleDescription: "",
|
||||
documentTypes: [],
|
||||
folder: null,
|
||||
};
|
||||
|
||||
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||
@ -118,44 +122,59 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
public override async componentDidMount(): Promise<void> {
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
private async loadData(){
|
||||
try{
|
||||
const folder = await Folders.getInstance().getByUid(this.props.folderUid, {
|
||||
q:{
|
||||
deed: {
|
||||
include: {
|
||||
deed_type: true
|
||||
deed_has_document_types: {
|
||||
include: {
|
||||
document_type: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
office: true
|
||||
}
|
||||
});
|
||||
if(!folder) return;
|
||||
|
||||
const documentTypes = await DeedTypes.getInstance().getByUid(folder.deed!.deed_type!.uid!, {
|
||||
q: {
|
||||
deed_type_has_document_types: {
|
||||
include: {
|
||||
document_type: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if(!documentTypes) return;
|
||||
|
||||
const documentTypesOptions: IOption[] = documentTypes.deed_type_has_document_types!.map((documentType) => {
|
||||
return {
|
||||
label: documentType.document_type!.name!,
|
||||
value: documentType.document_type!.uid!,
|
||||
};
|
||||
});
|
||||
|
||||
this.setState({
|
||||
documentTypes: documentTypesOptions,
|
||||
folder,
|
||||
documentTypes: await this.getAvailableDocuments(folder),
|
||||
});
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async getAvailableDocuments(folder: OfficeFolder): Promise<IOption[]>{
|
||||
const documentTypes = await Deeds.getInstance().getByUid(folder.deed!.uid!, {
|
||||
q: {
|
||||
deed_has_document_types: {
|
||||
include: {
|
||||
document_type: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if(!documentTypes) return [];
|
||||
|
||||
const documentTypesOptions: IOption[] = documentTypes.deed_has_document_types!.map((documentType) => {
|
||||
return {
|
||||
label: documentType.document_type!.name!,
|
||||
value: documentType.document_type!.uid!,
|
||||
};
|
||||
});
|
||||
|
||||
return documentTypesOptions
|
||||
|
||||
}
|
||||
|
||||
private canAddDocument() {
|
||||
if (this.state.documentName === "" || this.state.visibleDescription === "") {
|
||||
return false;
|
||||
@ -163,12 +182,37 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
return true;
|
||||
}
|
||||
|
||||
private addDocument() {
|
||||
this.setState({
|
||||
isCreateDocumentModalVisible: false,
|
||||
documentName: "",
|
||||
visibleDescription: "",
|
||||
});
|
||||
private async addDocument() {
|
||||
try{
|
||||
const documentType = await DocumentTypes.getInstance().post({
|
||||
name: this.state.documentName,
|
||||
private_description: this.state.visibleDescription,
|
||||
office: {
|
||||
uid: this.state.folder?.office!.uid!
|
||||
},
|
||||
public_description: this.state.visibleDescription
|
||||
})
|
||||
|
||||
const oldDocumentsType = this.state.folder?.deed?.deed_has_document_types!;
|
||||
const deed = await Deeds.getInstance().put(this.state.folder?.deed?.uid!,{
|
||||
deed_has_document_types: [
|
||||
...oldDocumentsType,
|
||||
{
|
||||
document_type: documentType,
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
console.log("Deed : ", deed);
|
||||
await this.loadData();
|
||||
this.setState({
|
||||
isCreateDocumentModalVisible: false,
|
||||
documentName: "",
|
||||
visibleDescription: "",
|
||||
});
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private onVisibleDescriptionChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user