Skip to content

Commit bd96bfc

Browse files
mfranciscDevtools
andauthored
phone number should not have duplicated country code (#1223)
Co-authored-by: Devtools <devtools@redhat.com>
1 parent 7a7ea1f commit bd96bfc

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationSteps/PhoneNumberStep.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
*/
1616
import React, { ForwardedRef, forwardRef } from 'react';
1717
import { E164Number } from 'libphonenumber-js/types.cjs';
18-
import {
19-
default as RPNInput,
20-
Country,
21-
getCountryCallingCode,
22-
} from 'react-phone-number-input';
18+
import { default as RPNInput, Country } from 'react-phone-number-input';
2319
import { useTheme } from '@mui/material/styles';
2420
import Box from '@mui/material/Box';
2521
import Button from '@mui/material/Button';
@@ -34,7 +30,7 @@ import DialogContentText from '@mui/material/DialogContentText';
3430
import DialogActions from '@mui/material/DialogActions';
3531
import IconButton from '@mui/material/IconButton';
3632
import CloseIcon from '@mui/icons-material/Close';
37-
import InputAdornment from '@mui/material/InputAdornment';
33+
3834
import CircularProgress from '@mui/material/CircularProgress';
3935

4036
const FLAG_FETCH_URL =
@@ -81,15 +77,6 @@ export const PhoneNumberStep: React.FC<PhoneNumberFormProps> = ({
8177
{...props}
8278
// eslint-disable-next-line jsx-a11y/no-autofocus
8379
autoFocus
84-
InputProps={{
85-
startAdornment: country ? (
86-
<InputAdornment position="start">
87-
<Typography color="textPrimary" style={{ fontSize: '16px' }}>
88-
+{getCountryCallingCode(country)}
89-
</Typography>
90-
</InputAdornment>
91-
) : undefined,
92-
}}
9380
/>
9481
);
9582
});

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationSteps/__tests__/PhoneNumberStep.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,23 @@ describe('PhoneNumberStep', () => {
145145
phoneInput.querySelector('[data-testid="tel-input"] input'),
146146
).toHaveValue('');
147147
});
148+
149+
test('should not display duplicate country code in phone input field', () => {
150+
const usPhoneNumber = parsePhoneNumber('+17373072270', 'US');
151+
render(
152+
<PhoneNumberStep
153+
phoneNumber={usPhoneNumber.number}
154+
setPhoneNumber={mockSetPhoneNumber}
155+
handleClose={mockHandleClose}
156+
handlePhoneNumberSubmit={mockHandlePhoneNumberSubmit}
157+
setCountry={mockSetCountry}
158+
country="US"
159+
/>,
160+
);
161+
162+
const phoneInput = screen.getByTestId('tel-input');
163+
const inputElement = phoneInput.querySelector('input');
164+
const inputValue = inputElement?.value || '';
165+
expect(inputValue).toBe('+1 737 307 2270');
166+
});
148167
});

0 commit comments

Comments
 (0)