This commit is contained in:
Hugo Lextrait 2023-05-10 10:50:53 +02:00
parent b86bdfc34d
commit 6259c983bf
2 changed files with 68 additions and 60 deletions

36
package-lock.json generated
View File

@ -400,9 +400,9 @@
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA=="
},
"node_modules/@mui/base": {
"version": "5.0.0-alpha.128",
"resolved": "https://registry.npmjs.org/@mui/base/-/base-5.0.0-alpha.128.tgz",
"integrity": "sha512-wub3wxNN+hUp8hzilMlXX3sZrPo75vsy1cXEQpqdTfIFlE9HprP1jlulFiPg5tfPst2OKmygXr2hhmgvAKRrzQ==",
"version": "5.0.0-beta.0",
"resolved": "https://registry.npmjs.org/@mui/base/-/base-5.0.0-beta.0.tgz",
"integrity": "sha512-ap+juKvt8R8n3cBqd/pGtZydQ4v2I/hgJKnvJRGjpSh3RvsvnDHO4rXov8MHQlH6VqpOekwgilFLGxMZjNTucA==",
"dependencies": {
"@babel/runtime": "^7.21.0",
"@emotion/is-prop-valid": "^1.2.0",
@ -432,26 +432,26 @@
}
},
"node_modules/@mui/core-downloads-tracker": {
"version": "5.12.3",
"resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-5.12.3.tgz",
"integrity": "sha512-yiJZ+knaknPHuRKhRk4L6XiwppwkAahVal3LuYpvBH7GkA2g+D9WLEXOEnNYtVFUggyKf6fWGLGnx0iqzkU5YA==",
"version": "5.13.0",
"resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-5.13.0.tgz",
"integrity": "sha512-5nXz2k8Rv2ZjtQY6kXirJVyn2+ODaQuAJmXSJtLDUQDKWp3PFUj6j3bILqR0JGOs9R5ejgwz3crLKsl6GwjwkQ==",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mui"
}
},
"node_modules/@mui/material": {
"version": "5.12.3",
"resolved": "https://registry.npmjs.org/@mui/material/-/material-5.12.3.tgz",
"integrity": "sha512-xNmKlrEN4HsTaKFNLZfc7ie7CXx2YqEeO//hsXZx2p3MGtDdeMr2sV3jC4hsFs57RhQlF79weY7uVvC8xSuVbg==",
"version": "5.13.0",
"resolved": "https://registry.npmjs.org/@mui/material/-/material-5.13.0.tgz",
"integrity": "sha512-ckS+9tCpAzpdJdaTF+btF0b6mF9wbXg/EVKtnoAWYi0UKXoXBAVvEUMNpLGA5xdpCdf+A6fPbVUEHs9TsfU+Yw==",
"dependencies": {
"@babel/runtime": "^7.21.0",
"@mui/base": "5.0.0-alpha.128",
"@mui/core-downloads-tracker": "^5.12.3",
"@mui/base": "5.0.0-beta.0",
"@mui/core-downloads-tracker": "^5.13.0",
"@mui/system": "^5.12.3",
"@mui/types": "^7.2.4",
"@mui/utils": "^5.12.3",
"@types/react-transition-group": "^4.4.5",
"@types/react-transition-group": "^4.4.6",
"clsx": "^1.2.1",
"csstype": "^3.1.2",
"prop-types": "^15.8.1",
@ -966,9 +966,9 @@
"integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ=="
},
"node_modules/@types/validator": {
"version": "13.7.16",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.16.tgz",
"integrity": "sha512-VyKmLktUHYLbrSbsRi241MSUlGYomQgK/tfCNpej3Gt5qDOM10AZ3nU2aR2s5JritClXuOBu4K7MkywVW/Y6Ow=="
"version": "13.7.17",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.17.tgz",
"integrity": "sha512-aqayTNmeWrZcvnG2MG9eGYI6b7S5fl+yKgPs6bAjOTwPS316R5SxBGKvtSExfyoJU7pIeHJfsHI0Ji41RVMkvQ=="
},
"node_modules/@typescript-eslint/parser": {
"version": "5.59.5",
@ -1707,9 +1707,9 @@
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg=="
},
"node_modules/enhanced-resolve": {
"version": "5.13.0",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.13.0.tgz",
"integrity": "sha512-eyV8f0y1+bzyfh8xAwW/WTSZpLbjhqc4ne9eGSH4Zo2ejdyiNG9pU6mf9DG8a7+Auk6MFTlNOT4Y2y/9k8GKVg==",
"version": "5.14.0",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.14.0.tgz",
"integrity": "sha512-+DCows0XNwLDcUhbFJPdlQEVnT2zXlCv7hPxemTz86/O+B/hCQ+mb7ydkPKiflpVraqLPCAfu7lDy+hBXueojw==",
"dependencies": {
"graceful-fs": "^4.2.4",
"tapable": "^2.2.0"

View File

@ -70,7 +70,12 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
<div className={classes["form-container"]}>
<div className={classes["checkbox-container"]}>
{this.state.documentTypes.map((documentType) => (
<CheckBox name="document_types" toolTip="Checkbox with tooltip" option={documentType} key={documentType.value as string} />
<CheckBox
name="document_types"
toolTip="Checkbox with tooltip"
option={documentType}
key={documentType.value as string}
/>
))}
</div>
<div className={classes["add-document-container"]}>
@ -125,44 +130,44 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
this.loadData();
}
private async loadData(){
try{
private async loadData() {
try {
const folder = await Folders.getInstance().getByUid(this.props.folderUid, {
q:{
q: {
deed: {
include: {
deed_has_document_types: {
include: {
document_type: true
}
}
}
document_type: true,
},
},
},
},
office: true
}
office: true,
},
});
if(!folder) return;
if (!folder) return;
this.setState({
folder,
documentTypes: await this.getAvailableDocuments(folder),
});
}catch(e){
} catch (e) {
console.error(e);
}
}
private async getAvailableDocuments(folder: OfficeFolder): Promise<IOption[]>{
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
}
}
}
})
deed_has_document_types: {
include: {
document_type: true,
},
},
},
});
if(!documentTypes) return [];
if (!documentTypes) return [];
const documentTypesOptions: IOption[] = documentTypes.deed_has_document_types!.map((documentType) => {
return {
@ -171,8 +176,7 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
};
});
return documentTypesOptions
return documentTypesOptions;
}
private canAddDocument() {
@ -183,24 +187,24 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
}
private async addDocument() {
try{
try {
const documentType = await DocumentTypes.getInstance().post({
name: this.state.documentName,
private_description: this.state.visibleDescription,
office: {
uid: this.state.folder?.office!.uid!
uid: this.state.folder?.office!.uid!,
},
public_description: this.state.visibleDescription
})
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!,{
await Deeds.getInstance().put(this.state.folder?.deed?.uid!, {
deed_has_document_types: [
...oldDocumentsType,
{
document_type: documentType,
}
]
},
],
});
await this.loadData();
@ -209,7 +213,7 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
documentName: "",
visibleDescription: "",
});
}catch(e){
} catch (e) {
console.error(e);
}
}
@ -253,32 +257,36 @@ class AskDocumentsClass extends BasePage<IPropsClass, IState> {
e: React.FormEvent<HTMLFormElement> | null,
values: {
[key: string]: any;
}
},
) {
try{
try {
const documentAsked: [] = values["document_types"] as [];
await documentAsked.forEach(async (document) => {
await Documents.getInstance().post({
folder: {
uid: this.props.folderUid
uid: this.props.folderUid,
},
depositor: {
uid: this.props.customerUid
uid: this.props.customerUid,
},
document_type: {
uid: document
}
uid: document,
},
});
});
this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid));
}catch(e){
this.props.router.push(
Module.getInstance()
.get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid),
);
} catch (e) {
console.error(e);
}
}
}
export default function AskDocuments(props: IProps){
export default function AskDocuments(props: IProps) {
const router = useRouter();
let { folderUid, customerUid } = router.query;
folderUid = folderUid as string;