Skip to content

Commit

Permalink
Merge pull request #37047 from Expensify/georgia-private-personal-det…
Browse files Browse the repository at this point in the history
…ails

Remove unnecessary calls to OpenPrivatePersonalDetailsPage
  • Loading branch information
grgia authored Apr 9, 2024
2 parents 048e655 + bfd8fb9 commit 8a64b29
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 111 deletions.
2 changes: 0 additions & 2 deletions src/components/CardPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import ExpensifyCardImage from '@assets/images/expensify-card.svg';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -22,7 +21,6 @@ type CardPreviewProps = CardPreviewOnyxProps;

function CardPreview({privatePersonalDetails, session}: CardPreviewProps) {
const styles = useThemeStyles();
usePrivatePersonalDetails();
const {legalFirstName, legalLastName} = privatePersonalDetails ?? {};
const cardHolder = legalFirstName && legalLastName ? `${legalFirstName} ${legalLastName}` : session?.email ?? '';

Expand Down
20 changes: 0 additions & 20 deletions src/hooks/usePrivatePersonalDetails.ts

This file was deleted.

54 changes: 1 addition & 53 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {DateOfBirthForm} from '@src/types/form';
import type {PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx';
import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import * as Session from './Session';

Expand All @@ -43,12 +43,6 @@ Onyx.connect({
callback: (val) => (allPersonalDetails = val),
});

let privatePersonalDetails: OnyxEntry<PrivatePersonalDetails> = null;
Onyx.connect({
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
callback: (val) => (privatePersonalDetails = val),
});

function updatePronouns(pronouns: string) {
if (currentUserAccountID) {
const parameters: UpdatePronounsParams = {pronouns};
Expand Down Expand Up @@ -240,43 +234,6 @@ function updateSelectedTimezone(selectedTimezone: SelectedTimezone) {
Navigation.goBack(ROUTES.SETTINGS_TIMEZONE);
}

/**
* Fetches additional personal data like legal name, date of birth, address
*/
function openPersonalDetails() {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: true,
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: false,
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: false,
},
},
];

API.read(READ_COMMANDS.OPEN_PERSONAL_DETAILS, {}, {optimisticData, successData, failureData});
}

/**
* Fetches public profile info about a given user.
* The API will only return the accountID, displayName, and avatar for the user
Expand Down Expand Up @@ -446,18 +403,9 @@ function clearAvatarErrors() {
});
}

/**
* Get private personal details value
*/
function getPrivatePersonalDetails(): OnyxEntry<PrivatePersonalDetails> {
return privatePersonalDetails;
}

export {
clearAvatarErrors,
deleteAvatar,
getPrivatePersonalDetails,
openPersonalDetails,
openPublicProfilePage,
updateAddress,
updateAutomaticTimezone,
Expand Down
12 changes: 7 additions & 5 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useGeographicalStateFromRoute from '@hooks/useGeographicalStateFromRoute';
import useLocalize from '@hooks/useLocalize';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -24,6 +23,8 @@ import type {Address} from '@src/types/onyx/PrivatePersonalDetails';
type AddressPageOnyxProps = {
/** User's private personal details */
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;
/** Whether app is loading */
isLoadingApp: OnyxEntry<boolean>;
};

type AddressPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.ADDRESS> & AddressPageOnyxProps;
Expand All @@ -43,9 +44,8 @@ function updateAddress(values: FormOnyxValues<typeof ONYXKEYS.FORMS.HOME_ADDRESS
);
}

function AddressPage({privatePersonalDetails, route}: AddressPageProps) {
function AddressPage({privatePersonalDetails, route, isLoadingApp = true}: AddressPageProps) {
const styles = useThemeStyles();
usePrivatePersonalDetails();
const {translate} = useLocalize();
const address = useMemo(() => privatePersonalDetails?.address, [privatePersonalDetails]);
const countryFromUrlTemp = route?.params?.country;
Expand All @@ -54,7 +54,6 @@ function AddressPage({privatePersonalDetails, route}: AddressPageProps) {
const countryFromUrl = CONST.ALL_COUNTRIES[countryFromUrlTemp as keyof typeof CONST.ALL_COUNTRIES] ? countryFromUrlTemp : '';
const stateFromUrl = useGeographicalStateFromRoute();
const [currentCountry, setCurrentCountry] = useState(address?.country);
const isLoadingPersonalDetails = privatePersonalDetails?.isLoading ?? true;
const [street1, street2] = (address?.street ?? '').split('\n');
const [state, setState] = useState(address?.state);
const [city, setCity] = useState(address?.city);
Expand Down Expand Up @@ -122,7 +121,7 @@ function AddressPage({privatePersonalDetails, route}: AddressPageProps) {
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
/>
{isLoadingPersonalDetails ? (
{isLoadingApp ? (
<FullscreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
) : (
<AddressForm
Expand All @@ -148,4 +147,7 @@ export default withOnyx<AddressPageProps, AddressPageOnyxProps>({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(AddressPage);
12 changes: 7 additions & 5 deletions src/pages/settings/Profile/PersonalDetails/DateOfBirthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
Expand All @@ -23,14 +22,14 @@ import type {PrivatePersonalDetails} from '@src/types/onyx';
type DateOfBirthPageOnyxProps = {
/** User's private personal details */
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;
/** Whether app is loading */
isLoadingApp: OnyxEntry<boolean>;
};
type DateOfBirthPageProps = DateOfBirthPageOnyxProps;

function DateOfBirthPage({privatePersonalDetails}: DateOfBirthPageProps) {
function DateOfBirthPage({privatePersonalDetails, isLoadingApp = true}: DateOfBirthPageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
usePrivatePersonalDetails();
const isLoadingPersonalDetails = privatePersonalDetails?.isLoading ?? true;

/**
* @returns An object containing the errors for each inputID
Expand Down Expand Up @@ -59,7 +58,7 @@ function DateOfBirthPage({privatePersonalDetails}: DateOfBirthPageProps) {
title={translate('common.dob')}
onBackButtonPress={() => Navigation.goBack()}
/>
{isLoadingPersonalDetails ? (
{isLoadingApp ? (
<FullscreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
) : (
<FormProvider
Expand Down Expand Up @@ -90,4 +89,7 @@ export default withOnyx<DateOfBirthPageProps, DateOfBirthPageOnyxProps>({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(DateOfBirthPage);
12 changes: 7 additions & 5 deletions src/pages/settings/Profile/PersonalDetails/LegalNamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -25,6 +24,8 @@ import type {Errors} from '@src/types/onyx/OnyxCommon';
type LegalNamePageOnyxProps = {
/** User's private personal details */
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;
/** Whether app is loading */
isLoadingApp: OnyxEntry<boolean>;
};

type LegalNamePageProps = LegalNamePageOnyxProps;
Expand All @@ -33,13 +34,11 @@ const updateLegalName = (values: PrivatePersonalDetails) => {
PersonalDetails.updateLegalName(values.legalFirstName?.trim() ?? '', values.legalLastName?.trim() ?? '');
};

function LegalNamePage({privatePersonalDetails}: LegalNamePageProps) {
function LegalNamePage({privatePersonalDetails, isLoadingApp = true}: LegalNamePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
usePrivatePersonalDetails();
const legalFirstName = privatePersonalDetails?.legalFirstName ?? '';
const legalLastName = privatePersonalDetails?.legalLastName ?? '';
const isLoadingPersonalDetails = privatePersonalDetails?.isLoading ?? true;

const validate = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.LEGAL_NAME_FORM>) => {
const errors: Errors = {};
Expand Down Expand Up @@ -86,7 +85,7 @@ function LegalNamePage({privatePersonalDetails}: LegalNamePageProps) {
title={translate('privatePersonalDetails.legalName')}
onBackButtonPress={() => Navigation.goBack()}
/>
{isLoadingPersonalDetails ? (
{isLoadingApp ? (
<FullscreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
) : (
<FormProvider
Expand Down Expand Up @@ -133,4 +132,7 @@ export default withOnyx<LegalNamePageProps, LegalNamePageOnyxProps>({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(LegalNamePage);
11 changes: 7 additions & 4 deletions src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Section from '@components/Section';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -33,6 +32,8 @@ type ProfilePageOnyxProps = {
loginList: OnyxEntry<LoginList>;
/** User's private personal details */
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;
/** Whether app is loading */
isLoadingApp: OnyxEntry<boolean>;
};

type ProfilePageProps = ProfilePageOnyxProps & WithCurrentUserPersonalDetailsProps;
Expand All @@ -53,6 +54,7 @@ function ProfilePage({
},
},
currentUserPersonalDetails,
isLoadingApp,
}: ProfilePageProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -67,10 +69,8 @@ function ProfilePage({

const contactMethodBrickRoadIndicator = UserUtils.getLoginListBrickRoadIndicator(loginList);
const emojiCode = currentUserPersonalDetails?.status?.emojiCode ?? '';
usePrivatePersonalDetails();
const privateDetails = privatePersonalDetails ?? {};
const legalName = `${privateDetails.legalFirstName ?? ''} ${privateDetails.legalLastName ?? ''}`.trim();
const isLoadingPersonalDetails = privatePersonalDetails?.isLoading ?? true;

const publicOptions = [
{
Expand Down Expand Up @@ -167,7 +167,7 @@ function ProfilePage({
childrenStyles={styles.pt3}
titleStyles={styles.accountSettingsSectionTitle}
>
{isLoadingPersonalDetails ? (
{isLoadingApp ? (
<FullScreenLoadingIndicator style={[styles.flex1, styles.pRelative, StyleUtils.getBackgroundColorStyle(theme.cardBG)]} />
) : (
<>
Expand Down Expand Up @@ -202,5 +202,8 @@ export default withCurrentUserPersonalDetails(
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(ProfilePage),
);
2 changes: 0 additions & 2 deletions src/pages/settings/Wallet/ReportCardLostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SingleOptionSelector from '@components/SingleOptionSelector';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CardUtils from '@libs/CardUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -82,7 +81,6 @@ function ReportCardLostPage({
formData,
}: ReportCardLostPageProps) {
const styles = useThemeStyles();
usePrivatePersonalDetails();

const domainCards = CardUtils.getDomainCards(cardList ?? {})[domain];
const physicalCard = CardUtils.findPhysicalCard(domainCards);
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Wallet/WalletPage/CardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import PressableWithDelayToggle from '@components/Pressable/PressableWithDelayToggle';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import usePrivatePersonalDetails from '@hooks/usePrivatePersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import Clipboard from '@libs/Clipboard';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -47,7 +46,6 @@ type CardDetailsProps = CardDetailsOnyxProps & {

function CardDetails({pan = '', expiration = '', cvv = '', privatePersonalDetails, domain}: CardDetailsProps) {
const styles = useThemeStyles();
usePrivatePersonalDetails();
const {translate} = useLocalize();

const handleCopyToClipboard = () => {
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/PrivatePersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ type PrivatePersonalDetails = {

/** User's home address */
address?: Address;

/** Whether we are loading the data via the API */
isLoading?: boolean;
};

export default PrivatePersonalDetails;
Expand Down
Loading

0 comments on commit 8a64b29

Please sign in to comment.