Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: multiple alerts getting rendered in DOM when moving back-and-forth from route and query page #132

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ onBeforeRouteLeave(async (to) => {
if(to.path === "/login") return;
let canLeave = false;

if(!hasUnsavedChanges.value) {
// clearning the selected ruleId whenever user tries to leave the page, we need to clear this id, as if user opens some other routing then the id will not be found which will result in an empty state scenario
store.dispatch("orderRouting/updateRoutingRuleId", "")
return;
}

const alert = await alertController.create({
header: translate("Leave page"),
message: translate("Any edits made on this page will be lost."),
Expand All @@ -340,19 +346,17 @@ onBeforeRouteLeave(async (to) => {
{
text: translate("LEAVE"),
handler: () => {
// clearning the selected ruleId whenever user leaves the page, we need to clear this id, as if user opens some other routing then the id will not be found which will result in an empty state scenario
store.dispatch("orderRouting/updateRoutingRuleId", "")
canLeave = true;
},
},
],
});

if(hasUnsavedChanges.value) {
alert.present();
await alert.onDidDismiss();
return canLeave;
}
// clearning the selected ruleId whenever user tries to leave the page, we need to clear this id, as if user opens some other routing then the id will not be found which will result in an empty state scenario
store.dispatch("orderRouting/updateRoutingRuleId", "")
alert.present();
await alert.onDidDismiss();
return canLeave;
})

function getRouteIndex() {
Expand Down
13 changes: 8 additions & 5 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ onBeforeRouteLeave(async (to) => {
if(to.path === "/login") return;
let canLeave = false;

// If there are no unsaved changes do not create and present the alert
if(!hasUnsavedChanges.value) {
return;
}

const alert = await alertController.create({
header: translate("Leave page"),
message: translate("Any edits made on this page will be lost."),
Expand All @@ -223,11 +228,9 @@ onBeforeRouteLeave(async (to) => {
],
});

if(hasUnsavedChanges.value) {
alert.present();
await alert.onDidDismiss();
return canLeave;
}
alert.present();
await alert.onDidDismiss();
return canLeave;
})

function updateCronExpression(event: CustomEvent) {
Expand Down
Loading