Skip to content

Studio: The "Add site" action doesn't work if there is no site - #570

Merged
katinthehatsite merged 3 commits into
trunkfrom
fix/add-site-button-on-onboarding
Oct 2, 2024
Merged

Studio: The "Add site" action doesn't work if there is no site#570
katinthehatsite merged 3 commits into
trunkfrom
fix/add-site-button-on-onboarding

Conversation

@katinthehatsite

@katinthehatsite katinthehatsite commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

Closes #377

Proposed Changes

This PR does the following:

  • when the user has no sites, is on onboarding screen and they click on File > Add site in the topbar menu, the menu option is disabled
  • when the user has some sites and they click on File > Add site in the topbar menu, that menu option is enabled ,and they can open the modal for adding a site

It addresses the current issue when the File > Add site looks enabled when the user has no sites and is on onboarding screen but clicking on it does nothing.

Testing Instructions

  • Pull the changes from this branch
  • Start the app with nvm use && npm install && npm start
  • Delete all sites and ensure that you see the onboarding screen
  • Click on File > Add site option in the topbar menu
  • Observe that that menu is disabled
  • Create a site through onboarding screen so that you have at least one site
  • Click on File > Add site option in the topbar menu
  • Observe that Add site menu item is enabled
  • Confirm that you can click it and it opens the modal to add a new site

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@katinthehatsite katinthehatsite self-assigned this Sep 27, 2024
@katinthehatsite
katinthehatsite requested a review from a team September 27, 2024 19:27
Comment on lines +42 to +43
// App menu is reloaded to ensure the items show the translated strings.
getIpcApi().setupAppMenu( { needsOnboarding } );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't expect that refreshing the app menu requires passing the entire config parameters, like needsOnboarding. That said, I wonder if we could create a React context to manage the app menu from a global perspective instead.

The provider will use the hook useOnboarding to retrieve needsOnboarding, and set a side effect to update that app menu as we do in:

useEffect( () => {
getIpcApi().setupAppMenu( { needsOnboarding } );
}, [ needsOnboarding ] );

Additionally, the provider will expose a function to refresh the app menu that will be consumed here. We could also expose other functions in the future to make updates in the app bar in a reactive way.

With the above approach, we'll unlock updating the app menu from anywhere on the app. WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe another alternative would be reading the number of sites directly on IPC?

Something like (I didn't try the code):

export async function setupAppMenu( _event: IpcMainInvokeEvent ) {
	const userData = await loadUserData();
	const needsOnboarding = userData.sites.length === 0;
	setupMenu( { needsOnboarding } );
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since we need to manipulate just one menu item for now, I am going to merge this as this will have an immediate positive effect on the user experience. Let's open a separate issue to create a React context and make this more adaptable for future implementations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created the issue related to this here: https://github.com/Automattic/dotcom-forge/issues/9313

Comment thread src/components/onboarding.tsx

@wojtekn wojtekn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feature-wise works as expected, thanks!

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works as expected. I see the add site menu item is disabled for onboarding, and enabled when we have one site or more.
Changing the language respects the correct state.

Screenshot 2024-10-01 at 15 36 34
Comment on lines +42 to +43
// App menu is reloaded to ensure the items show the translated strings.
getIpcApi().setupAppMenu( { needsOnboarding } );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe another alternative would be reading the number of sites directly on IPC?

Something like (I didn't try the code):

export async function setupAppMenu( _event: IpcMainInvokeEvent ) {
	const userData = await loadUserData();
	const needsOnboarding = userData.sites.length === 0;
	setupMenu( { needsOnboarding } );
}
@katinthehatsite

Copy link
Copy Markdown
Contributor Author

Thanks @sejas - that is what I was planning to do initially (meaning reading the amount of sites) but I found that it works similarly 👍

@katinthehatsite
katinthehatsite merged commit aa03651 into trunk Oct 2, 2024
@katinthehatsite
katinthehatsite deleted the fix/add-site-button-on-onboarding branch October 2, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants