From 93c0e1e5140eee2ee007f6ca4312ec5d882f10cb Mon Sep 17 00:00:00 2001
From: Harshith DS <harshith.ds@matriotsolutions.com>
Date: Tue, 2 Aug 2022 12:25:13 +0530
Subject: [PATCH] TMSS-1657: Fixed redirecting issue in Cycle and Project edit
 pages

---
 SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/edit.js   | 3 ++-
 SAS/TMSS/frontend/tmss_webapp/src/routes/Project/edit.js | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/edit.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/edit.js
index 7b367e380dd..2d63ed95976 100644
--- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/edit.js
+++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/edit.js
@@ -332,6 +332,7 @@ export class CycleEdit extends Component {
                 .then(async (cycle) => { 
                     if (cycle && this.state.cycle.updated_at !== cycle.updated_at) {
                         this.saveCycleQuota(cycle);
+                        this.props.history.length>2 && this.props.history.go(-2);
                     }   else {
                         this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Unable to update Cycle'});
                         //this.setState({errors: cycle});
@@ -410,7 +411,7 @@ export class CycleEdit extends Component {
      */
     cancelEdit() {
         publish('edit-dirty', false);
-        this.props.history.length>1?!this.state.isDirty?this.props.history.go(-2):this.props.history.go(-1):this.props.history.push(`/cycle/view/${this.props.match.params.id}`);
+        this.props.history.length>1?this.state.isDirty?this.props.history.go(-2):this.props.history.go(-1):this.props.history.push(`/cycle/view/${this.props.match.params.id}`);
         this.setState({showDialog: false});
     }
 
diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/edit.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/edit.js
index 8d9fc05dd00..bad5ca428d5 100644
--- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/edit.js
+++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/edit.js
@@ -385,6 +385,7 @@ export class ProjectEdit extends Component {
                         project.archive_location = archive_location;
                         project.archiveId = archiveId;
                         this.saveProjectQuota(project);
+                        this.props.history.length>2 && this.props.history.go(-2);
                     }   else {
                         this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Unable to update Project'});
                         this.setState({errors: project});
@@ -397,6 +398,8 @@ export class ProjectEdit extends Component {
      * Function to Create, Update & Delete project_quota for the project
      */
     async saveProjectQuota(project) {
+        this.setState({isDirty: false});
+        publish('edit-dirty', false);
         let dialog = {};
         let quotaError = {};
         let updatingProjectQuota = [];
@@ -458,8 +461,7 @@ export class ProjectEdit extends Component {
         }   else {
             dialog = {header: 'Error', detail: 'Project updated successfully but resource allocation not updated properly.'};
         }
-        this.setState({dialogVisible: true, dialog: dialog, isDirty: false});
-        publish('edit-dirty', false);
+        this.setState({dialogVisible: true, dialog: dialog});
     }
 
     /**
@@ -482,7 +484,7 @@ export class ProjectEdit extends Component {
      */
     cancelEdit() {
         publish('edit-dirty', false);
-        this.props.history.length>1?!this.state.isDirty?this.props.history.go(-2):this.props.history.go(-1):this.props.history.push(`/project/view/${this.props.match.params.id}`);
+        this.props.history.length>1?this.state.isDirty?this.props.history.go(-2):this.props.history.go(-1):this.props.history.push(`/project/view/${this.props.match.params.id}`);
         this.setState({showDialog: false});
     }
 
-- 
GitLab