Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ Onyx.connect({
initWithStoredValues: false,
});

let myPersonalDetails;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
if (!val || !currentUserAccountID) {
return;
}

myPersonalDetails = val[currentUserAccountID];
},
});

let allPolicies = [];
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
Expand Down Expand Up @@ -267,8 +255,8 @@ function setUpPoliciesAndNavigate(session) {
}
}

function openProfile() {
const oldTimezoneData = myPersonalDetails.timezone || {};
function openProfile(personalDetails) {
const oldTimezoneData = personalDetails.timezone || {};
let newTimezoneData = oldTimezoneData;

if (lodashGet(oldTimezoneData, 'automatic', true)) {
Expand Down Expand Up @@ -308,8 +296,6 @@ function openProfile() {
],
},
);

Navigation.navigate(ROUTES.SETTINGS_PROFILE);
}

export {setLocale, setLocaleAndNavigate, setSidebarLoaded, setUpPoliciesAndNavigate, openProfile, openApp, reconnectApp, confirmReadyToOpenApp};
3 changes: 1 addition & 2 deletions src/pages/settings/InitialSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
import compose from '../../libs/compose';
import CONST from '../../CONST';
import Permissions from '../../libs/Permissions';
import * as App from '../../libs/actions/App';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
import * as PaymentMethods from '../../libs/actions/PaymentMethods';
import bankAccountPropTypes from '../../components/bankAccountPropTypes';
Expand Down Expand Up @@ -200,7 +199,7 @@ class InitialSettingsPage extends React.Component {
translationKey: 'common.profile',
icon: Expensicons.Profile,
action: () => {
App.openProfile();
Navigation.navigate(ROUTES.SETTINGS_PROFILE);
},
brickRoadIndicator: profileBrickRoadIndicator,
},
Expand Down
7 changes: 6 additions & 1 deletion src/pages/settings/Profile/ProfilePage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodashGet from 'lodash/get';
import React from 'react';
import React, {useEffect} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -23,6 +23,7 @@ import * as Expensicons from '../../../components/Icon/Expensicons';
import ONYXKEYS from '../../../ONYXKEYS';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import userPropTypes from '../userPropTypes';
import * as App from '../../../libs/actions/App';

const propTypes = {
/* Onyx Props */
Expand Down Expand Up @@ -84,6 +85,10 @@ function ProfilePage(props) {
},
];

useEffect(() => {
App.openProfile(props.currentUserPersonalDetails);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to call openProfile any time props.currentUserPersonalDetails changes? 🤔 I assumed we'd only want to call the function the first time we open the profile page - similar to the old componentDidMount

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an issue where myPersonalDetails was not initialized yet when calling openProfile so I thought maybe it would be better to just pass it in 🤔

But I guess I can return early in openProfile if myPersonalDetails are not there yet? What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can add earlier return - that if you do not have myPersonalDetails you should not openProfile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but then we have a problem where we call openProfile before our personal details are loaded ...and we never call it again 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, was ooo friday :D

Oof so I guess if we do the early return (if props. currentUserPersonalDetails doesn't exist, return) then we'll have to keep props.currentUserPersonalDetails as a dependency, right? I guess I'm ok with that, the current user probably won't be updating their personal details on a different device while they have this page open

}, [props.currentUserPersonalDetails]);

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<HeaderWithBackButton
Expand Down