Delete asked document (#31)
This commit is contained in:
commit
b707e8d2d5
@ -82,4 +82,14 @@ export default class Documents extends BaseSuperAdmin {
|
|||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async delete(uid: string): Promise<Document> {
|
||||||
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||||
|
try {
|
||||||
|
return await this.deleteRequest<Document>(url);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,6 @@ export default class UserFolderHeader extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private hasPendingFiles() {
|
private hasPendingFiles() {
|
||||||
console.log(this.props.folder.documents);
|
|
||||||
const documents =
|
const documents =
|
||||||
this.props.folder.documents?.filter((document) => document.depositor?.contact?.uid === this.props.customer.contact?.uid) ?? [];
|
this.props.folder.documents?.filter((document) => document.depositor?.contact?.uid === this.props.customer.contact?.uid) ?? [];
|
||||||
const notAskedDocuments = documents.filter((document) => document.document_status === EDocumentStatus.DEPOSITED) ?? [];
|
const notAskedDocuments = documents.filter((document) => document.document_status === EDocumentStatus.DEPOSITED) ?? [];
|
||||||
|
@ -15,6 +15,7 @@ import classes from "./classes.module.scss";
|
|||||||
import DocumentList from "./DocumentList";
|
import DocumentList from "./DocumentList";
|
||||||
import UserFolderHeader from "./UserFolderHeader";
|
import UserFolderHeader from "./UserFolderHeader";
|
||||||
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
||||||
|
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
customer: Customer;
|
customer: Customer;
|
||||||
@ -26,6 +27,7 @@ type IProps = {
|
|||||||
};
|
};
|
||||||
type IState = {
|
type IState = {
|
||||||
isOpenDeletionModal: boolean;
|
isOpenDeletionModal: boolean;
|
||||||
|
selectedDocumentToDelete: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class UserFolder extends React.Component<IProps, IState> {
|
export default class UserFolder extends React.Component<IProps, IState> {
|
||||||
@ -39,10 +41,12 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
isOpenDeletionModal: false,
|
isOpenDeletionModal: false,
|
||||||
|
selectedDocumentToDelete: "",
|
||||||
};
|
};
|
||||||
this.closeDeletionModal = this.closeDeletionModal.bind(this);
|
this.closeDeletionModal = this.closeDeletionModal.bind(this);
|
||||||
this.openDeletionModal = this.openDeletionModal.bind(this);
|
this.openDeletionModal = this.openDeletionModal.bind(this);
|
||||||
this.changeUserFolder = this.changeUserFolder.bind(this);
|
this.changeUserFolder = this.changeUserFolder.bind(this);
|
||||||
|
this.deleteAskedDocument = this.deleteAskedDocument.bind(this);
|
||||||
}
|
}
|
||||||
public override render(): JSX.Element {
|
public override render(): JSX.Element {
|
||||||
const documentsAsked: Document[] | null = this.getDocumentsByStatus("ASKED");
|
const documentsAsked: Document[] | null = this.getDocumentsByStatus("ASKED");
|
||||||
@ -55,6 +59,7 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
<Confirm
|
<Confirm
|
||||||
isOpen={this.state.isOpenDeletionModal}
|
isOpen={this.state.isOpenDeletionModal}
|
||||||
onClose={this.closeDeletionModal}
|
onClose={this.closeDeletionModal}
|
||||||
|
onAccept={this.deleteAskedDocument}
|
||||||
closeBtn
|
closeBtn
|
||||||
header={"Supprimer la demande de document ?"}
|
header={"Supprimer la demande de document ?"}
|
||||||
cancelText={"Cancel"}
|
cancelText={"Cancel"}
|
||||||
@ -122,11 +127,23 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
this.rootRefElement.current?.style.setProperty("--animation-delay", this.props.animationDelay!.toString().concat("ms"));
|
this.rootRefElement.current?.style.setProperty("--animation-delay", this.props.animationDelay!.toString().concat("ms"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async deleteAskedDocument(){
|
||||||
|
try{
|
||||||
|
await Documents.getInstance().delete(this.state.selectedDocumentToDelete);
|
||||||
|
window.location.reload();
|
||||||
|
}catch(e){
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private calculateDocumentsPercentageProgress(): number {
|
private calculateDocumentsPercentageProgress(): number {
|
||||||
if (!this.props.customer.documents) return 0;
|
if (!this.props.customer.documents) return 0;
|
||||||
const totalDocuments: number = this.props.customer.documents.length;
|
const totalDocuments: number = this.props.customer.documents.length;
|
||||||
const numberDocumentsAsked: number = this.getDocumentsByStatus(EDocumentStatus.ASKED)?.length || 0;
|
const numberDocumentsAsked: number = this.getDocumentsByStatus(EDocumentStatus.ASKED)?.length || 0;
|
||||||
return Math.round(((totalDocuments - numberDocumentsAsked) / totalDocuments) * 100);
|
|
||||||
|
const percentage = Math.round(((totalDocuments - numberDocumentsAsked) / totalDocuments) * 100);
|
||||||
|
if(!percentage) return 0;
|
||||||
|
return percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDocumentsByStatus(status: string): Document[] | null {
|
private getDocumentsByStatus(status: string): Document[] | null {
|
||||||
@ -159,9 +176,11 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private openDeletionModal(uid?: string): void {
|
private openDeletionModal(uid?: string): void {
|
||||||
// TODO: call API to delete document
|
if(!uid) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isOpenDeletionModal: true,
|
isOpenDeletionModal: true,
|
||||||
|
selectedDocumentToDelete: uid,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private closeDeletionModal(): void {
|
private closeDeletionModal(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user