From c0f984c41d437139fe830aeb555370f9c983e42a Mon Sep 17 00:00:00 2001 From: arnoldezeolisa <33605318+arnoldezeolisa@users.noreply.github.com> Date: Wed, 8 Jun 2022 15:07:42 -0500 Subject: [PATCH] added cancel modal instead of error toast when trying to nav away without saving (#471) * added cancel modal instead of error toast when trying to nav away from tab without saving * added in navigation after selecting leave in cancel modal * adding tracked var back --- .../lwc/dataMappingStep/dataMappingStep.js | 3 +- .../main/default/lwc/setup/setup.html | 12 +++++ .../force-app/main/default/lwc/setup/setup.js | 48 ++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/sfdx/force-app/main/default/lwc/dataMappingStep/dataMappingStep.js b/sfdx/force-app/main/default/lwc/dataMappingStep/dataMappingStep.js index 5c4bce1acb..c0c7d71c39 100644 --- a/sfdx/force-app/main/default/lwc/dataMappingStep/dataMappingStep.js +++ b/sfdx/force-app/main/default/lwc/dataMappingStep/dataMappingStep.js @@ -165,6 +165,7 @@ export default class DataMappingStep extends LightningElement { this.isMappingsUpdated = true; this.dispatchEvent(new CustomEvent('valuechange')); } + this.isMappingsUpdated = false; } debounce(targetInput) { @@ -484,7 +485,7 @@ export default class DataMappingStep extends LightningElement { window.open(apiUrl, '_blank'); } - async connectedCallback() { + @api async connectedCallback() { this.dispatchEvent(new CustomEvent('contentloading')); try { const getFormattedStripeObjects = await getFormattedStripeObjectFields(); diff --git a/sfdx/force-app/main/default/lwc/setup/setup.html b/sfdx/force-app/main/default/lwc/setup/setup.html index a190c49129..74be8f0f25 100644 --- a/sfdx/force-app/main/default/lwc/setup/setup.html +++ b/sfdx/force-app/main/default/lwc/setup/setup.html @@ -424,4 +424,16 @@

Stripe Billing Connector + + +
+ +

+ Are you sure you want to exit without saving your changes? All changes will be reverted if you leave this tab now. +

+
+ + +
+ \ No newline at end of file diff --git a/sfdx/force-app/main/default/lwc/setup/setup.js b/sfdx/force-app/main/default/lwc/setup/setup.js index 5465dce2c6..77c97326f3 100644 --- a/sfdx/force-app/main/default/lwc/setup/setup.js +++ b/sfdx/force-app/main/default/lwc/setup/setup.js @@ -21,6 +21,9 @@ export default class FirstTimeSetup extends LightningElement { @track saveDisabled = true; @track loading = true; @track contentLoading = false; + @track changesCanceled = false; + @track currentTab = ''; + @track tabToNavTo = ''; @track stepName; @track steps = [ { @@ -315,10 +318,53 @@ export default class FirstTimeSetup extends LightningElement { } } } else { - this.showSetupToast('Save your changes before navigating to another tab', 'error', 'sticky') + this.currentTab = event.currentTarget; + this.tabToNavTo = this.currentTab.dataset.index; + this.showCancelModal(); } } + runTabConnectedCallback() { + this.saveDisabled = true; + this.changesCanceled = true; + if(this.activeSectionIndex == 2) { + this.template.querySelector('c-sync-preferences-step').connectedCallback(); + this.hideCancelModal(); + return; + } + + this.template.querySelector('c-data-mapping-step').connectedCallback(); + this.hideCancelModal(); + } + + showCancelModal() { + this.template.querySelector('.stripe-modal_confirm-cancel').show(); + } + + hideCancelModal() { + this.template.querySelector('.stripe-modal_confirm-cancel').hide(); + if(this.changesCanceled) { + this.showSetupToast('Your changes have been reverted', 'success'); + this.changesCanceled = false; + + //navigate to selcted step + const currentActive = this.template.querySelector('.stripe-navigation-item_active'); + const previousSectionContent = this.template.querySelector('c-step[data-index="' + this.activeSectionIndex + '"]'); + if(previousSectionContent) { + currentActive.classList.remove('stripe-navigation-item_active'); + previousSectionContent.classList.add('slds-hide'); + } + + this.currentTab.classList.add('stripe-navigation-item_active'); + this.activeSectionIndex = this.tabToNavTo; + const targetSectionContent = this.template.querySelector('c-step[data-index="' + this.activeSectionIndex + '"]'); + if(targetSectionContent) { + targetSectionContent.classList.remove('slds-hide'); + } + } + + } + showNextStep() { const lastActiveStep = this.template.querySelector('c-step[data-index="' + this.activeStepIndex + '"]'); this.activeStepIndex++;