Payment Modal: Fix scroll and card info validation (#1944)

This commit is contained in:
Alexander Zinchuk 2022-07-08 15:00:34 +02:00
parent e841738112
commit 63c150ddd8
5 changed files with 22 additions and 25 deletions

View File

@ -42,10 +42,7 @@ const CardInput : FC<OwnProps> = ({ value, error, onChange }) => {
const newCardType = detectCardType(e.target.value);
setCardType(newCardType);
onChange(newValue);
if (cardNumberRef.current) {
cardNumberRef.current.value = newValue;
}
}, [onChange, cardNumberRef]);
}, [onChange]);
const cardIcon = getCardIcon(cardType);
@ -61,6 +58,7 @@ const CardInput : FC<OwnProps> = ({ value, error, onChange }) => {
error={error}
tabIndex={0}
maxLength={CARD_NUMBER_MAX_LENGTH}
teactExperimentControlled
/>
<span className="right-addon">{cardIcon}</span>
</div>

View File

@ -1,5 +1,5 @@
import type { FC } from '../../lib/teact/teact';
import React, { memo, useCallback, useRef } from '../../lib/teact/teact';
import React, { memo, useCallback } from '../../lib/teact/teact';
import { formatCardExpiry } from '../middle/helpers/inputFormatters';
@ -16,33 +16,27 @@ export type OwnProps = {
const ExpiryInput : FC<OwnProps> = ({ value, error, onChange }) => {
const lang = useLang();
// eslint-disable-next-line no-null/no-null
const expiryInputRef = useRef<HTMLInputElement>(null);
const handleKeyDown = useCallback((e) => {
if (e.key === 'Backspace' && value.charAt(value.length - 1) === '/') {
const newValue = value.slice(0, value.length - 1);
if (expiryInputRef.current) {
expiryInputRef.current.value = newValue;
}
}
}, [value]);
const handleChange = useCallback((e) => {
onChange(formatCardExpiry(e.target.value));
}, [onChange]);
const newValue = e.target.value;
// Allow deleting separator
if (value.endsWith('/') && value.length > newValue.length) {
onChange(newValue);
} else {
onChange(formatCardExpiry(e.target.value));
}
}, [onChange, value]);
return (
<InputText
label={lang('PaymentCardExpireDate')}
ref={expiryInputRef}
onChange={handleChange}
onKeyDown={handleKeyDown}
value={value}
error={error}
inputMode="numeric"
tabIndex={0}
maxLength={MAX_FIELD_LENGTH}
teactExperimentControlled
/>
);
};

View File

@ -58,7 +58,8 @@ const PaymentInfo: FC<OwnProps> = ({
}, [dispatch]);
const handleCvvChange = useCallback((e) => {
dispatch({ type: 'changeCvvCode', payload: e.target.value });
const newValue = e.target.value.replace(/[^0-9]/g, '');
dispatch({ type: 'changeCvvCode', payload: newValue });
}, [dispatch]);
const handleCountryChange = useCallback((e) => {
@ -110,6 +111,7 @@ const PaymentInfo: FC<OwnProps> = ({
maxLength={3}
tabIndex={0}
error={formErrors.cvv}
teactExperimentControlled
/>
</section>
{ needCountry || needZip ? (
@ -147,6 +149,7 @@ const PaymentInfo: FC<OwnProps> = ({
value={state.billingZip}
inputMode="text"
tabIndex={0}
maxLength={12}
error={formErrors.billingZip}
/>
)}

View File

@ -30,7 +30,7 @@
}
.Transition {
height: 25rem;
height: min(25rem, 60vh);
}
.empty-content {
@ -54,7 +54,7 @@
}
.footer {
position: absolute;
position: relative;
bottom: 0;
border-bottom-left-radius: var(--border-radius-default-small);
border-bottom-right-radius: var(--border-radius-default-small);
@ -75,8 +75,7 @@
.modal-content {
padding: 0;
overflow: auto;
overflow: overlay;
overflow: hidden;
}
}

View File

@ -21,6 +21,7 @@ type OwnProps = {
autoComplete?: string;
maxLength?: number;
tabIndex?: number;
teactExperimentControlled?: boolean;
inputMode?: 'text' | 'none' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
onInput?: (e: FormEvent<HTMLInputElement>) => void;
@ -45,6 +46,7 @@ const InputText: FC<OwnProps> = ({
inputMode,
maxLength,
tabIndex,
teactExperimentControlled,
onChange,
onInput,
onKeyPress,
@ -87,6 +89,7 @@ const InputText: FC<OwnProps> = ({
onBlur={onBlur}
onPaste={onPaste}
aria-label={labelText}
teactExperimentControlled={teactExperimentControlled}
/>
{labelText && (
<label htmlFor={id}>{labelText}</label>