Skip to content

Commit

Permalink
create setWorkspaceMemberErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jan 17, 2023
1 parent d31d4be commit 689a4bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ function setWorkspaceErrors(policyID, errors) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errors});
}

/**
* @param {String} policyID
* @param {String} member
* @param {Object} errors
*/
function setWorkspaceMemberErrors(policyID, member, errors) {
if (!allPolicies[policyID]) {
return;
}

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

/**
* @param {String} policyID
* @param {String} customUnitID
Expand Down Expand Up @@ -994,4 +1007,5 @@ export {
openWorkspaceMembersPage,
openWorkspaceInvitePage,
removeWorkspace,
setWorkspaceMemberErrors,
};
17 changes: 10 additions & 7 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class WorkspaceMembersPage extends React.Component {
* Remove selected users from the workspace
*/
removeUsers() {
this.validate();
Policy.removeMembers(this.state.selectedEmployees, this.props.route.params.policyID);
this.setState({
selectedEmployees: [],
Expand Down Expand Up @@ -196,6 +197,15 @@ class WorkspaceMembersPage extends React.Component {
}
}

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

/**
* Do not move this or make it an anonymous function it is a method
* so it will not be recreated each time we render an item
Expand Down Expand Up @@ -250,13 +260,6 @@ class WorkspaceMembersPage extends React.Component {
);
}

validate() {
_.each(this.state.selectedEmployees, member => {
if (member)
});
// this.props.policy.owner !== item.login && this.props.session.email !== item.login && item.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

render() {
const policyMemberList = lodashGet(this.props, 'policyMemberList', {});
let data = [];
Expand Down

0 comments on commit 689a4bc

Please sign in to comment.