Skip to content

Commit

Permalink
fix setWorkspaceMemberErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jan 17, 2023
1 parent 689a4bc commit a3a7337
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,14 @@ function setWorkspaceErrors(policyID, errors) {

/**
* @param {String} policyID
* @param {String} member
* @param {Object} errors
*/
function setWorkspaceMemberErrors(policyID, member, errors) {
if (!allPolicies[policyID]) {
function setWorkspaceMemberErrors(policyID, errors) {
if (!allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]) {
return;
}

Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policyID}`, {[member]: {errors}});
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policyID}`, errors);
}

/**
Expand Down
25 changes: 17 additions & 8 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {withNetwork} from '../../components/OnyxProvider';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import networkPropTypes from '../../components/networkPropTypes';
import * as Expensicons from '../../components/Icon/Expensicons';
import DateUtils from '../../libs/DateUtils';

const propTypes = {
/** The personal details of the person who is logged in */
Expand Down Expand Up @@ -108,11 +109,11 @@ class WorkspaceMembersPage extends React.Component {
*/
removeUsers() {
this.validate();
Policy.removeMembers(this.state.selectedEmployees, this.props.route.params.policyID);
this.setState({
selectedEmployees: [],
isRemoveMembersConfirmModalVisible: false,
});
// Policy.removeMembers(this.state.selectedEmployees, this.props.route.params.policyID);
// this.setState({
// selectedEmployees: [],
// isRemoveMembersConfirmModalVisible: false,
// });
}

/**
Expand Down Expand Up @@ -198,12 +199,20 @@ class WorkspaceMembersPage extends React.Component {
}

validate() {
const onyxUpdate = {};
_.each(this.state.selectedEmployees, (member) => {
if (member === this.props.policy.owner) {
const error = this.props.translate('workspace.people.error.cannotRemove');
setWorkspaceMemberError(member, error);
if (member !== this.props.policy.owner && member !== this.props.session.email) {
return;
}

onyxUpdate[member] = {
errors: {
[DateUtils.getMicroseconds()]: this.props.translate('workspace.people.error.cannotRemove')
},
};
});

Policy.setWorkspaceMemberErrors(this.props.route.params.policyID, onyxUpdate);
}

/**
Expand Down

0 comments on commit a3a7337

Please sign in to comment.