@@ -70,6 +70,8 @@ const ProofOfAddressForm = observer(
70
70
should_show_form : true ,
71
71
} ) ;
72
72
73
+ const [ should_scroll_to_top , setShouldScrollToTop ] = React . useState ( false ) ;
74
+
73
75
const poa_uploader_files_descriptions = React . useMemo ( ( ) => getFileUploaderDescriptions ( 'poa' ) , [ ] ) ;
74
76
75
77
const { upload } = useFileUploader ( ) ;
@@ -89,6 +91,20 @@ const ProofOfAddressForm = observer(
89
91
} ) ;
90
92
} , [ account_settings , fetchResidenceList , fetchStatesList ] ) ;
91
93
94
+ React . useEffect ( ( ) => {
95
+ if ( should_scroll_to_top ) {
96
+ // Scroll to the top of the page
97
+ const el = document . querySelector ( '#dt_poa_submit-error' ) as HTMLInputElement ;
98
+ const target_element = el ?. parentElement ?? el ;
99
+ if ( typeof target_element ?. scrollIntoView === 'function' ) {
100
+ target_element ?. scrollIntoView ( { behavior : 'smooth' , block : 'start' } ) ;
101
+ }
102
+
103
+ // Reset the condition
104
+ setShouldScrollToTop ( false ) ;
105
+ }
106
+ } , [ should_scroll_to_top ] ) ;
107
+
92
108
const changeable_fields = getChangeableFields ( ) ;
93
109
94
110
const validateFields = ( values : TFormInitialValues ) => {
@@ -163,6 +179,7 @@ const ProofOfAddressForm = observer(
163
179
setStatus ( { msg : data . error . message } ) ;
164
180
setFormState ( { ...form_state , ...{ is_btn_loading : false } } ) ;
165
181
setSubmitting ( false ) ;
182
+ setShouldScrollToTop ( true ) ;
166
183
return ;
167
184
}
168
185
@@ -190,6 +207,7 @@ const ProofOfAddressForm = observer(
190
207
if ( api_response ?. warning ) {
191
208
setStatus ( { msg : api_response ?. message } ) ;
192
209
setFormState ( { ...form_state , ...{ is_btn_loading : false } } ) ;
210
+ setShouldScrollToTop ( true ) ;
193
211
return ;
194
212
}
195
213
@@ -223,6 +241,7 @@ const ProofOfAddressForm = observer(
223
241
if ( isServerError ( error ) ) {
224
242
setStatus ( { msg : error . message } ) ;
225
243
setFormState ( { ...form_state , ...{ is_btn_loading : false } } ) ;
244
+ setShouldScrollToTop ( true ) ;
226
245
}
227
246
} finally {
228
247
setSubmitting ( false ) ;
@@ -276,23 +295,22 @@ const ProofOfAddressForm = observer(
276
295
className = { className }
277
296
>
278
297
< FormBody scroll_offset = { setOffset ( status ) } >
279
- { status ?. msg && (
298
+ { ( status ?. msg || is_resubmit ) && (
280
299
< HintBox
281
300
className = 'account-form_poa-submit-error'
282
301
icon = 'IcAlertDanger'
283
302
message = {
284
303
< Text as = 'p' size = { is_mobile ? 'xxxs' : 'xs' } >
285
- { status . msg }
304
+ { ! status ?. msg && is_resubmit && (
305
+ < Localize i18n_default_text = 'We were unable to verify your address with the details you provided. Please check and resubmit or choose a different document type.' />
306
+ ) }
307
+ { status ?. msg }
286
308
</ Text >
287
309
}
288
310
is_danger
311
+ id = 'dt_poa_submit-error'
289
312
/>
290
313
) }
291
- { is_resubmit && (
292
- < Text size = { is_mobile ? 'xxs' : 'xs' } align = 'left' color = 'loss-danger' >
293
- < Localize i18n_default_text = 'We were unable to verify your address with the details you provided. Please check and resubmit or choose a different document type.' />
294
- </ Text >
295
- ) }
296
314
< FormSubHeader title = { localize ( 'Address' ) } title_text_size = 's' />
297
315
< PersonalDetailsForm
298
316
is_qualified_for_poa
0 commit comments