@@ -19,6 +19,7 @@ import { CreateDividendDistributionParams } from './Container';
1919import * as sc from './styles' ;
2020import { Step1 } from './Step-1' ;
2121import { Step2 } from './Step-2' ;
22+ import { ConfirmModal } from './Step-2/ConfirmModal' ;
2223import { Step3 } from './Step-3' ;
2324import { types , formatters } from '@polymathnetwork/new-shared' ;
2425import BigNumber from 'bignumber.js' ;
@@ -27,6 +28,7 @@ import {
2728 GetErc20BalanceByAddressAndWalletArgs ,
2829 GetIsValidErc20ByAddressArgs ,
2930} from '~/types' ;
31+ import { block , unblock } from 'redux-little-router' ;
3032
3133export interface ExclusionEntry {
3234 [ 'Investor ETH Address' ] : string ;
@@ -64,6 +66,8 @@ export interface State {
6466 dividendAmount : BigNumber ;
6567 tokenSymbol : string ;
6668 positiveWithholdingAmount : number ;
69+ isDirty : boolean ;
70+ confirmModalOpen : boolean ;
6771}
6872
6973export class Presenter extends Component < Props , State > {
@@ -74,6 +78,8 @@ export class Presenter extends Component<Props, State> {
7478 positiveWithholdingAmount : this . props . taxWithholdings . filter (
7579 ( { percentage } ) => percentage > 0
7680 ) . length ,
81+ isDirty : false ,
82+ confirmModalOpen : false ,
7783 } ;
7884
7985 public setExcludedWallets = ( excludedWallets : null | ExclusionEntry [ ] ) => {
@@ -92,6 +98,41 @@ export class Presenter extends Component<Props, State> {
9298 this . setState ( { positiveWithholdingAmount } ) ;
9399 } ;
94100
101+ public setIsDirty = ( isDirty : boolean ) => {
102+ if ( isDirty !== this . state . isDirty ) {
103+ this . setState ( { isDirty } ) ;
104+ if ( isDirty ) {
105+ // Block reload
106+ window . onbeforeunload = e => {
107+ e . preventDefault ( ) ;
108+ return true ;
109+ } ;
110+ block ( ( ) => {
111+ return (
112+ 'To apply your new/modified tax withholding entries, simply hit "CANCEL" and click on "UPDATE" above the Tax Withholdings table.\n' +
113+ 'To ignore the new/modified tax withholding entries, simply hit "PROCEED"'
114+ ) ;
115+ } ) ;
116+ } else {
117+ window . onbeforeunload = null ;
118+ unblock ( ) ;
119+ }
120+ }
121+ } ;
122+
123+ public closeConfirmModal = ( ) => {
124+ this . setState ( { confirmModalOpen : false } ) ;
125+ } ;
126+
127+ public openConfirmModal = ( ) => {
128+ this . setState ( { confirmModalOpen : true } ) ;
129+ } ;
130+
131+ public onConfirmBack = ( ) => {
132+ this . closeConfirmModal ( ) ;
133+ this . props . onPreviousStep ( ) ;
134+ } ;
135+
95136 public getExcludedAddresses = ( ) => {
96137 const { excludedWallets } = this . state ;
97138
@@ -145,6 +186,7 @@ export class Presenter extends Component<Props, State> {
145186 nonExcludedInvestors = { nonExcludedInvestors }
146187 exclusionList = { exclusionList }
147188 isLoadingData = { isLoadingData }
189+ setIsDirty = { this . setIsDirty }
148190 />
149191 ) ;
150192 }
@@ -187,6 +229,7 @@ export class Presenter extends Component<Props, State> {
187229 dividendAmount,
188230 tokenSymbol,
189231 positiveWithholdingAmount,
232+ confirmModalOpen,
190233 } = this . state ;
191234 const { investorBalances } = checkpoint ;
192235 const exclusionList = this . getExcludedAddresses ( ) ;
@@ -208,9 +251,13 @@ export class Presenter extends Component<Props, State> {
208251 ) => {
209252 // TODO @RafaelVidaurre : Fix this by using the right component
210253 if ( stepIndex > 0 ) {
211- onPreviousStep ( ) ;
212254 event . preventDefault ( ) ;
213255 event . stopPropagation ( ) ;
256+ if ( this . state . isDirty ) {
257+ this . openConfirmModal ( ) ;
258+ } else {
259+ onPreviousStep ( ) ;
260+ }
214261 }
215262 } }
216263 >
@@ -300,6 +347,11 @@ export class Presenter extends Component<Props, State> {
300347 </ CardPrimary >
301348 </ GridRow . Col >
302349 </ GridRow >
350+ < ConfirmModal
351+ isOpen = { confirmModalOpen }
352+ onConfirm = { this . onConfirmBack }
353+ onClose = { this . closeConfirmModal }
354+ />
303355 </ div >
304356 ) ;
305357 }
0 commit comments