22/**
33 * External dependencies
44 */
5- import React , { useState , useLayoutEffect , useEffect } from 'react' ;
5+ import React , { useState , useEffect , useLayoutEffect } from 'react' ;
66import { ExternalLink } from '@wordpress/components' ;
77import { __ , sprintf } from '@wordpress/i18n' ;
8- import { getQuery } from '@woocommerce/navigation' ;
8+ import { getQuery , updateQueryString } from '@woocommerce/navigation' ;
9+ import { dispatch } from '@wordpress/data' ;
910
1011/**
1112 * Internal dependencies
@@ -29,6 +30,7 @@ import {
2930} from '../../data' ;
3031import FraudProtection from '../fraud-protection' ;
3132import DuplicatedPaymentMethodsContext from './duplicated-payment-methods-context' ;
33+ import VatFormModal from '../../vat/form-modal' ;
3234import './style.scss' ;
3335
3436const ExpressCheckoutDescription = ( ) => (
@@ -185,6 +187,36 @@ const SettingsManager = () => {
185187 dismissedDuplicateNotices ,
186188 setDismissedDuplicateNotices ,
187189 ] = useState ( wcpaySettings . dismissedDuplicateNotices || { } ) ;
190+ const [ isVatFormModalOpen , setVatFormModalOpen ] = useState ( false ) ;
191+
192+ useEffect ( ( ) => {
193+ const urlParams = new URLSearchParams ( window . location . search ) ;
194+ if ( urlParams . get ( 'woopayments-vat-details-modal' ) === 'true' ) {
195+ if ( ! wcpaySettings . accountStatus . hasSubmittedVatData ) {
196+ setVatFormModalOpen ( true ) ;
197+ } else {
198+ dispatch ( 'core/notices' ) . createInfoNotice (
199+ __ (
200+ 'Tax details are already submitted.' ,
201+ 'woocommerce-payments'
202+ )
203+ ) ;
204+ }
205+ }
206+ } , [ ] ) ;
207+
208+ const handleVatFormModalClose = ( ) => {
209+ setVatFormModalOpen ( false ) ;
210+ // Remove the URL parameter when the modal is closed.
211+ updateQueryString ( { 'woopayments-vat-details-modal' : undefined } ) ;
212+ } ;
213+
214+ const handleVatFormModalCompleted = ( ) => {
215+ dispatch ( 'core/notices' ) . createInfoNotice (
216+ __ ( 'Tax details updated' , 'woocommerce-payments' )
217+ ) ;
218+ handleVatFormModalClose ( ) ;
219+ } ;
188220
189221 return (
190222 < SettingsLayout >
@@ -262,6 +294,11 @@ const SettingsManager = () => {
262294 </ LoadableSettingsSection >
263295 </ SettingsSection >
264296 < SaveSettingsSection disabled = { ! isTransactionInputsValid } />
297+ < VatFormModal
298+ isModalOpen = { isVatFormModalOpen }
299+ setModalOpen = { handleVatFormModalClose }
300+ onCompleted = { handleVatFormModalCompleted }
301+ />
265302 </ SettingsLayout >
266303 ) ;
267304} ;
0 commit comments