@@ -2,35 +2,30 @@ import React from 'react';
2
2
import { useActions , useAppState } from 'app/overmind' ;
3
3
import { Text , Menu , Stack , Icon , Tooltip } from '@codesandbox/components' ;
4
4
import { sortBy } from 'lodash-es' ;
5
- import css from '@styled-system/css' ;
6
5
import { TeamAvatar } from 'app/components/TeamAvatar' ;
7
- import { SubscriptionType } from 'app/graphql/types' ;
8
- import { MenuItem , Badge } from './elements' ;
9
-
10
- type Team = {
11
- id : string ;
12
- name : string ;
13
- avatarUrl : string | null ;
14
- } ;
6
+ import { Badge } from 'app/components/Badge' ;
15
7
16
8
interface WorkspaceSelectProps {
17
- activeAccount : Team ;
18
9
disabled ?: boolean ;
19
- onSelect : ( account : Team ) => void ;
10
+ onSelect : ( teamId : string ) => void ;
11
+ selectedTeamId : string ;
20
12
}
21
13
22
14
export const WorkspaceSelect : React . FC < WorkspaceSelectProps > = React . memo (
23
- ( { activeAccount , disabled, onSelect } ) => {
15
+ ( { disabled, onSelect, selectedTeamId } ) => {
24
16
const state = useAppState ( ) ;
25
17
const { dashboard, user } = state ;
26
18
const { openCreateTeamModal } = useActions ( ) ;
27
19
28
- if ( ! dashboard . teams || ! state . personalWorkspaceId ) return null ;
20
+ if ( dashboard . teams . length === 0 || ! state . personalWorkspaceId ) return null ;
29
21
30
22
const personalWorkspace = dashboard . teams . find (
31
23
t => t . id === state . personalWorkspaceId
32
24
) ! ;
33
25
26
+ const selectedTeam = dashboard . teams . find ( t => t . id === selectedTeamId ) ;
27
+ const isPersonalTeam = selectedTeamId === state . personalWorkspaceId ;
28
+
34
29
const workspaces = [
35
30
personalWorkspace ,
36
31
...sortBy (
@@ -47,60 +42,58 @@ export const WorkspaceSelect: React.FC<WorkspaceSelectProps> = React.memo(
47
42
: null
48
43
}
49
44
>
50
- < Stack css = { css ( { width : '100%' , height : '100%' } ) } >
45
+ < Stack css = { { flex : 1 , height : '100%' } } >
51
46
< Menu >
52
47
< Stack
53
48
as = { Menu . Button }
54
49
disabled = { disabled }
55
50
justify = "space-between"
56
51
align = "center"
57
- css = { css ( {
52
+ css = { {
58
53
width : '100%' ,
59
- height : '100%' ,
60
- marginLeft : 0 ,
54
+ cursor : 'default' ,
55
+ color : '#C2C2C2' ,
56
+ paddingLeft : '28px' ,
57
+ height : '36px' ,
58
+ borderRadius : '2px 0 0 2px' ,
61
59
'&:hover' : {
62
- backgroundColor : 'grays.600 ' ,
60
+ backgroundColor : '#242424 ' ,
63
61
} ,
64
- } ) }
62
+ } }
65
63
>
66
- < Stack gap = { 2 } as = "span" align = "center" >
67
- < Stack as = "span" align = "center" justify = "center" >
68
- < TeamAvatar
69
- avatar = {
70
- state . activeTeamInfo ?. avatarUrl || activeAccount . avatarUrl
71
- }
72
- name = { activeAccount . name }
73
- />
74
- </ Stack >
75
- < Text size = { 14 } weight = "normal" maxWidth = { 140 } >
76
- { activeAccount . name }
64
+ < Stack align = "center" gap = { 1 } css = { { paddingRight : 4 } } >
65
+ < Text
66
+ size = { 16 }
67
+ maxWidth = { selectedTeam . subscription ? 166 : 126 }
68
+ >
69
+ { isPersonalTeam ? 'Personal' : selectedTeam . name }
77
70
</ Text >
71
+
72
+ { ! selectedTeam . subscription && (
73
+ < Badge color = "accent" > Free</ Badge >
74
+ ) }
78
75
</ Stack >
79
76
80
77
< Icon name = "chevronDown" size = { 8 } />
81
78
</ Stack >
82
79
83
80
< Menu . List
84
- css = { css ( {
81
+ css = { {
85
82
width : '100%' ,
86
- marginTop : - 2 ,
87
- backgroundColor : 'grays.600' ,
88
- } ) }
89
- style = { { backgroundColor : '#242424' , borderColor : '#343434' } } // TODO: find a way to override reach styles without the selector mess
83
+ marginLeft : 7 ,
84
+ marginTop : 4 ,
85
+ borderRadius : '2px' ,
86
+ backgroundColor : '#242424' ,
87
+ } }
90
88
>
91
89
{ workspaces . map ( team => (
92
- < MenuItem
90
+ < Stack
93
91
as = { Menu . Item }
94
92
key = { team . id }
95
93
align = "center"
96
94
gap = { 2 }
97
- onSelect = { ( ) =>
98
- onSelect ( {
99
- name : team . name ,
100
- id : team . id ,
101
- avatarUrl : team . avatarUrl ,
102
- } )
103
- }
95
+ css = { { borderBottom : '1px solid #343434' } }
96
+ onSelect = { ( ) => onSelect ( team . id ) }
104
97
>
105
98
< TeamAvatar
106
99
avatar = {
@@ -112,40 +105,41 @@ export const WorkspaceSelect: React.FC<WorkspaceSelectProps> = React.memo(
112
105
size = "small"
113
106
style = { { overflow : 'hidden' } }
114
107
/>
115
- < Stack align = "center" >
116
- < Text css = { css ( { width : '100%' } ) } size = { 3 } >
117
- { team . name }
108
+ < Stack
109
+ align = "center"
110
+ justify = "space-between"
111
+ css = { { flex : 1 } }
112
+ gap = { 1 }
113
+ >
114
+ < Text css = { { width : '100%' } } size = { 3 } >
115
+ { team . id === state . personalWorkspaceId
116
+ ? 'Personal'
117
+ : team . name }
118
118
</ Text >
119
119
120
- { [
121
- SubscriptionType . TeamPro ,
122
- SubscriptionType . PersonalPro ,
123
- ] . includes ( team . subscription ?. type ) && < Badge > Pro</ Badge > }
120
+ { ! team . subscription && < Badge color = "accent" > Free</ Badge > }
124
121
</ Stack >
125
- </ MenuItem >
122
+ </ Stack >
126
123
) ) }
127
124
128
125
< Stack
129
126
as = { Menu . Item }
130
127
align = "center"
131
128
gap = { 2 }
132
- css = { css ( {
133
- height : 10 ,
129
+ css = { {
134
130
textAlign : 'left' ,
135
- marginLeft : '1px' ,
136
- } ) }
137
- style = { { paddingLeft : 8 } }
131
+ } }
138
132
onSelect = { openCreateTeamModal }
139
133
>
140
134
< Stack
141
135
justify = "center"
142
136
align = "center"
143
- css = { css ( {
144
- size : 6 ,
145
- borderRadius : 'small' ,
146
- border : '1px solid ' ,
147
- borderColor : 'grays.500 ' ,
148
- } ) }
137
+ css = { {
138
+ width : 24 ,
139
+ height : 24 ,
140
+ borderRadius : '2px ' ,
141
+ border : '1px solid #999 ' ,
142
+ } }
149
143
>
150
144
< Icon name = "plus" size = { 10 } />
151
145
</ Stack >
0 commit comments