Skip to content

Commit 7e842b9

Browse files
committed
fix read all the expiry date errors
1 parent d95d06f commit 7e842b9

File tree

5 files changed

+9
-28
lines changed

5 files changed

+9
-28
lines changed

packages/lib/src/components/Card/components/CardInput/useSRPanelForCardInputErrors.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from 'preact/hooks';
22
import useSRPanelContext from '../../../../core/Errors/useSRPanelContext';
33
import { SetSRMessagesReturnFn } from '../../../../core/Errors/SRPanelProvider';
4-
import { handlePartialAddressMode, lookupBlurBasedErrors, mapFieldKey } from './utils';
4+
import { handlePartialAddressMode, mapFieldKey } from './utils';
55
import { usePrevious } from '../../../../utils/hookUtils';
66
import { SetSRMessagesReturnObject, SortedErrorObject } from '../../../../core/Errors/types';
77
import { ERROR_ACTION_BLUR_SCENARIO, ERROR_ACTION_FOCUS_FIELD } from '../../../../core/Errors/constants';
@@ -66,14 +66,7 @@ const useSRPanelForCardInputErrors = ({ errors, props, isValidating, retrieveLay
6666
const latestErrorMsg = difference?.[0];
6767

6868
if (latestErrorMsg) {
69-
// Use the error code to look up whether error is actually a blur based one (most are but some SF ones aren't)
70-
const isBlurBasedError = lookupBlurBasedErrors(latestErrorMsg.errorCode);
71-
72-
/**
73-
* ONLY ADD BLUR BASED ERRORS TO THE ERROR PANEL - doing this step prevents the non-blur based errors from being read out twice
74-
* (once from the aria-live, error panel & once from the aria-describedby element)
75-
*/
76-
const latestSRError = isBlurBasedError ? latestErrorMsg.errorMessage : null;
69+
const latestSRError = latestErrorMsg.errorMessage;
7770
// console.log('### CardInput2::componentDidUpdate:: #2 (not validating) single error:: latestSRError', latestSRError);
7871
setSRMessagesFromStrings(latestSRError);
7972
} else {

packages/lib/src/components/Card/components/CardInput/utils.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { InstallmentsObj } from './components/Installments/Installments';
1717
import { SFPProps } from '../../../internal/SecuredFields/SFP/types';
1818
import { BRAND_READABLE_NAME_MAP } from '../../../internal/SecuredFields/lib/constants';
1919
import { UseImageHookType } from '../../../../core/Context/useImage';
20-
import { SF_ErrorCodes } from '../../../../core/Errors/constants';
2120

2221
export const getCardImageUrl = (brand: string, getImage: UseImageHookType): string => {
2322
const imageOptions = {
@@ -173,16 +172,6 @@ export const handlePartialAddressMode = (addressMode: AddressModeOptions): Addre
173172
return addressMode == AddressModeOptions.partial ? PARTIAL_ADDRESS_SCHEMA : null;
174173
};
175174

176-
// Almost all errors are blur based, but some SF ones are not i.e. when an unsupported card is entered or the expiry date is out of range
177-
export function lookupBlurBasedErrors(errorCode) {
178-
return ![
179-
SF_ErrorCodes.ERROR_MSG_UNSUPPORTED_CARD_ENTERED,
180-
SF_ErrorCodes.ERROR_MSG_CARD_TOO_OLD,
181-
SF_ErrorCodes.ERROR_MSG_CARD_TOO_FAR_IN_FUTURE,
182-
SF_ErrorCodes.ERROR_MSG_CARD_EXPIRES_TOO_SOON
183-
].includes(errorCode);
184-
}
185-
186175
export function getFullBrandName(brand) {
187176
return BRAND_READABLE_NAME_MAP[brand] ?? brand;
188177
}

packages/lib/src/core/Errors/SRMessages.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, Fragment } from 'preact';
1+
import { h } from 'preact';
22
import { useRef, useState } from 'preact/hooks';
33
import { SRMessagesProps } from './types';
44

@@ -7,7 +7,7 @@ export interface SRMessagesRef {
77
setMessages?: (who: string[]) => void;
88
}
99

10-
export function SRMessages({ setComponentRef }: SRMessagesProps) {
10+
export function SRMessages({ setComponentRef, customAria }: SRMessagesProps) {
1111
const messagesRef = useRef<SRMessagesRef>({});
1212
// Just call once to create the object by which we expose the members expected by the parent comp
1313
if (!Object.keys(messagesRef.current).length) {
@@ -22,14 +22,14 @@ export function SRMessages({ setComponentRef }: SRMessagesProps) {
2222
};
2323

2424
return messages ? (
25-
<Fragment>
25+
<div role={'log'} {...customAria}>
2626
{messages.map(msg => {
2727
return (
2828
<div key={msg} className="adyen-checkout-sr-panel__msg" {...(process.env.NODE_ENV !== 'production' && { 'data-testid': msg })}>
2929
{msg}
3030
</div>
3131
);
3232
})}
33-
</Fragment>
33+
</div>
3434
) : null;
3535
}

packages/lib/src/core/Errors/SRPanel.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SRPanel extends BaseElement<SRPanelProps> {
1919
showPanel: false,
2020
id: 'ariaLiveSRPanel',
2121
ariaAttributes: {
22-
'aria-relevant': 'all',
22+
'aria-relevant': 'additions',
2323
'aria-live': 'polite',
2424
'aria-atomic': 'true'
2525
}
@@ -104,11 +104,9 @@ export class SRPanel extends BaseElement<SRPanelProps> {
104104
return (
105105
<div
106106
className={this.showPanel ? 'adyen-checkout-sr-panel' : 'adyen-checkout-sr-panel--sr-only'}
107-
role={'log'}
108-
{...this.props.ariaAttributes}
109107
{...(process.env.NODE_ENV !== 'production' && { 'data-testid': this.id })}
110108
>
111-
<SRMessages setComponentRef={this.setComponentRef} />
109+
<SRMessages setComponentRef={this.setComponentRef} customAria={this.props.ariaAttributes} />
112110
</div>
113111
);
114112
}

packages/lib/src/core/Errors/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type SRPanelConfig = Pick<SRPanelProps, 'enabled' | 'node' | 'showPanel'
4949

5050
export interface SRMessagesProps {
5151
setComponentRef: (ref: any) => void;
52+
customAria: any;
5253
}
5354

5455
export interface GenericError {

0 commit comments

Comments
 (0)