✨ Delete asked document working
This commit is contained in:
parent
ad874c6c93
commit
117636eb4f
@ -80,4 +80,14 @@ export default class Documents extends BaseSuperAdmin {
|
||||
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() {
|
||||
console.log(this.props.folder.documents);
|
||||
const documents =
|
||||
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) ?? [];
|
||||
|
@ -15,6 +15,7 @@ import classes from "./classes.module.scss";
|
||||
import DocumentList from "./DocumentList";
|
||||
import UserFolderHeader from "./UserFolderHeader";
|
||||
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
||||
import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents";
|
||||
|
||||
type IProps = {
|
||||
customer: Customer;
|
||||
@ -26,6 +27,7 @@ type IProps = {
|
||||
};
|
||||
type IState = {
|
||||
isOpenDeletionModal: boolean;
|
||||
selectedDocumentToDelete: string;
|
||||
};
|
||||
|
||||
export default class UserFolder extends React.Component<IProps, IState> {
|
||||
@ -39,10 +41,12 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
||||
super(props);
|
||||
this.state = {
|
||||
isOpenDeletionModal: false,
|
||||
selectedDocumentToDelete: "",
|
||||
};
|
||||
this.closeDeletionModal = this.closeDeletionModal.bind(this);
|
||||
this.openDeletionModal = this.openDeletionModal.bind(this);
|
||||
this.changeUserFolder = this.changeUserFolder.bind(this);
|
||||
this.deleteAskedDocument = this.deleteAskedDocument.bind(this);
|
||||
}
|
||||
public override render(): JSX.Element {
|
||||
const documentsAsked: Document[] | null = this.getDocumentsByStatus("ASKED");
|
||||
@ -55,6 +59,7 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
||||
<Confirm
|
||||
isOpen={this.state.isOpenDeletionModal}
|
||||
onClose={this.closeDeletionModal}
|
||||
onAccept={this.deleteAskedDocument}
|
||||
closeBtn
|
||||
header={"Supprimer la demande de document ?"}
|
||||
cancelText={"Cancel"}
|
||||
@ -122,6 +127,15 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
||||
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 {
|
||||
if (!this.props.customer.documents) return 0;
|
||||
const totalDocuments: number = this.props.customer.documents.length;
|
||||
@ -159,9 +173,11 @@ export default class UserFolder extends React.Component<IProps, IState> {
|
||||
}
|
||||
|
||||
private openDeletionModal(uid?: string): void {
|
||||
// TODO: call API to delete document
|
||||
if(!uid) return;
|
||||
|
||||
this.setState({
|
||||
isOpenDeletionModal: true,
|
||||
selectedDocumentToDelete: uid,
|
||||
});
|
||||
}
|
||||
private closeDeletionModal(): void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user