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
Changes from 1 commit
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
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