/
UserHomeTabs.jsx
179 lines (174 loc) · 6.03 KB
/
UserHomeTabs.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React from 'react';
import { Tabs, Tab, AppBar, CircularProgress, Button } from '@mui/material';
import {
List as ListIcon,
Loyalty as LoyaltyIcon,
Home as HomeIcon,
Add as AddIcon,
} from '@mui/icons-material';
import { isEmpty, startCase } from 'lodash';
import { WHITE, GREEN, ORANGE } from '../../common/constants';
import { currentUserHasAccess } from '../../common/utils';
import Search from '../search/Search';
import CommonFormDrawer from '../common/CommonFormDrawer';
import OrgForm from '../orgs/OrgForm';
import CollectionForm from '../collections/CollectionForm';
import SourceForm from '../sources/forms/SourceForm';
const HEIGHT = '50px'
const ICON_STYLES = {marginRight: '10px', marginBottom: '0px'}
const TAB_STYLES = {minHeight: HEIGHT, paddingTop: '6px', height: HEIGHT}
const UserHomeTabs = props => {
const { tab, user } = props;
const [orgForm, setOrgForm] = React.useState(false);
const [sourceForm, setSourceForm] = React.useState(false);
const [collectionForm, setCollectionForm] = React.useState(false);
const indicatorColorClass = () => tab === 2 ? 'bg-orange' : 'bg-green';
const getIconStyles = (index, color) => tab === index ?
{color: color, ...ICON_STYLES} :
{...ICON_STYLES};
const getTabStyles = (index, color) => tab === index ?
{color: color, ...TAB_STYLES} :
{...TAB_STYLES};
const loaded = !isEmpty(user)
const hasAccess = currentUserHasAccess();
const onNewResourceClick = resource => {
if(resource === 'organization')
setOrgForm(true)
if(resource === 'source')
setSourceForm(true)
if(resource === 'collection')
setCollectionForm(true)
}
const getNewResourceButton = resource => {
return (
<Button
size="small"
color="primary"
variant="outlined"
startIcon={<AddIcon fontSize="inherit"/>}
onClick={() => onNewResourceClick(resource)}>
{startCase(resource)}
</Button>
)
}
return (
<div className='col-xs-12 no-right-padding'>
<AppBar position="static" color="default" style={{backgroundColor: WHITE, boxShadow: 'none'}}>
<Tabs
value={tab}
indicatorColor="primary"
textColor="primary"
variant="fullWidth"
style={{height: HEIGHT}}
classes={{
indicator: indicatorColorClass()
}}
>
<Tab
className='material-tab'
label="User Sources"
icon={<ListIcon fontSize='small' style={getIconStyles(0, GREEN)} />}
style={getTabStyles(0, GREEN)}
component="a" href={`#${user.url}sources/`}
/>
<Tab
className='material-tab'
label="User Collections"
icon={<LoyaltyIcon fontSize='small' style={getIconStyles(1, GREEN)} />}
style={getTabStyles(1, GREEN)}
component="a" href={`#${user.url}collections/`}
/>
<Tab
className='material-tab'
label="Organization Membership"
icon={<HomeIcon fontSize='small' style={getIconStyles(2, ORANGE)} />}
style={getTabStyles(2, ORANGE)}
component="a" href={`#${user.url}orgs/`}
/>
</Tabs>
</AppBar>
<div className='sub-tab-container' style={{display: 'flex', height: 'auto'}}>
{
tab === 0 &&
(
loaded ?
<Search
{...props}
nested
essentialColumns
parentResource="user"
baseURL={user.sources_url}
fixedFilters={{isTable: true, limit: 25}}
resource="sources"
searchInputPlaceholder={`Search ${user.username} sources...`}
newResourceComponent={hasAccess && getNewResourceButton('source')}
/> :
<CircularProgress color="primary" />
)
}
{
tab === 1 &&
(
loaded ?
<Search
{...props}
nested
essentialColumns
parentResource="user"
baseURL={user.collections_url}
fixedFilters={{isTable: true, limit: 25}}
resource="collections"
searchInputPlaceholder={`Search ${user.username} collections...`}
newResourceComponent={hasAccess && getNewResourceButton('collection')}
/> :
<CircularProgress color="primary" />
)
}
{
tab === 2 &&
(
loaded ?
<Search
{...props}
nested
parentResource="user"
baseURL={user.organizations_url}
fixedFilters={{isTable: true, limit: 25}}
resource="organizations"
searchInputPlaceholder={`Search ${user.username} organizations...`}
newResourceComponent={hasAccess && getNewResourceButton('organization')}
/> :
<CircularProgress color="primary" />
)
}
</div>
<CommonFormDrawer
style={{zIndex: 1202}}
isOpen={sourceForm}
onClose={() => setSourceForm(false)}
size='smedium'
formComponent={
<SourceForm onCancel={() => setSourceForm(false)} reloadOnSuccess={tab==0} owner={user} />
}
/>
<CommonFormDrawer
style={{zIndex: 1202}}
isOpen={collectionForm}
onClose={() => setCollectionForm(false)}
size='smedium'
formComponent={
<CollectionForm onCancel={() => setCollectionForm(false)} reloadOnSuccess={tab==1} owner={user} />
}
/>
<CommonFormDrawer
style={{zIndex: 1202}}
isOpen={orgForm}
onClose={() => setOrgForm(false)}
formComponent={
<OrgForm onCancel={() => setOrgForm(false)} reloadOnSuccess={tab==2} successURI={user.organizations_url} />
}
/>
</div>
)
}
export default UserHomeTabs;