Skip to content

Commit 49c943a

Browse files
author
Joshua Zhou
committed
Add validation for empty phone numbers
1 parent 3d5f5f7 commit 49c943a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/features/Account/ManageAccountForm.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,35 @@ const ManageAccountForm: React.FC<IManageAccountProps> = (props) => {
281281
name={'newPassword'}
282282
/>
283283
<ErrorMessage component={FormikElements.Error} name="newPassword" />
284+
</>
285+
)}
286+
287+
{props.mode === ManageAccountModes.CREATE && (
288+
<>
289+
<FastField
290+
component={FormikElements.PhoneNumberInput}
291+
label={CONSTANTS.PHONE_NUMBER_LABEL}
292+
name={"phoneNumber"}
293+
required={true}
294+
value={fp.values.phoneNumber}
295+
/>
296+
<ErrorMessage component={FormikElements.Error} name="phoneNumber" />
297+
</>
298+
)}
299+
300+
{props.mode === ManageAccountModes.EDIT && (
301+
<>
284302
<FastField
285303
component={FormikElements.FormattedNumber}
286304
label={CONSTANTS.PHONE_NUMBER_LABEL}
287-
placeholder="+# (###) ###-####"
288-
format="+# (###) ###-####"
289305
name={'phoneNumber'}
290306
required={true}
291307
value={fp.values.phoneNumber}
292308
/>
293309
<ErrorMessage component={FormikElements.Error} name="phoneNumber" />
294310
</>
295311
)}
312+
296313
<FastField
297314
component={FormikElements.Select}
298315
creatable={true}
@@ -374,4 +391,4 @@ const ManageAccountForm: React.FC<IManageAccountProps> = (props) => {
374391
);
375392
};
376393

377-
export default WithToasterContainer(ManageAccountForm);
394+
export default WithToasterContainer(ManageAccountForm);

src/features/Account/validationSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const getValidationSchema = (isCreate: boolean) => {
2222
'validPhone',
2323
'Must be a valid phone number',
2424
(value) => {
25+
if (!value) return false;
2526
const parsedValue = value?.replace(/\D/g, '');
2627
return !parsedValue || (parsedValue.length > 10 && parsedValue.length < 14);
2728
}

0 commit comments

Comments
 (0)