Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using MY_PERSONAL_DETAILS and only use PERSONAL_DETAILS in Onyx #9560

Merged
merged 40 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1a05abf
Refactor AuthScreens.js to use PERSONAL_DETAILS instead of MY_PERSONA…
puneetlath Jun 24, 2022
8b67fd9
Flag wich details in the personalDetails object belong to the current…
puneetlath Jun 24, 2022
98092d7
Update AuthScreen.js to look for new isCurrentUser flag
puneetlath Jun 24, 2022
09fe20d
Update Report.js to use PERSONAL_DETAILS instead of MY_PERSONAL_DETAILS
puneetlath Jun 24, 2022
413872f
Replace semicolon that was supposed to be comma
puneetlath Jun 24, 2022
dc7170b
Refactor ReportActionCompose.js to use PERSONAL_DETAILS instead of MY…
puneetlath Jun 25, 2022
630e90e
Refactor RequestCallPage.js to use PERSONAL_DETAILS instead of MY_PER…
puneetlath Jun 25, 2022
c6a6d82
Refactor DateUtils.js to use PERSONAL_DETAILS instead of MY_PERSONAL_…
puneetlath Jun 25, 2022
9aa4772
Refactor EnablePayments.js to use PERSONAL_DETAILS instead of MY_PERS…
puneetlath Jun 26, 2022
a65ca25
Refactor IOUModal.js to use PERSONAL_DETAILS instead of MY_PERSONAL_D…
puneetlath Jun 26, 2022
c3ba3b0
Refactor IOUCurrencySelection.js to use PERSONAL_DETAILS instead of M…
puneetlath Jun 27, 2022
b1a1eb7
Refactor SidebarLinks.js to use PERSONAL_DETAILS instead of MY_PERSON…
puneetlath Jun 27, 2022
dc7a183
Refactor ProfilePage.js to use PERSONAL_DETAILS instead of MY_PERSONA…
puneetlath Jun 27, 2022
b035b1d
Remove no longer used currentUserPersonalDetailsPropsTypes
puneetlath Jun 27, 2022
5f9bf56
Refactor InitialSettingsPage.js to use PERSONAL_DETAILS instead of MY…
puneetlath Jun 27, 2022
b005095
Refactor IOUConfirmationList.js to use PERSONAL_DETAILS instead of MY…
puneetlath Jun 27, 2022
22e1150
No longer save to MY_PERSONAL_DETAILS key in fetchPersonalDetails method
puneetlath Jun 27, 2022
085ed98
Refactor PersonalDetails.js to use PERSONAL_DETAILS instead of MY_PER…
puneetlath Jun 27, 2022
380dbaf
Remove the MY_PERSONAL_DETAILS onyx key
puneetlath Jun 27, 2022
3d37ef3
Merge branch 'main' into puneet-personaldetails-refactor
puneetlath Jun 28, 2022
67e1fd5
Get rid of unnecessary personal details references from IOUCurrencySe…
puneetlath Jun 28, 2022
8aec239
Create HOC for withPersonalDetails
puneetlath Jul 11, 2022
31ab939
Add session prop and proptype to personal details HOC
puneetlath Jul 11, 2022
1def41d
rename withPersonalDetails to withCurrentUserPersonalDetails
puneetlath Jul 15, 2022
00bd238
update withCurrentUserPersonalDetails to pass single prop of current …
puneetlath Jul 15, 2022
afa27df
update RequestCallPage to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
6fc8e92
update ReportActionCompose to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
a6fbd64
update Report.js to use current user email instead of current user flag
puneetlath Jul 15, 2022
59168f3
update AdditionalDetailsStep to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
55568ac
update IOUModal to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
cd60eca
update InitialSettingsPage to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
83ae808
update SidebarLinks to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
92a6cbb
update IOUConfirmationList to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
e6bbd9c
update ProfilePage to use withCurrentUserPersonalDetails HOC
puneetlath Jul 15, 2022
c9e4421
update DateUtils to use current user email instead of current user flag
puneetlath Jul 15, 2022
6f371c0
use lodash get instead of new variable for current user
puneetlath Jul 15, 2022
58f74c8
update AuthScreens to use current user email instead of current user …
puneetlath Jul 15, 2022
ccb9d27
dont flag the current user details in personal details
puneetlath Jul 15, 2022
0deaba4
Add more values to personal details prop type
puneetlath Jul 15, 2022
972c310
Merge branch 'main' into puneet-personaldetails-refactor
puneetlath Jul 15, 2022
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
3 changes: 0 additions & 3 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export default {
// Keeps track if there is modal currently visible or not
MODAL: 'modal',

// Contains the personalDetails of the user as well as their timezone
MY_PERSONAL_DETAILS: 'myPersonalDetails',

// Has information about the network status (offline/online)
NETWORK: 'network',

Expand Down
28 changes: 8 additions & 20 deletions src/components/IOUConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SettlementButton from './SettlementButton';
import ROUTES from '../ROUTES';
import networkPropTypes from './networkPropTypes';
import {withNetwork} from './OnyxProvider';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from './withCurrentUserPersonalDetails';

const propTypes = {
/** Callback to inform parent modal of success */
Expand Down Expand Up @@ -63,20 +64,9 @@ const propTypes = {

...withLocalizePropTypes,

/* Onyx Props */

/** The personal details of the person who is logged in */
myPersonalDetails: PropTypes.shape({

/** Display name of the current user from their personal details */
displayName: PropTypes.string,

/** Avatar URL of the current user from their personal details */
avatar: PropTypes.string,
...withCurrentUserPersonalDetailsPropTypes,

/** Primary login of the user */
login: PropTypes.string,
}),
/* Onyx Props */

/** Holds data related to IOU view state, rather than the underlying IOU data. */
iou: PropTypes.shape({
Expand All @@ -103,8 +93,8 @@ const defaultProps = {
},
onUpdateComment: null,
comment: '',
myPersonalDetails: {},
iouType: CONST.IOU.IOU_TYPE.REQUEST,
...withCurrentUserPersonalDetailsDefaultProps,
};

class IOUConfirmationList extends Component {
Expand Down Expand Up @@ -190,7 +180,7 @@ class IOUConfirmationList extends Component {
const formattedParticipants = _.union(formattedSelectedParticipants, formattedUnselectedParticipants);

const formattedMyPersonalDetails = OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(
this.props.myPersonalDetails,
this.props.currentUserPersonalDetails,
this.props.numberFormat(this.calculateAmount(selectedParticipants, true) / 100, {
style: 'currency',
currency: this.props.iou.selectedCurrencyCode,
Expand Down Expand Up @@ -246,7 +236,7 @@ class IOUConfirmationList extends Component {
}));

splits.push({
email: OptionsListUtils.addSMSDomainIfPhoneNumber(this.props.myPersonalDetails.login),
email: OptionsListUtils.addSMSDomainIfPhoneNumber(this.props.currentUserPersonalDetails.login),

// The user is default and we should send in cents to API
// USD is temporary and there must be support for other currencies in the future
Expand All @@ -266,7 +256,7 @@ class IOUConfirmationList extends Component {
const selectedParticipants = this.getSelectedParticipants();
return [
...selectedParticipants,
OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(this.props.myPersonalDetails),
OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(this.props.currentUserPersonalDetails),
];
}

Expand Down Expand Up @@ -395,11 +385,9 @@ export default compose(
withLocalize,
withWindowDimensions,
withNetwork(),
withCurrentUserPersonalDetails,
withOnyx({
iou: {key: ONYXKEYS.IOU},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
},
Expand Down
72 changes: 72 additions & 0 deletions src/components/withCurrentUserPersonalDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import getComponentDisplayName from '../libs/getComponentDisplayName';
import ONYXKEYS from '../ONYXKEYS';
import personalDetailsPropType from '../pages/personalDetailsPropType';

const withCurrentUserPersonalDetailsPropTypes = {
currentUserPersonalDetails: personalDetailsPropType,
};

const withCurrentUserPersonalDetailsDefaultProps = {
currentUserPersonalDetails: {},
};

export default function (WrappedComponent) {
const WithCurrentUserPersonalDetails = (props) => {
const currentUserEmail = props.session.email;

return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={props.forwardedRef}
currentUserPersonalDetails={props.personalDetails[currentUserEmail]}
/>
);
};

WithCurrentUserPersonalDetails.displayName = `WithCurrentUserPersonalDetails(${getComponentDisplayName(WrappedComponent)})`;
WithCurrentUserPersonalDetails.propTypes = {
forwardedRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}),
]),

/** Personal details of all the users, including current user */
personalDetails: PropTypes.objectOf(personalDetailsPropType),

/** Session of the current user */
session: PropTypes.shape({
email: PropTypes.string,
}),
};

WithCurrentUserPersonalDetails.defaultProps = {
forwardedRef: undefined,
personalDetails: {},
session: {
email: '',
},
};

const withCurrentUserPersonalDetails = React.forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<WithCurrentUserPersonalDetails {...props} forwardedRef={ref} />
));

return withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
},
})(withCurrentUserPersonalDetails);
}

export {
withCurrentUserPersonalDetailsPropTypes,
withCurrentUserPersonalDetailsDefaultProps,
};
17 changes: 15 additions & 2 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ import * as Localize from './Localize';
import * as PersonalDetails from './actions/PersonalDetails';
import * as CurrentDate from './actions/CurrentDate';

let currentUserEmail;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
// When signed out, val is undefined
if (!val) {
return;
}

currentUserEmail = val.email;
},
});

let timezone = CONST.DEFAULT_TIME_ZONE;
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS,
callback: (val) => {
timezone = lodashGet(val, 'timezone', CONST.DEFAULT_TIME_ZONE);
timezone = lodashGet(val, currentUserEmail, 'timezone', CONST.DEFAULT_TIME_ZONE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this one :)

},
});

Expand Down
17 changes: 15 additions & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,27 @@ import LogOutPreviousUserPage from '../../../pages/LogOutPreviousUserPage';
import networkPropTypes from '../../../components/networkPropTypes';
import {withNetwork} from '../../../components/OnyxProvider';

let currentUserEmail;
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
key: ONYXKEYS.SESSION,
callback: (val) => {
// When signed out, val is undefined
if (!val) {
return;
}

const timezone = lodashGet(val, 'timezone', {});
currentUserEmail = val.email;
},
});

Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
callback: (val) => {
if (!val) {
return;
}

const timezone = lodashGet(val, currentUserEmail, 'timezone', {});
Copy link
Contributor

@marcaaron marcaaron Jul 16, 2022

Choose a reason for hiding this comment

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

NAB, it seems like there is a very remote chance that currentUserEmail won't have a value at this point. It depends entirely on the session.email data being set before the personalDetails and both would be set when the user logs in actually not 100% sure when they would be set.

The subscriptions here feel out of place though and should be probably be moved into PersonalDetails (but not necessary to do that now).

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this needed to be lodashGet(val, [currentUserEmail, 'timezone'], {});

const currentTimezone = moment.tz.guess(true);

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
Expand Down
15 changes: 1 addition & 14 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ function fetchPersonalDetails() {
returnValueList: 'personalDetailsList',
})
.then((data) => {
let myPersonalDetails = {};

// If personalDetailsList does not have the current user ensure we initialize their details with an empty
// object at least
const personalDetailsList = _.isEmpty(data.personalDetailsList) ? {} : data.personalDetailsList;
Expand All @@ -136,15 +134,6 @@ function fetchPersonalDetails() {

const allPersonalDetails = formatPersonalDetails(personalDetailsList);
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, allPersonalDetails);

myPersonalDetails = allPersonalDetails[currentUserEmail];

// Add the first and last name to the current user's MY_PERSONAL_DETAILS key
myPersonalDetails.firstName = lodashGet(data.personalDetailsList, [currentUserEmail, 'firstName'], '');
myPersonalDetails.lastName = lodashGet(data.personalDetailsList, [currentUserEmail, 'lastName'], '');

// Set my personal details so they can be easily accessed and subscribed to on their own key
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, myPersonalDetails);
});
}

Expand Down Expand Up @@ -262,8 +251,6 @@ function mergeLocalPersonalDetails(details) {
// displayName is a generated field so we'll use the firstName and lastName + login to update it.
mergedDetails.displayName = getDisplayName(currentUserEmail, mergedDetails);

// Update the associated Onyx keys
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, mergedDetails);
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[currentUserEmail]: mergedDetails});
}

Expand Down Expand Up @@ -325,7 +312,7 @@ function fetchLocalCurrency() {
})
.then(getCurrencyList)
.then(() => {
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {localCurrencyCode: currency});
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[currentUserEmail]: {localCurrencyCode: currency}});
})
.finally(() => {
Onyx.merge(ONYXKEYS.IOU, {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Onyx.connect({

let myPersonalDetails;
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
callback: val => myPersonalDetails = val,
key: ONYXKEYS.PERSONAL_DETAILS,
callback: val => myPersonalDetails = val[currentUserEmail],
});

const allReports = {};
Expand Down
13 changes: 5 additions & 8 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import AddressSearch from '../../components/AddressSearch';
import DatePicker from '../../components/DatePicker';
import FormHelper from '../../libs/FormHelper';
import walletAdditionalDetailsDraftPropTypes from './walletAdditionalDetailsDraftPropTypes';
import personalDetailsPropType from '../personalDetailsPropType';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
import * as PersonalDetails from '../../libs/actions/PersonalDetails';

const propTypes = {
...withLocalizePropTypes,
...withCurrentUserPersonalDetailsPropTypes,

/** Stores additional information about the additional details step e.g. loading state and errors with fields */
walletAdditionalDetails: PropTypes.shape({
Expand Down Expand Up @@ -61,9 +62,6 @@ const propTypes = {

/** Stores the personal details typed by the user */
walletAdditionalDetailsDraft: walletAdditionalDetailsDraftPropTypes,

/** The personal details of the person who is logged in */
myPersonalDetails: personalDetailsPropType.isRequired,
};

const defaultProps = {
Expand All @@ -86,6 +84,7 @@ const defaultProps = {
dob: '',
ssn: '',
},
...withCurrentUserPersonalDetailsDefaultProps,
};

class AdditionalDetailsStep extends React.Component {
Expand Down Expand Up @@ -275,7 +274,7 @@ class AdditionalDetailsStep extends React.Component {
const isErrorVisible = _.size(this.getErrors()) > 0
|| lodashGet(this.props, 'walletAdditionalDetails.additionalErrorMessage', '').length > 0;
const shouldAskForFullSSN = this.props.walletAdditionalDetails.shouldAskForFullSSN;
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.myPersonalDetails);
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.currentUserPersonalDetails);

return (
<ScreenWrapper>
Expand Down Expand Up @@ -407,13 +406,11 @@ AdditionalDetailsStep.propTypes = propTypes;
AdditionalDetailsStep.defaultProps = defaultProps;
export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withOnyx({
walletAdditionalDetails: {
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
initWithStoredValues: false,
},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
}),
)(AdditionalDetailsStep);
13 changes: 5 additions & 8 deletions src/pages/RequestCallPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Icon from '../components/Icon';
import CONST from '../CONST';
import Growl from '../libs/Growl';
import * as Inbox from '../libs/actions/Inbox';
import personalDetailsPropType from './personalDetailsPropType';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../components/withCurrentUserPersonalDetails';
import TextInput from '../components/TextInput';
import Text from '../components/Text';
import Section from '../components/Section';
Expand All @@ -38,9 +38,7 @@ import FormAlertWithSubmitButton from '../components/FormAlertWithSubmitButton';

const propTypes = {
...withLocalizePropTypes,

/** The personal details of the person who is logged in */
myPersonalDetails: personalDetailsPropType.isRequired,
...withCurrentUserPersonalDetailsPropTypes,

/** Login list for the user that is signed in */
loginList: PropTypes.arrayOf(PropTypes.shape({
Expand Down Expand Up @@ -101,12 +99,13 @@ const defaultProps = {
lastAccessedWorkspacePolicyID: '',
blockedFromConcierge: {},
loginList: [],
...withCurrentUserPersonalDetailsDefaultProps,
};

class RequestCallPage extends Component {
constructor(props) {
super(props);
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(props.myPersonalDetails);
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(props.currentUserPersonalDetails);
this.state = {
firstName,
hasFirstNameError: false,
Expand Down Expand Up @@ -377,10 +376,8 @@ RequestCallPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withNetwork(),
withCurrentUserPersonalDetails,
withOnyx({
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
loginList: {
key: ONYXKEYS.LOGIN_LIST,
},
Expand Down
Loading