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

Show errors after workspace creation failure #12117

Merged
merged 10 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 10 additions & 5 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,15 @@ function clearDeleteWorkspaceError(policyID) {
});
}

/**
* Removes the workspace after failure to create.
*
* @param {String} policyID
*/
function removeWorkspace(policyID) {
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, null);
}

/**
* Generate a policy name based on an email and policy list.
* @param {String} [email] the email to base the workspace name on. If not passed, will use the logged in user's email instead
Expand Down Expand Up @@ -842,11 +851,6 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false) {
},
}],
failureData: [{
onyxMethod: CONST.ONYX.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: null,
},
{
onyxMethod: CONST.ONYX.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policyID}`,
value: null,
Expand Down Expand Up @@ -949,4 +953,5 @@ export {
createWorkspace,
openWorkspaceMembersPage,
openWorkspaceInvitePage,
removeWorkspace,
};
5 changes: 5 additions & 0 deletions src/pages/settings/InitialSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ function dismissWorkspaceError(policyID, pendingAction) {
Policy.clearDeleteWorkspaceError(policyID);
return;
}

if (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
Policy.removeWorkspace(policyID);
return;
}
throw new Error('Not implemented');
}

Expand Down
25 changes: 24 additions & 1 deletion src/pages/workspace/WorkspaceInitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class WorkspaceInitialPage extends React.Component {
this.openEditor = this.openEditor.bind(this);
this.toggleDeleteModal = this.toggleDeleteModal.bind(this);
this.confirmDeleteAndHideModal = this.confirmDeleteAndHideModal.bind(this);
this.disabled = this.disabled.bind(this);
this.dismissError = this.dismissError.bind(this);

this.state = {
isDeleteModalOpen: false,
Expand Down Expand Up @@ -80,6 +82,18 @@ class WorkspaceInitialPage extends React.Component {
Navigation.navigate(ROUTES.SETTINGS);
}

/**
* @returns {Boolean}
*/
disabled() {
Justicea83 marked this conversation as resolved.
Show resolved Hide resolved
return Boolean(this.props.policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && this.props.policy.errors);
Copy link
Contributor

Choose a reason for hiding this comment

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

The above logic caused issue:

because optimistic / success data is setting requiresCategory to null, therefore policy.errors will always be true.

App/src/libs/actions/Policy.ts

Lines 3571 to 3599 in 942c851

optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
requiresCategory,
errors: {
requiresCategory: null,
},
pendingFields: {
requiresCategory: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errors: {
requiresCategory: null,
},
pendingFields: {
requiresCategory: null,
},
},
},
],

The proposed and implemented solution to fix this was to check !isEmptyObject(policy.errors) instead.

}

dismissError() {
Navigation.navigate(ROUTES.SETTINGS);
Policy.removeWorkspace(this.props.policy.id);
}

render() {
const policy = this.props.policy;
const hasMembersError = PolicyUtils.hasPolicyMemberError(this.props.policyMemberList);
Expand Down Expand Up @@ -163,11 +177,17 @@ class WorkspaceInitialPage extends React.Component {
styles.justifyContentBetween,
]}
>
<OfflineWithFeedback pendingAction={this.props.policy.pendingAction}>
<OfflineWithFeedback
pendingAction={this.props.policy.pendingAction}
onClose={() => this.dismissError()}
Justicea83 marked this conversation as resolved.
Show resolved Hide resolved
errors={this.props.policy.errors}
errorRowStyles={[styles.ph6, styles.pv2]}
>
<View style={[styles.flex1]}>
<View style={styles.pageWrapper}>
<View style={[styles.settingsPageBody, styles.alignItemsCenter]}>
<Pressable
disabled={this.disabled()}
style={[styles.pRelative, styles.avatarLarge]}
onPress={this.openEditor}
>
Expand All @@ -192,6 +212,7 @@ class WorkspaceInitialPage extends React.Component {
</Pressable>
{!_.isEmpty(this.props.policy.name) && (
<Pressable
disabled={this.disabled()}
style={[
styles.alignSelfCenter,
styles.mt4,
Expand All @@ -218,6 +239,8 @@ class WorkspaceInitialPage extends React.Component {
{_.map(menuItems, item => (
<MenuItem
key={item.translationKey}
disabled={this.disabled()}
interactive={!this.disabled()}
title={this.props.translate(item.translationKey)}
icon={item.icon}
iconRight={item.iconRight}
Expand Down