@@ -8,12 +8,13 @@ import cx from 'classnames';
8
8
import Icon from 'js/components/common/icon' ;
9
9
import KoboDropdown from 'js/components/common/koboDropdown' ;
10
10
11
- // Stores
11
+ // Stores and hooks
12
12
import projectViewsStore from './projectViewsStore' ;
13
+ import { useOrganizationQuery } from 'js/account/stripe.api' ;
13
14
14
15
// Constants
15
16
import { PROJECTS_ROUTES } from 'js/router/routerConstants' ;
16
- import { HOME_VIEW } from './constants' ;
17
+ import { HOME_VIEW , ORG_VIEW } from './constants' ;
17
18
18
19
// Styles
19
20
import styles from './viewSwitcher.module.scss' ;
@@ -32,11 +33,14 @@ function ViewSwitcher(props: ViewSwitcherProps) {
32
33
// We track the menu visibility for the trigger icon.
33
34
const [ isMenuVisible , setIsMenuVisible ] = useState ( false ) ;
34
35
const [ projectViews ] = useState ( ( ) => projectViewsStore ) ;
36
+ const orgQuery = useOrganizationQuery ( ) ;
35
37
const navigate = useNavigate ( ) ;
36
38
37
39
const onOptionClick = ( viewUid : string ) => {
38
40
if ( viewUid === HOME_VIEW . uid || viewUid === null ) {
39
41
navigate ( PROJECTS_ROUTES . MY_PROJECTS ) ;
42
+ } else if ( viewUid === ORG_VIEW . uid ) {
43
+ navigate ( PROJECTS_ROUTES . MY_ORG_PROJECTS ) ;
40
44
} else {
41
45
navigate ( PROJECTS_ROUTES . CUSTOM_VIEW . replace ( ':viewUid' , viewUid ) ) ;
42
46
// The store keeps a number of assets of each view, and that number
@@ -45,8 +49,16 @@ function ViewSwitcher(props: ViewSwitcherProps) {
45
49
}
46
50
} ;
47
51
52
+ const hasMultipleOptions = (
53
+ projectViews . views . length !== 0 ||
54
+ orgQuery . data ?. is_mmo
55
+ ) ;
56
+ const organizationName = orgQuery . data ?. name || t ( 'Organization' ) ;
57
+
48
58
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 ) {
50
62
triggerLabel = projectViews . getView ( props . selectedViewUid ) ?. name || '-' ;
51
63
}
52
64
@@ -55,9 +67,9 @@ function ViewSwitcher(props: ViewSwitcherProps) {
55
67
return null ;
56
68
}
57
69
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 ) {
61
73
return (
62
74
< button
63
75
className = { cx ( styles . trigger , styles . triggerSimple ) }
@@ -97,6 +109,18 @@ function ViewSwitcher(props: ViewSwitcherProps) {
97
109
{ HOME_VIEW . name }
98
110
</ button >
99
111
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
+
100
124
{ /* This is the list of all options for custom views. These are only
101
125
being added if custom views are defined (at least one). */ }
102
126
{ projectViews . views . map ( ( view ) => (
0 commit comments