@@ -8,12 +8,13 @@ import cx from 'classnames';
88import Icon from 'js/components/common/icon' ;
99import KoboDropdown from 'js/components/common/koboDropdown' ;
1010
11- // Stores
11+ // Stores and hooks
1212import projectViewsStore from './projectViewsStore' ;
13+ import { useOrganizationQuery } from 'js/account/stripe.api' ;
1314
1415// Constants
1516import { PROJECTS_ROUTES } from 'js/router/routerConstants' ;
16- import { HOME_VIEW } from './constants' ;
17+ import { HOME_VIEW , ORG_VIEW } from './constants' ;
1718
1819// Styles
1920import styles from './viewSwitcher.module.scss' ;
@@ -32,11 +33,14 @@ function ViewSwitcher(props: ViewSwitcherProps) {
3233 // We track the menu visibility for the trigger icon.
3334 const [ isMenuVisible , setIsMenuVisible ] = useState ( false ) ;
3435 const [ projectViews ] = useState ( ( ) => projectViewsStore ) ;
36+ const orgQuery = useOrganizationQuery ( ) ;
3537 const navigate = useNavigate ( ) ;
3638
3739 const onOptionClick = ( viewUid : string ) => {
3840 if ( viewUid === HOME_VIEW . uid || viewUid === null ) {
3941 navigate ( PROJECTS_ROUTES . MY_PROJECTS ) ;
42+ } else if ( viewUid === ORG_VIEW . uid ) {
43+ navigate ( PROJECTS_ROUTES . MY_ORG_PROJECTS ) ;
4044 } else {
4145 navigate ( PROJECTS_ROUTES . CUSTOM_VIEW . replace ( ':viewUid' , viewUid ) ) ;
4246 // The store keeps a number of assets of each view, and that number
@@ -45,8 +49,16 @@ function ViewSwitcher(props: ViewSwitcherProps) {
4549 }
4650 } ;
4751
52+ const hasMultipleOptions = (
53+ projectViews . views . length !== 0 ||
54+ orgQuery . data ?. is_mmo
55+ ) ;
56+ const organizationName = orgQuery . data ?. name || t ( 'Organization' ) ;
57+
4858 let triggerLabel = HOME_VIEW . name ;
49- if ( props . selectedViewUid !== HOME_VIEW . uid ) {
59+ if ( props . selectedViewUid === ORG_VIEW . uid ) {
60+ triggerLabel = ORG_VIEW . name . replace ( '##organization name##' , organizationName ) ;
61+ } else if ( props . selectedViewUid !== HOME_VIEW . uid ) {
5062 triggerLabel = projectViews . getView ( props . selectedViewUid ) ?. name || '-' ;
5163 }
5264
@@ -55,9 +67,9 @@ function ViewSwitcher(props: ViewSwitcherProps) {
5567 return null ;
5668 }
5769
58- // If there are no custom views defined , there's no point in displaying
59- // the dropdown, we will display a "simple" header.
60- if ( projectViews . views . length === 0 ) {
70+ // If there is only one option in the switcher , there is no point in making
71+ // this piece of UI interactive. We display a "simple" header instead .
72+ if ( ! hasMultipleOptions ) {
6173 return (
6274 < button
6375 className = { cx ( styles . trigger , styles . triggerSimple ) }
@@ -97,6 +109,18 @@ function ViewSwitcher(props: ViewSwitcherProps) {
97109 { HOME_VIEW . name }
98110 </ button >
99111
112+ { /* This is the organization view option - depends if user is in MMO
113+ organization */ }
114+ { orgQuery . data ?. is_mmo &&
115+ < button
116+ key = { ORG_VIEW . uid }
117+ className = { styles . menuOption }
118+ onClick = { ( ) => onOptionClick ( ORG_VIEW . uid ) }
119+ >
120+ { ORG_VIEW . name . replace ( '##organization name##' , organizationName ) }
121+ </ button >
122+ }
123+
100124 { /* This is the list of all options for custom views. These are only
101125 being added if custom views are defined (at least one). */ }
102126 { projectViews . views . map ( ( view ) => (
0 commit comments