7
7
* @flow strict-local
8
8
* @format
9
9
*/
10
-
11
10
import type { OrganizationPlainAttributes } from '@fbcnms/sequelize-models/models/organization' ;
12
11
13
12
import Button from '@fbcnms/ui/components/design-system/Button' ;
@@ -20,12 +19,11 @@ import OrganizationUserDialog from './OrganizationUserDialog';
20
19
import React from 'react' ;
21
20
import Tab from '@material-ui/core/Tab' ;
22
21
import Tabs from '@material-ui/core/Tabs' ;
23
-
24
22
import { UserRoles } from '@fbcnms/auth/types' ;
25
23
import { brightGray , white } from '@fbcnms/ui/theme/colors' ;
26
24
import { makeStyles } from '@material-ui/styles' ;
27
25
import { useAxios } from '@fbcnms/ui/hooks' ;
28
- import { useState } from 'react' ;
26
+ import { useEffect , useState } from 'react' ;
29
27
30
28
const useStyles = makeStyles ( _ => ( {
31
29
input : {
@@ -38,6 +36,13 @@ const useStyles = makeStyles(_ => ({
38
36
color : white ,
39
37
} ,
40
38
} ) ) ;
39
+ type TabType =
40
+ | 'automation'
41
+ | 'admin'
42
+ | 'inventory'
43
+ | 'nms'
44
+ | 'workorders'
45
+ | 'hub' ;
41
46
42
47
export type DialogProps = {
43
48
error : string ,
@@ -50,15 +55,25 @@ export type DialogProps = {
50
55
// If true, enable all networks for an organization
51
56
shouldEnableAllNetworks : boolean ,
52
57
setShouldEnableAllNetworks : boolean => void ,
58
+ edit : boolean ,
59
+ getProjectTabs ?: ( ) => Array < { id : TabType , name : string } > ,
60
+ // flag to display advanced fields
61
+ hideAdvancedFields : boolean ,
53
62
} ;
54
63
55
64
type Props = {
56
65
onClose : ( ) => void ,
57
- onCreateOrg : ( org : CreateOrgType ) => void ,
66
+ onCreateOrg : ( org : $Shape < OrganizationPlainAttributes > ) => void ,
58
67
onCreateUser : ( user : CreateUserType ) => void ,
59
68
// flag to display create user tab
60
69
addUser : boolean ,
61
70
setAddUser : ( ) => void ,
71
+ open : boolean ,
72
+ organization : ?OrganizationPlainAttributes ,
73
+ // editing organization
74
+ edit : boolean ,
75
+ // flag to display advanced fields
76
+ hideAdvancedFields : boolean ,
62
77
} ;
63
78
64
79
type CreateUserType = {
@@ -72,11 +87,6 @@ type CreateUserType = {
72
87
passwordConfirmation ?: string ,
73
88
} ;
74
89
75
- type CreateOrgType = {
76
- name : string ,
77
- networkIDs : Array < string > ,
78
- customDomains ?: Array < string > ,
79
- } ;
80
90
/**
81
91
* Create Orgnization Dilaog
82
92
* This component displays a dialog with 2 tabs
@@ -91,13 +101,27 @@ export default function (props: Props) {
91
101
} ) ;
92
102
93
103
const [ organization , setOrganization ] = useState < OrganizationPlainAttributes > (
94
- { } ,
104
+ props . organization || { } ,
95
105
) ;
96
- const [ currentTab , setCurrentTab ] = useState ( props . addUser ? 1 : 0 ) ;
106
+ const [ currentTab , setCurrentTab ] = useState ( 0 ) ;
97
107
const [ shouldEnableAllNetworks , setShouldEnableAllNetworks ] = useState ( false ) ;
98
108
const [ user , setUser ] = useState < CreateUserType > ( { } ) ;
99
109
const [ createError , setCreateError ] = useState ( '' ) ;
100
110
const allNetworks = error || ! response ? [ ] : response . data . sort ( ) ;
111
+ const organizationDialogTitle =
112
+ currentTab === 1
113
+ ? 'Add User'
114
+ : props . edit
115
+ ? 'Edit Organization'
116
+ : 'Add Organization' ;
117
+
118
+ useEffect ( ( ) => {
119
+ setCurrentTab ( props . addUser ? 1 : 0 ) ;
120
+ } , [ props . addUser ] ) ;
121
+
122
+ useEffect ( ( ) => {
123
+ setOrganization ( { } ) ;
124
+ } , [ props . open ] ) ;
101
125
102
126
if ( isLoading ) {
103
127
return < LoadingFillerBackdrop /> ;
@@ -116,23 +140,34 @@ export default function (props: Props) {
116
140
allNetworks,
117
141
shouldEnableAllNetworks,
118
142
setShouldEnableAllNetworks,
143
+ edit : props . edit ,
144
+ hideAdvancedFields : props . hideAdvancedFields ,
119
145
} ;
120
146
const onSave = async ( ) => {
121
147
if ( currentTab === 0 ) {
122
148
if ( ! organization . name ) {
123
149
setCreateError ( 'Name cannot be empty' ) ;
124
150
return ;
125
151
}
126
- const payload = {
152
+ const newOrg = {
127
153
name : organization . name ,
128
154
networkIDs : shouldEnableAllNetworks
129
155
? allNetworks
130
156
: Array . from ( organization . networkIDs || [ ] ) ,
131
157
customDomains : [ ] , // TODO
132
- // tabs: Array.from(tabs),
158
+ // default tab is nms
159
+ tabs : Array . from ( organization . tabs || [ 'nms' ] ) ,
160
+ csvCharset : '' ,
161
+ ssoSelectedType : 'none' ,
162
+ ssoCert : '' ,
163
+ ssoEntrypoint : '' ,
164
+ ssoIssuer : '' ,
165
+ ssoOidcClientID : '' ,
166
+ ssoOidcClientSecret : '' ,
167
+ ssoOidcConfigurationURL : '' ,
133
168
} ;
134
169
135
- props . onCreateOrg ( payload ) ;
170
+ props . onCreateOrg ( newOrg ) ;
136
171
setCurrentTab ( currentTab + 1 ) ;
137
172
setCreateError ( '' ) ;
138
173
props . setAddUser ( ) ;
@@ -151,7 +186,7 @@ export default function (props: Props) {
151
186
return ;
152
187
}
153
188
154
- const payload : CreateUserType = {
189
+ const newUser : CreateUserType = {
155
190
email : user . email ,
156
191
password : user . password ,
157
192
role : user . role ,
@@ -160,17 +195,17 @@ export default function (props: Props) {
160
195
? [ ]
161
196
: Array . from ( user . networkIDs || [ ] ) ,
162
197
} ;
163
- props . onCreateUser ( payload ) ;
198
+ props . onCreateUser ( newUser ) ;
164
199
}
165
200
} ;
166
201
167
202
return (
168
203
< Dialog
169
- open = { true }
204
+ open = { props . open }
170
205
onClose = { props . onClose }
171
206
maxWidth = { 'sm' }
172
207
fullWidth = { true } >
173
- < DialogTitle > Add Organization </ DialogTitle >
208
+ < DialogTitle > { organizationDialogTitle } </ DialogTitle >
174
209
< Tabs
175
210
indicatorColor = "primary"
176
211
value = { currentTab }
0 commit comments