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 21 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
29 changes: 11 additions & 18 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 personalDetailsPropType from '../pages/personalDetailsPropType';
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB - should be plural since there's more than one prop type in this file - though this isn't your fault since you didn't create the original file :D

Suggested change
import personalDetailsPropType from '../pages/personalDetailsPropType';
import personalDetailsPropTypes from '../pages/personalDetailsPropTypes';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Updating.


const propTypes = {
/** Callback to inform parent modal of success */
Expand Down Expand Up @@ -65,18 +66,8 @@ const propTypes = {

/* 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,

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

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

Expand All @@ -125,6 +116,8 @@ class IOUConfirmationList extends Component {
value: props.hasMultipleParticipants ? CONST.IOU.IOU_TYPE.SPLIT : CONST.IOU.IOU_TYPE.REQUEST,
}];

this.myPersonalDetails = _.findWhere(props.personalDetails, {isCurrentUser: true});
puneetlath marked this conversation as resolved.
Show resolved Hide resolved

this.state = {
participants: formattedParticipants,
};
Expand Down Expand Up @@ -190,7 +183,7 @@ class IOUConfirmationList extends Component {
const formattedParticipants = _.union(formattedSelectedParticipants, formattedUnselectedParticipants);

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

splits.push({
email: OptionsListUtils.addSMSDomainIfPhoneNumber(this.props.myPersonalDetails.login),
email: OptionsListUtils.addSMSDomainIfPhoneNumber(this.myPersonalDetails.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 +259,7 @@ class IOUConfirmationList extends Component {
const selectedParticipants = this.getSelectedParticipants();
return [
...selectedParticipants,
OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(this.props.myPersonalDetails),
OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(this.myPersonalDetails),
];
}

Expand Down Expand Up @@ -398,8 +391,8 @@ export default compose(
withNetwork(),
withOnyx({
iou: {key: ONYXKEYS.IOU},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import * as CurrentDate from './actions/CurrentDate';

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);
const currentUser = _.findWhere(val, {isCurrentUser: true});
timezone = lodashGet(currentUser, 'timezone', CONST.DEFAULT_TIME_ZONE);
},
});

Expand Down
5 changes: 3 additions & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ import networkPropTypes from '../../../components/networkPropTypes';
import {withNetwork} from '../../../components/OnyxProvider';

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

const timezone = lodashGet(val, 'timezone', {});
const currentUser = _.findWhere(val, {isCurrentUser: true});
const timezone = lodashGet(currentUser, '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
18 changes: 4 additions & 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 @@ -135,16 +133,10 @@ 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);
// Flag which details belong to the currently logged in user for easy access before storing
allPersonalDetails[currentUserEmail].isCurrentUser = true;
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, allPersonalDetails);
});
}

Expand Down Expand Up @@ -262,8 +254,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 +315,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 @@ -51,8 +51,8 @@ Onyx.connect({

let myPersonalDetails;
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
callback: val => myPersonalDetails = val,
key: ONYXKEYS.PERSONAL_DETAILS,
callback: val => myPersonalDetails = _.findWhere(val, {isCurrentUser: true}),
});

const allReports = {};
Expand Down
11 changes: 6 additions & 5 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ 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,
/** Personal details of all the users, including current user */
personalDetails: PropTypes.objectOf(personalDetailsPropType).isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -93,6 +93,7 @@ class AdditionalDetailsStep extends React.Component {
super(props);

this.activateWallet = this.activateWallet.bind(this);
this.myPersonalDetails = _.findWhere(props.personalDetails, {isCurrentUser: true});

this.requiredFields = [
'legalFirstName',
Expand Down Expand Up @@ -233,7 +234,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.myPersonalDetails);

return (
<ScreenWrapper>
Expand Down Expand Up @@ -370,8 +371,8 @@ export default compose(
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
initWithStoredValues: false,
},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
}),
)(AdditionalDetailsStep);
11 changes: 6 additions & 5 deletions src/pages/RequestCallPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import networkPropTypes from '../components/networkPropTypes';
const propTypes = {
...withLocalizePropTypes,

/** The personal details of the person who is logged in */
myPersonalDetails: personalDetailsPropType.isRequired,
/** Personal details of all the users */
Copy link
Contributor

Choose a reason for hiding this comment

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

In AdditionalDetailsStep.js you have this at the end of the same comment: , including current user

Probably should be consistent - I think it makes sense to keep , including current user in these comments

personalDetails: PropTypes.objectOf(personalDetailsPropType).isRequired,

/** Login list for the user that is signed in */
loginList: PropTypes.arrayOf(PropTypes.shape({
Expand Down Expand Up @@ -99,7 +99,8 @@ const defaultProps = {
class RequestCallPage extends Component {
constructor(props) {
super(props);
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(props.myPersonalDetails);
const myPersonalDetails = _.findWhere(props.personalDetails, {isCurrentUser: true});
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(myPersonalDetails);
this.state = {
firstName,
hasFirstNameError: false,
Expand Down Expand Up @@ -355,8 +356,8 @@ export default compose(
withLocalize,
withNetwork(),
withOnyx({
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
loginList: {
key: ONYXKEYS.LOGIN_LIST,
Expand Down
13 changes: 2 additions & 11 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ const propTypes = {
expiresAt: PropTypes.string,
}),

/** The personal details of the person who is logged in */
myPersonalDetails: PropTypes.shape({
/** Primary login of the user */
login: PropTypes.string,
}),

...windowDimensionsPropTypes,
...withLocalizePropTypes,
};
Expand All @@ -113,7 +107,6 @@ const defaultProps = {
reportActions: {},
blockedFromConcierge: {},
personalDetails: {},
myPersonalDetails: {},
};

class ReportActionCompose extends React.Component {
Expand All @@ -135,6 +128,7 @@ class ReportActionCompose extends React.Component {
this.setTextInputRef = this.setTextInputRef.bind(this);
this.getInputPlaceholder = this.getInputPlaceholder.bind(this);
this.getIOUOptions = this.getIOUOptions.bind(this);
this.myPersonalDetails = _.findWhere(props.personalDetails, {isCurrentUser: true});

this.state = {
isFocused: this.shouldFocusInputOnScreenFocus,
Expand Down Expand Up @@ -263,7 +257,7 @@ class ReportActionCompose extends React.Component {
* @returns {Array<object>}
*/
getIOUOptions(reportParticipants) {
const participants = _.filter(reportParticipants, email => this.props.myPersonalDetails.login !== email);
const participants = _.filter(reportParticipants, email => this.myPersonalDetails.login !== email);
const hasExcludedIOUEmails = lodashIntersection(reportParticipants, CONST.EXPENSIFY_EMAILS).length > 0;
const hasMultipleParticipants = participants.length > 1;
const iouOptions = [];
Expand Down Expand Up @@ -696,8 +690,5 @@ export default compose(
blockedFromConcierge: {
key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE,
},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
}),
)(ReportActionCompose);
24 changes: 8 additions & 16 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ const propTypes = {
/** List of users' personal details */
personalDetails: PropTypes.objectOf(participantPropTypes),

/** 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,
}),

/** Information about the network */
network: networkPropTypes.isRequired,

Expand All @@ -91,9 +82,6 @@ const defaultProps = {
reports: {},
reportsWithDraft: {},
personalDetails: {},
myPersonalDetails: {
avatar: ReportUtils.getDefaultAvatar(),
},
currentlyViewedReportID: '',
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
initialReportDataLoaded: false,
Expand Down Expand Up @@ -172,6 +160,13 @@ class SidebarLinks extends React.Component {

constructor(props) {
super(props);

// Get my details from the list of personal details and set default avatar if not already set
this.myPersonalDetails = _.findWhere(props.personalDetails, {isCurrentUser: true});
if (!_.has(this.myPersonalDetails, 'avatar') || _.isEmpty(this.myPersonalDetails.avatar)) {
this.myPersonalDetails.avatar = ReportUtils.getDefaultAvatar();
}

this.state = {
activeReport: {
reportID: props.currentlyViewedReportID,
Expand Down Expand Up @@ -287,7 +282,7 @@ class SidebarLinks extends React.Component {
onPress={this.props.onAvatarClick}
>
<AvatarWithIndicator
source={this.props.myPersonalDetails.avatar}
source={this.myPersonalDetails.avatar}
isActive={this.props.network && !this.props.network.isOffline}
isSyncing={this.props.network && !this.props.network.isOffline && this.props.isSyncingData}
tooltipText={this.props.translate('common.settings')}
Expand Down Expand Up @@ -333,9 +328,6 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
currentlyViewedReportID: {
key: ONYXKEYS.CURRENTLY_VIEWED_REPORTID,
},
Expand Down
Loading