✨ Creating document type working
This commit is contained in:
parent
22442234e2
commit
5f134a765a
@ -14,7 +14,14 @@ export interface IGetDocumentTypesparams {
|
|||||||
export type IPutDocumentTypesParams = {
|
export type IPutDocumentTypesParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IPostDocumentTypesParams {}
|
export interface IPostDocumentTypesParams {
|
||||||
|
name: string;
|
||||||
|
public_description: string;
|
||||||
|
private_description: string;
|
||||||
|
office: {
|
||||||
|
uid: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentTypes extends BaseSuperAdmin {
|
export default class DocumentTypes extends BaseSuperAdmin {
|
||||||
@ -47,10 +54,10 @@ export default class DocumentTypes extends BaseSuperAdmin {
|
|||||||
/**
|
/**
|
||||||
* @description : Create a Document
|
* @description : Create a Document
|
||||||
*/
|
*/
|
||||||
public async post(body: any): Promise<DocumentType> {
|
public async post(body: IPostDocumentTypesParams): Promise<DocumentType> {
|
||||||
const url = new URL(this.baseURl);
|
const url = new URL(this.baseURl);
|
||||||
try {
|
try {
|
||||||
return await this.postRequest<DocumentType>(url, body);
|
return await this.postRequest<DocumentType>(url, body as any);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.onError(err);
|
this.onError(err);
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
|
@ -19,6 +19,8 @@ import classes from "./classes.module.scss";
|
|||||||
import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes";
|
import DeedTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes";
|
||||||
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
||||||
import Module from "@Front/Config/Module";
|
import Module from "@Front/Config/Module";
|
||||||
|
import DocumentTypes from "@Front/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes";
|
||||||
|
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
type IPropsClass = IProps & {
|
type IPropsClass = IProps & {
|
||||||
@ -31,6 +33,7 @@ type IState = {
|
|||||||
documentName: string;
|
documentName: string;
|
||||||
visibleDescription: string;
|
visibleDescription: string;
|
||||||
documentTypes: IOption[];
|
documentTypes: IOption[];
|
||||||
|
folder: OfficeFolder | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||||
@ -42,6 +45,7 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
documentName: "",
|
documentName: "",
|
||||||
visibleDescription: "",
|
visibleDescription: "",
|
||||||
documentTypes: [],
|
documentTypes: [],
|
||||||
|
folder: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onFormSubmit = this.onFormSubmit.bind(this);
|
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||||||
@ -118,6 +122,10 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async componentDidMount(): Promise<void> {
|
public override async componentDidMount(): Promise<void> {
|
||||||
|
this.loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadData(){
|
||||||
try{
|
try{
|
||||||
const folder = await Folders.getInstance().getByUid(this.props.folderUid, {
|
const folder = await Folders.getInstance().getByUid(this.props.folderUid, {
|
||||||
q:{
|
q:{
|
||||||
@ -125,11 +133,21 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
include: {
|
include: {
|
||||||
deed_type: true
|
deed_type: true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
office: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!folder) return;
|
if(!folder) return;
|
||||||
|
this.setState({
|
||||||
|
folder,
|
||||||
|
documentTypes: await this.getAvailableDocuments(folder),
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getAvailableDocuments(folder: OfficeFolder): Promise<IOption[]>{
|
||||||
const documentTypes = await DeedTypes.getInstance().getByUid(folder.deed!.deed_type!.uid!, {
|
const documentTypes = await DeedTypes.getInstance().getByUid(folder.deed!.deed_type!.uid!, {
|
||||||
q: {
|
q: {
|
||||||
deed_type_has_document_types: {
|
deed_type_has_document_types: {
|
||||||
@ -140,7 +158,7 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!documentTypes) return;
|
if(!documentTypes) return [];
|
||||||
|
|
||||||
const documentTypesOptions: IOption[] = documentTypes.deed_type_has_document_types!.map((documentType) => {
|
const documentTypesOptions: IOption[] = documentTypes.deed_type_has_document_types!.map((documentType) => {
|
||||||
return {
|
return {
|
||||||
@ -149,13 +167,10 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
return documentTypesOptions
|
||||||
documentTypes: documentTypesOptions,
|
|
||||||
});
|
|
||||||
}catch(e){
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private canAddDocument() {
|
private canAddDocument() {
|
||||||
if (this.state.documentName === "" || this.state.visibleDescription === "") {
|
if (this.state.documentName === "" || this.state.visibleDescription === "") {
|
||||||
return false;
|
return false;
|
||||||
@ -163,12 +178,26 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private addDocument() {
|
private async addDocument() {
|
||||||
|
try{
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
await this.loadData();
|
||||||
this.setState({
|
this.setState({
|
||||||
isCreateDocumentModalVisible: false,
|
isCreateDocumentModalVisible: false,
|
||||||
documentName: "",
|
documentName: "",
|
||||||
visibleDescription: "",
|
visibleDescription: "",
|
||||||
});
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onVisibleDescriptionChange(e: React.ChangeEvent<HTMLInputElement>) {
|
private onVisibleDescriptionChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user