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

Personal details migration todos #20506

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
12 changes: 6 additions & 6 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
/**
* Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx,
* then a default object is constructed.
* @param {String} accountID
* @param {Number} accountID
* @returns {Object}
*/
function getPersonalDetailsForAccountID(accountID) {
Expand All @@ -862,7 +862,7 @@ function getPersonalDetailsForAccountID(accountID) {
/**
* Get the displayName for a single report participant.
*
* @param {String} accountID
* @param {Number} accountID
* @param {Boolean} [shouldUseShortForm]
* @returns {String}
*/
Expand All @@ -886,10 +886,10 @@ function getDisplayNameForParticipant(accountID, shouldUseShortForm = false) {
*/
function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) {
return _.map(participants, (participant) => {
const personalDetails = getPersonalDetailsForAccountID(participant.accountID);
const displayName = getDisplayNameForParticipant(participant.accountID, isMultipleParticipantReport);

// TODO: Maybe get login from personal details via participant accountID?
const tooltip = participant.login ? Str.removeSMSDomain(participant.login) : '';
const tooltip = personalDetails.login ? Str.removeSMSDomain(personalDetails.login) : '';

let pronouns = participant.pronouns;
if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) {
Expand Down Expand Up @@ -1215,8 +1215,8 @@ function buildOptimisticTaskCommentReportAction(taskReportID, taskTitle, taskAss
*/
function buildOptimisticIOUReport(payeeEmail, payeeAccountID, payerAccountID, total, chatReportID, currency, isSendingMoney = false) {
const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency);
// TODO: GET ME
const payerEmail = 'GET ME WITH PERSONAL DETAILS';
const personalDetails = getPersonalDetailsForAccountID(payerAccountID);
const payerEmail = personalDetails.login;
return {
// If we're sending money, hasOutstandingIOU should be false
hasOutstandingIOU: !isSendingMoney,
Expand Down
21 changes: 13 additions & 8 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Onyx.connect({
},
});

let personalDetails;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (personalDetails = val),
});

/**
* Stores in Onyx the policy ID of the last workspace that was accessed by the user
* @param {String|null} policyID
Expand Down Expand Up @@ -187,42 +193,41 @@ function hasActiveFreePolicy(policies) {
/**
* Remove the passed members from the policy employeeList
*
* @param {Array} members
* @param {Array} accountIDs
* @param {String} policyID
*/
function removeMembers(members, accountIDs, policyID) {
function removeMembers(accountIDs, policyID) {
// In case user selects only themselves (admin), their email will be filtered out and the members
// array passed will be empty, prevent the function from proceeding in that case as there is noone to remove
if (members.length === 0) {
// array passed will be empty, prevent the function from proceeding in that case as there is no one to remove
if (accountIDs.length === 0) {
return;
}
const membersListKey = `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`;
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: membersListKey,
value: _.object(accountIDs, Array(members.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})),
value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})),
},
];
const successData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: membersListKey,
value: _.object(accountIDs, Array(members.length).fill(null)),
value: _.object(accountIDs, Array(accountIDs.length).fill(null)),
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: membersListKey,
value: _.object(accountIDs, Array(members.length).fill({errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')})),
value: _.object(accountIDs, Array(accountIDs.length).fill({errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')})),
},
];
API.write(
'DeleteMembersFromWorkspace',
{
emailList: members.join(','),
emailList: _.map(accountIDs, (accountID) => personalDetails[accountID].login).join(','),
policyID,
},
{optimisticData, successData, failureData},
Expand Down
1 change: 0 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Log from '../Log';
import * as ReportUtils from '../ReportUtils';
import DateUtils from '../DateUtils';
import * as ReportActionsUtils from '../ReportActionsUtils';
import * as OptionsListUtils from '../OptionsListUtils';
import * as CollectionUtils from '../CollectionUtils';
import * as EmojiUtils from '../EmojiUtils';
import * as ErrorUtils from '../ErrorUtils';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const showUserDetails = (accountID) => {
};

const ReportActionItemSingle = (props) => {
const actorEmail = lodashGet(props.action, actorEmail, '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
const actorEmail = lodashGet(props.action, 'actorEmail', '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
const actorAccountID = props.action.actorAccountID;
const {avatar, displayName, pendingFields} = props.personalDetailsList[actorAccountID] || {};
const avatarSource = UserUtils.getAvatar(avatar, actorAccountID);
Expand Down
41 changes: 18 additions & 23 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,9 @@ class WorkspaceMembersPage extends React.Component {
}

// Remove the admin from the list
const membersToRemove = _.without(this.state.selectedEmployees, this.props.session.email);
const accountIDsToRemove = _.without(this.state.selectedEmployees, this.props.session.accountID);

// It's a pain, but we need to map the emails back to accountIDs now so we can set optimistic data. TODO removeMembers using accountIDs only.
const emailsToAccountIDs = PolicyUtils.getClientPolicyMemberEmailsToAccountIDs(this.props.policyMembers, this.props.personalDetails);
const accountIDsToRemove = _.map(membersToRemove, (email) => emailsToAccountIDs[email]);
Policy.removeMembers(membersToRemove, accountIDsToRemove, this.props.route.params.policyID);
Policy.removeMembers(accountIDsToRemove, this.props.route.params.policyID);
this.setState({
selectedEmployees: [],
isRemoveMembersConfirmModalVisible: false,
Expand Down Expand Up @@ -229,32 +226,32 @@ class WorkspaceMembersPage extends React.Component {
/**
* Toggle user from the selectedEmployees list
*
* @param {String} login
* @param {String} accountID
* @param {String} pendingAction
*
*/
toggleUser(login, pendingAction) {
toggleUser(accountID, pendingAction) {
if (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return;
}

// Add or remove the user if the checkbox is enabled
if (_.contains(this.state.selectedEmployees, login)) {
this.removeUser(login);
if (_.contains(this.state.selectedEmployees, accountID)) {
this.removeUser(accountID);
} else {
this.addUser(login);
this.addUser(accountID);
}
}

/**
* Add user from the selectedEmployees list
*
* @param {String} login
* @param {String} accountID
*/
addUser(login) {
addUser(accountID) {
this.setState(
(prevState) => ({
selectedEmployees: [...prevState.selectedEmployees, login],
selectedEmployees: [...prevState.selectedEmployees, accountID],
}),
() => this.validate(),
);
Expand All @@ -263,12 +260,12 @@ class WorkspaceMembersPage extends React.Component {
/**
* Remove user from the selectedEmployees list
*
* @param {String} login
* @param {String} accountID
*/
removeUser(login) {
removeUser(accountID) {
this.setState(
(prevState) => ({
selectedEmployees: _.without(prevState.selectedEmployees, login),
selectedEmployees: _.without(prevState.selectedEmployees, accountID),
}),
() => this.validate(),
);
Expand Down Expand Up @@ -322,7 +319,7 @@ class WorkspaceMembersPage extends React.Component {
* @returns {React.Component}
*/
renderItem({item}) {
const isChecked = _.contains(this.state.selectedEmployees, item.login);
const isChecked = _.contains(this.state.selectedEmployees, item.accountID);
return (
<OfflineWithFeedback
errorRowStyles={[styles.peopleRowBorderBottom]}
Expand All @@ -332,7 +329,7 @@ class WorkspaceMembersPage extends React.Component {
>
<PressableWithFeedback
style={[styles.peopleRow, (_.isEmpty(item.errors) || this.state.errors[item.login]) && styles.peopleRowBorderBottom]}
onPress={() => this.toggleUser(item.login, item.pendingAction)}
onPress={() => this.toggleUser(item.accountID, item.pendingAction)}
accessibilityRole="checkbox"
accessibilityState={{
checked: isChecked,
Expand All @@ -344,7 +341,7 @@ class WorkspaceMembersPage extends React.Component {
>
<Checkbox
isChecked={isChecked}
onPress={() => this.toggleUser(item.login, item.pendingAction)}
onPress={() => this.toggleUser(item.accountID, item.pendingAction)}
/>
<View style={styles.flex1}>
<OptionRow
Expand Down Expand Up @@ -414,7 +411,7 @@ class WorkspaceMembersPage extends React.Component {
if (member.login === this.props.session.email || member.login === this.props.policy.owner || member.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return;
}
removableMembers[member.login] = member;
removableMembers[member.accountID] = member;
});
const policyID = lodashGet(this.props.route, 'params.policyID');
const policyName = lodashGet(this.props.policy, 'name');
Expand Down Expand Up @@ -477,9 +474,7 @@ class WorkspaceMembersPage extends React.Component {
<View style={[styles.w100, styles.mt4, styles.flex1]}>
<View style={[styles.peopleRow, styles.ph5, styles.pb3]}>
<Checkbox
isChecked={
!_.isEmpty(removableMembers) && _.every(_.keys(removableMembers), (memberEmail) => _.contains(this.state.selectedEmployees, memberEmail))
}
isChecked={!_.isEmpty(removableMembers) && _.every(_.keys(removableMembers), (accountID) => _.contains(this.state.selectedEmployees, accountID))}
onPress={() => this.toggleAllUsers(removableMembers)}
/>
<View style={[styles.flex1]}>
Expand Down