Skip to content

Commit

Permalink
add BE error RBR and error field to phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
allgandalf committed Oct 21, 2024
1 parent 9446f6a commit 53d430a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ const translations = {
dateShouldBeAfter: ({dateString}: DateShouldBeAfterParams) => `Date should be after ${dateString}.`,
hasInvalidCharacter: 'Name can only include Latin characters.',
incorrectZipFormat: ({zipFormat}: IncorrectZipFormatParams = {}) => `Incorrect zip code format.${zipFormat ? ` Acceptable format: ${zipFormat}` : ''}`,
invalidPhoneNumber: `Please ensure the phone number is valid (e.g. ${CONST.EXAMPLE_PHONE_NUMBER}).`,
},
},
resendValidationForm: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ const translations = {
dateShouldBeAfter: ({dateString}: DateShouldBeAfterParams) => `La fecha debe ser posterior a ${dateString}.`,
incorrectZipFormat: ({zipFormat}: IncorrectZipFormatParams = {}) => `Formato de código postal incorrecto.${zipFormat ? ` Formato aceptable: ${zipFormat}` : ''}`,
hasInvalidCharacter: 'El nombre sólo puede incluir caracteres latinos.',
invalidPhoneNumber: 'Asegúrese de que el número de teléfono sean válidos (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER}).',
},
},
resendValidationForm: {

Check failure on line 1784 in src/languages/es.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected template string expression
Expand Down
24 changes: 23 additions & 1 deletion src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types';
import DateUtils from '@libs/DateUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as LoginUtils from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
Expand Down Expand Up @@ -158,7 +159,7 @@ function updateDateOfBirth({dob}: DateOfBirthForm) {
Navigation.goBack();
}

function updatePhoneNumber(phoneNumber: string) {
function updatePhoneNumber(phoneNumber: string, currenPhoneNumber: string) {
const parameters: UpdatePhoneNumberParams = {phoneNumber};
API.write(WRITE_COMMANDS.UPDATE_PHONE_NUMBER, parameters, {
optimisticData: [
Expand All @@ -170,6 +171,26 @@ function updatePhoneNumber(phoneNumber: string) {
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
phoneNumber: currenPhoneNumber,
errorFields: {
phoneNumber: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('privatePersonalDetails.error.invalidPhoneNumber'),
},
},
},
],
});
}

function clearPhoneNumberError() {
Onyx.merge(ONYXKEYS.PRIVATE_PERSONAL_DETAILS, {
errorFields: {
phoneNumber: null,
},
});
}

Expand Down Expand Up @@ -498,6 +519,7 @@ export {
updateDisplayName,
updateLegalName,
updatePhoneNumber,
clearPhoneNumberError,
updatePronouns,
updateSelectedTimezone,
updatePersonalDetailsAndShipExpensifyCard,
Expand Down
15 changes: 12 additions & 3 deletions src/pages/settings/Profile/PersonalDetails/PhoneNumberPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import ScreenWrapper from '@components/ScreenWrapper';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as LoginUtils from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as PhoneNumberUtils from '@libs/PhoneNumber';
Expand All @@ -28,8 +30,11 @@ function PhoneNumberPage() {
const {translate} = useLocalize();
const phoneNumber = privatePersonalDetails?.phoneNumber ?? '';

const validateLoginError = ErrorUtils.getEarliestErrorField(privatePersonalDetails, 'phoneNumber');
const currenPhoneNumber = privatePersonalDetails?.phoneNumber ?? '';

const updatePhoneNumber = (values: PrivatePersonalDetails) => {
PersonalDetails.updatePhoneNumber(values?.phoneNumber ?? '');
PersonalDetails.updatePhoneNumber(values?.phoneNumber ?? '', currenPhoneNumber);
Navigation.goBack();
};

Expand Down Expand Up @@ -70,7 +75,11 @@ function PhoneNumberPage() {
submitButtonText={translate('common.save')}
enabledWhenOffline
>
<View style={[styles.mb4]}>
<OfflineWithFeedback
errors={validateLoginError}
style={styles.mb4}
onClose={() => PersonalDetails.clearPhoneNumberError()}
>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.PHONE_NUMBER}
Expand All @@ -81,7 +90,7 @@ function PhoneNumberPage() {
defaultValue={phoneNumber}
spellCheck={false}
/>
</View>
</OfflineWithFeedback>
</FormProvider>
)}
</ScreenWrapper>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function ProfilePage() {
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);

const getPronouns = (): string => {
Expand Down Expand Up @@ -100,6 +99,7 @@ function ProfilePage() {
description: translate('common.phoneNumber'),
title: privateDetails.phoneNumber ?? '',
pageRoute: ROUTES.SETTINGS_PHONE_NUMBER,
brickRoadIndicator: privatePersonalDetails?.errorFields?.phoneNumber ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
},
{
description: translate('privatePersonalDetails.address'),
Expand Down Expand Up @@ -200,6 +200,7 @@ function ProfilePage() {
description={detail.description}
wrapperStyle={styles.sectionMenuItemTopDescription}
onPress={() => Navigation.navigate(detail.pageRoute)}
brickRoadIndicator={detail.brickRoadIndicator}
/>
))}
</>
Expand Down
4 changes: 4 additions & 0 deletions src/types/onyx/PrivatePersonalDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {Country} from '@src/CONST';
import type * as OnyxCommon from './OnyxCommon';

/** User address data */
type Address = {
Expand Down Expand Up @@ -64,6 +65,9 @@ type PrivatePersonalDetails = {

/** User's home address history. The most recent address is the last item in the array */
addresses?: Address[];

/** Error objects keyed by field name containing errors keyed by microtime */
errorFields?: OnyxCommon.ErrorFields;
};

export default PrivatePersonalDetails;
Expand Down

0 comments on commit 53d430a

Please sign in to comment.