From be5008e0d6c00aa94ff09886cba2345b31e234f0 Mon Sep 17 00:00:00 2001
From: devendra <devendra@devendras-MacBook-Pro.local>
Date: Wed, 4 Jan 2023 17:43:38 +0530
Subject: [PATCH] Feat: Delete Form feature

---
 src/components/form/ListForms.js | 67 ++++++++++++++------------------
 src/constants/LangConstants.ts   |  3 +-
 2 files changed, 32 insertions(+), 38 deletions(-)

diff --git a/src/components/form/ListForms.js b/src/components/form/ListForms.js
index 3290b92..0b9a16b 100644
--- a/src/components/form/ListForms.js
+++ b/src/components/form/ListForms.js
@@ -67,24 +67,7 @@ class ListForms extends Component {
     } else {
       formData.status = LANG.FORM_STATUS.UNPUBLISH;
     }
-    FormService.add(formData).then(
-      (response) => {
-        if (response.statusInfo.statusCode === APP.CODE.SUCCESS) {
-          Notify.success(response.statusInfo.statusMessage);
-          //   this.props.updateParent(response.responseData.id);
-          setTimeout(() => {
-            this.getAllForms();
-          }, 500);
-        } else {
-          Notify.error(response.statusInfo.errorMessage);
-        }
-      },
-      (error) => {
-        error.statusInfo
-          ? Notify.error(error.statusInfo.errorMessage)
-          : Notify.error(error.message);
-      }
-    );
+    this.saveFormDetails(formData, false);
   };
 
   searchForms = (event) => {
@@ -111,25 +94,35 @@ class ListForms extends Component {
   // };
 
   deleteForm = () => {
-    this.setState({showConfirmModal:  false});
-    // FormService.deleteForm(formToDelete?.id).then(
-    //   (response) => {
-    //       if (response.statusInfo && response.statusInfo.statusCode === APP.CODE.SUCCESS) {
-    //           console.log(response.responseData);
-    //           Notify.success('Form deleted successfully!');
-    //           getAllForms();
-    //       } else {
-    //           Notify.error(response.statusInfo.errorMessage);
-    //       }
-    //       this.setState({showConfirmModal:  false});
-    //   },
-    //   (error) => {
-    //       error.statusInfo
-    //           ? Notify.error(error.statusInfo.errorMessage)
-    //           : Notify.error(error.message);
-    //       this.setState({showConfirmModal:  false});
-    //   }
-    // );
+    const formData = {...this.state.formToDelete, status: LANG.FORM_STATUS.DELETED}
+    saveFormDetails(formData, true);
+  }
+
+
+  saveFormDetails = (formData, isDelete) => {
+    FormService.add(formData).then(
+      (response) => {
+        if (response.statusInfo.statusCode === APP.CODE.SUCCESS) {
+          if(isDelete) {
+            this.setState({showConfirmModal:  false});
+            Notify.success("Form deleted successfully")
+          }else {
+            Notify.success(response.statusInfo.statusMessage);
+          }
+          //   this.props.updateParent(response.responseData.id);
+          setTimeout(() => {
+            this.getAllForms();
+          }, 500);
+        } else {
+          Notify.error(response.statusInfo.errorMessage);
+        }
+      },
+      (error) => {
+        error.statusInfo
+          ? Notify.error(error.statusInfo.errorMessage)
+          : Notify.error(error.message);
+      }
+    );
   }
 
   render() {
diff --git a/src/constants/LangConstants.ts b/src/constants/LangConstants.ts
index bec48d0..56a17a8 100644
--- a/src/constants/LangConstants.ts
+++ b/src/constants/LangConstants.ts
@@ -28,7 +28,8 @@ export const LANG = {
     APPROVED: "APPROVED",
     REJECTED: "REJECTED",
     LEAD_INSPECTION_COMPLETED: "LEADINSCOMPLETED",
-    ASSISTING_INSPECTION_COMPLETED: "INSCOMPLETED"
+    ASSISTING_INSPECTION_COMPLETED: "INSCOMPLETED",
+    DELETED: "DELETED"
   },
   COL: {
     1: 1,
-- 
GitLab