Skip to content

Commit

Permalink
Merge pull request #6280 from Santhosh-Sellavel/workspace_create_butt…
Browse files Browse the repository at this point in the history
…on_state_fix

Restricted workspace create button click while workspace is created.
  • Loading branch information
Julesssss authored Nov 16, 2021
2 parents c7e618c + 315a914 commit 0f2a11a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default {
// Boolean flag set whenever the sidebar has loaded
IS_SIDEBAR_LOADED: 'isSidebarLoaded',

// Boolean flag set when workspace is being created
IS_CREATING_WORKSPACE: 'isCreatingWorkspace',

NETWORK_REQUEST_QUEUE: 'networkRequestQueue',

// What the active route is for our navigator. Global route that determines what views to display.
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ function updateAllPolicies(policyCollection) {
* @returns {Promise}
*/
function create(name = '') {
Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, true);
let res = null;
return API.Policy_Create({type: CONST.POLICY.TYPE.FREE, policyName: name})
.then((response) => {
Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, false);
if (response.jsonCode !== 200) {
// Show the user feedback
const errorMessage = translateLocal('workspace.new.genericFailureMessage');
Expand Down
9 changes: 8 additions & 1 deletion src/pages/home/sidebar/SidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ const propTypes = {
/* Flag for new users used to open the Global Create menu on first load */
isFirstTimeNewExpensifyUser: PropTypes.bool,

/* Is workspace is being created by the user? */
isCreatingWorkspace: PropTypes.bool,

...windowDimensionsPropTypes,

...withLocalizePropTypes,
};
const defaultProps = {
isFirstTimeNewExpensifyUser: false,
isCreatingWorkspace: false,
};

class SidebarScreen extends Component {
Expand Down Expand Up @@ -185,7 +189,7 @@ class SidebarScreen extends Component {
onSelected: () => Navigation.navigate(ROUTES.IOU_BILL),
},
] : []),
...(Permissions.canUseFreePlan(this.props.betas) && !Policy.isAdminOfFreePolicy(this.props.allPolicies) ? [
...(!this.props.isCreatingWorkspace && Permissions.canUseFreePlan(this.props.betas) && !Policy.isAdminOfFreePolicy(this.props.allPolicies) ? [
{
icon: NewWorkspace,
iconWidth: 46,
Expand Down Expand Up @@ -221,5 +225,8 @@ export default compose(
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
},
isCreatingWorkspace: {
key: ONYXKEYS.IS_CREATING_WORKSPACE,
},
}),
)(SidebarScreen);

0 comments on commit 0f2a11a

Please sign in to comment.