From 73e14ed0c9ff7ce2a00644208d640d8c44ae91d0 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 11:50:03 -0400 Subject: [PATCH 01/10] possible fix --- src/registrar/views/domain_request.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index b7462f3002..e5dbfeb9b1 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -497,6 +497,12 @@ def save(self, forms: list): for form in forms: if form is not None and hasattr(form, "to_database"): form.to_database(self.domain_request) + + def go_to_home_page_if_last_step_back_button(self): + print(self.request.session.get("last_page")) + if self.request.session.get("last_page") == "request/finished": + return redirect(reverse("home")) + return None # TODO - this is a WIP until the domain request experience for portfolios is complete From 8c7bbb9bad7323362edcbea5c829dc82c389a61f Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 15:05:36 -0400 Subject: [PATCH 02/10] removed method --- src/registrar/views/domain_request.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index e5dbfeb9b1..61404698ab 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -498,12 +498,6 @@ def save(self, forms: list): if form is not None and hasattr(form, "to_database"): form.to_database(self.domain_request) - def go_to_home_page_if_last_step_back_button(self): - print(self.request.session.get("last_page")) - if self.request.session.get("last_page") == "request/finished": - return redirect(reverse("home")) - return None - # TODO - this is a WIP until the domain request experience for portfolios is complete class PortfolioDomainRequestWizard(DomainRequestWizard): From 144252ac7f9da3f348600b24b12068c88d7831df Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 16:16:03 -0400 Subject: [PATCH 03/10] fix --- src/registrar/assets/js/get-gov.js | 16 ++++++++++++++++ src/registrar/views/domain_request.py | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 027ef4344d..8544feea9b 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2228,3 +2228,19 @@ const utcDateString = (dateString) => { } } })(); + + +(function() { + const currentPath = window.location.pathname; + if(currentPath == "/request/finished"){ + window.onpopstate = function(event) { + + window.location.href = "" + }; + + } + + + // Optional: Push a new state to the history to handle the initial load + history.pushState(null, document.title, window.location.href); +})(); \ No newline at end of file diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index 61404698ab..8315034342 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -497,7 +497,6 @@ def save(self, forms: list): for form in forms: if form is not None and hasattr(form, "to_database"): form.to_database(self.domain_request) - # TODO - this is a WIP until the domain request experience for portfolios is complete class PortfolioDomainRequestWizard(DomainRequestWizard): From b9ee17b411d7dc060ff577e04844e875a9909982 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 16:16:38 -0400 Subject: [PATCH 04/10] fixed spacing --- src/registrar/views/domain_request.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index 8315034342..b7462f3002 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -498,6 +498,7 @@ def save(self, forms: list): if form is not None and hasattr(form, "to_database"): form.to_database(self.domain_request) + # TODO - this is a WIP until the domain request experience for portfolios is complete class PortfolioDomainRequestWizard(DomainRequestWizard): StepEnum: PortfolioDomainRequestStep = PortfolioDomainRequestStep # type: ignore From e3efa42bc00caf7d6689a91dc87f3cb372236816 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 16:17:30 -0400 Subject: [PATCH 05/10] removed pushState --- src/registrar/assets/js/get-gov.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 8544feea9b..2e476825b5 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2239,8 +2239,4 @@ const utcDateString = (dateString) => { }; } - - - // Optional: Push a new state to the history to handle the initial load - history.pushState(null, document.title, window.location.href); })(); \ No newline at end of file From af2715373242838492bf4d46ab48434869ad2348 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 16:33:06 -0400 Subject: [PATCH 06/10] added / to match path name --- src/registrar/assets/js/get-gov.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 2e476825b5..d35f4c0acd 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2232,7 +2232,7 @@ const utcDateString = (dateString) => { (function() { const currentPath = window.location.pathname; - if(currentPath == "/request/finished"){ + if(currentPath == "/request/finished/"){ window.onpopstate = function(event) { window.location.href = "" From c5e7c22efe42cc4acd396e22b3c7a106d9dd7e6c Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 16:55:36 -0400 Subject: [PATCH 07/10] added fix --- src/registrar/assets/js/get-gov.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index d35f4c0acd..8c38522cb8 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2233,6 +2233,7 @@ const utcDateString = (dateString) => { (function() { const currentPath = window.location.pathname; if(currentPath == "/request/finished/"){ + history.pushState(null, null, currentPath); window.onpopstate = function(event) { window.location.href = "" From 4f1c40910663e64306276fa3c0ef9bf0b088a886 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Tue, 24 Sep 2024 23:28:22 -0400 Subject: [PATCH 08/10] added a possible fix for the back button --- src/registrar/assets/js/get-gov.js | 35 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 8c38522cb8..0f2f0c4af2 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2230,14 +2230,35 @@ const utcDateString = (dateString) => { })(); +// (function() { +// const currentPath = window.location.pathname; + +// if (currentPath === "/request/finished/") { +// // Push a new state to prevent going back +// history.pushState({}, "", ""); + +// console.log("requesteeefrf") +// window.addEventListener('popstate', function(event){ +// window.location.href = "/"; +// }) +// // // Set up the popstate event handler +// // window.onpopstate = function(event) { +// // console.log("Back button pressed"); +// // // Redirect or handle state change +// // window.location.href = "/"; // Replace with your target URL +// // }; +// } +// })(); + (function() { + // Set up the popstate event handler const currentPath = window.location.pathname; - if(currentPath == "/request/finished/"){ - history.pushState(null, null, currentPath); - window.onpopstate = function(event) { - - window.location.href = "" + history.pushState({}, "", ""); + if (currentPath === "/request/finished/") { + window.onpopstate = function(event) { + console.log("Back button pressed"); + window.location.href = "/"; }; +} - } -})(); \ No newline at end of file +})(); \ No newline at end of file From d81841e95012043ebfeff99fbc92a819b32b58df Mon Sep 17 00:00:00 2001 From: asaki222 Date: Wed, 25 Sep 2024 14:41:57 -0400 Subject: [PATCH 09/10] possible fix --- src/registrar/assets/js/get-gov.js | 36 +++++++----------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 0f2f0c4af2..31c9f713bb 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2230,35 +2230,15 @@ const utcDateString = (dateString) => { })(); -// (function() { -// const currentPath = window.location.pathname; - -// if (currentPath === "/request/finished/") { -// // Push a new state to prevent going back -// history.pushState({}, "", ""); - -// console.log("requesteeefrf") -// window.addEventListener('popstate', function(event){ -// window.location.href = "/"; -// }) -// // // Set up the popstate event handler -// // window.onpopstate = function(event) { -// // console.log("Back button pressed"); -// // // Redirect or handle state change -// // window.location.href = "/"; // Replace with your target URL -// // }; -// } -// })(); - (function() { - // Set up the popstate event handler const currentPath = window.location.pathname; - history.pushState({}, "", ""); if (currentPath === "/request/finished/") { - window.onpopstate = function(event) { - console.log("Back button pressed"); - window.location.href = "/"; + history.replaceState({ data: '' }, '', ''); + window.onpopstate = function(event) { + if (event.state) { + console.log("Back button pressed"); + window.location.href = "/"; + } }; -} - -})(); \ No newline at end of file + } +})(); From eccc916181bf62370ef02b7a2c80e7748251bb80 Mon Sep 17 00:00:00 2001 From: asaki222 Date: Thu, 26 Sep 2024 17:14:25 -0400 Subject: [PATCH 10/10] hopefully final changes --- src/registrar/assets/js/get-gov.js | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 31c9f713bb..ff81554126 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2230,15 +2230,30 @@ const utcDateString = (dateString) => { })(); +/** + * An IIFE that redirects to the home page when a user clicks on the back button on the 'request/finished/' page + */ + (function() { - const currentPath = window.location.pathname; - if (currentPath === "/request/finished/") { - history.replaceState({ data: '' }, '', ''); - window.onpopstate = function(event) { - if (event.state) { - console.log("Back button pressed"); - window.location.href = "/"; + document.addEventListener("DOMContentLoaded", () => { + const currentPath = window.location.pathname; + + if (currentPath === "/request/finished/") { + + // Push a dummy state to create a history entry + history.pushState({ page: "dummy" }, "Dummy Page", "/request/review"); + // Replace the current state with the correct page state + history.replaceState({ page: "finished" }, "Finished Page", "/request/finished/") + + // Listen for back button click event + window.addEventListener("popstate", (event) => { + // Handle back navigation + if (!event.state || event.state.page !== "finished") { + // Redirect to home page + window.location.href = "/"; + } + }); } - }; - } + }); })(); +