Skip to content

Commit daaa93e

Browse files
[COJ]/likhith/COJ-571/Display single error message in POA section (#13129)
* fix: added condition to handle one single error message * fix: scroll into view of error message in POA
1 parent 9f61549 commit daaa93e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/account/src/Sections/Verification/ProofOfAddress/proof-of-address-form.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const ProofOfAddressForm = observer(
7070
should_show_form: true,
7171
});
7272

73+
const [should_scroll_to_top, setShouldScrollToTop] = React.useState(false);
74+
7375
const poa_uploader_files_descriptions = React.useMemo(() => getFileUploaderDescriptions('poa'), []);
7476

7577
const { upload } = useFileUploader();
@@ -89,6 +91,20 @@ const ProofOfAddressForm = observer(
8991
});
9092
}, [account_settings, fetchResidenceList, fetchStatesList]);
9193

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+
92108
const changeable_fields = getChangeableFields();
93109

94110
const validateFields = (values: TFormInitialValues) => {
@@ -163,6 +179,7 @@ const ProofOfAddressForm = observer(
163179
setStatus({ msg: data.error.message });
164180
setFormState({ ...form_state, ...{ is_btn_loading: false } });
165181
setSubmitting(false);
182+
setShouldScrollToTop(true);
166183
return;
167184
}
168185

@@ -190,6 +207,7 @@ const ProofOfAddressForm = observer(
190207
if (api_response?.warning) {
191208
setStatus({ msg: api_response?.message });
192209
setFormState({ ...form_state, ...{ is_btn_loading: false } });
210+
setShouldScrollToTop(true);
193211
return;
194212
}
195213

@@ -223,6 +241,7 @@ const ProofOfAddressForm = observer(
223241
if (isServerError(error)) {
224242
setStatus({ msg: error.message });
225243
setFormState({ ...form_state, ...{ is_btn_loading: false } });
244+
setShouldScrollToTop(true);
226245
}
227246
} finally {
228247
setSubmitting(false);
@@ -276,23 +295,22 @@ const ProofOfAddressForm = observer(
276295
className={className}
277296
>
278297
<FormBody scroll_offset={setOffset(status)}>
279-
{status?.msg && (
298+
{(status?.msg || is_resubmit) && (
280299
<HintBox
281300
className='account-form_poa-submit-error'
282301
icon='IcAlertDanger'
283302
message={
284303
<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}
286308
</Text>
287309
}
288310
is_danger
311+
id='dt_poa_submit-error'
289312
/>
290313
)}
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-
)}
296314
<FormSubHeader title={localize('Address')} title_text_size='s' />
297315
<PersonalDetailsForm
298316
is_qualified_for_poa

packages/components/src/components/hint-box/hint-box.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type THintBox = {
1212
icon_height?: number;
1313
icon_width?: number;
1414
message: string | React.ReactElement;
15+
id?: string;
1516
};
1617

1718
/** @deprecated use `InlineMessage` instead. */
@@ -25,6 +26,7 @@ const HintBox = ({
2526
icon_height,
2627
icon_width,
2728
message,
29+
id,
2830
}: THintBox) => {
2931
return (
3032
<div
@@ -38,6 +40,7 @@ const HintBox = ({
3840
},
3941
className
4042
)}
43+
id={id}
4144
>
4245
<Icon
4346
className={classNames('dc-hint-box__icon', {

0 commit comments

Comments
 (0)