Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Commit eed2aae

Browse files
committed
feat(fbcnms-ui): Add Organization detail + edit
Signed-off-by: HannaFar <hannafarag159@gmail.com>
1 parent eeeccc8 commit eed2aae

7 files changed

+705
-367
lines changed

fbcnms-packages/fbcnms-ui/master/OrganizationDialog.js

+53-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @flow strict-local
88
* @format
99
*/
10-
1110
import type {OrganizationPlainAttributes} from '@fbcnms/sequelize-models/models/organization';
1211

1312
import Button from '@fbcnms/ui/components/design-system/Button';
@@ -20,12 +19,11 @@ import OrganizationUserDialog from './OrganizationUserDialog';
2019
import React from 'react';
2120
import Tab from '@material-ui/core/Tab';
2221
import Tabs from '@material-ui/core/Tabs';
23-
2422
import {UserRoles} from '@fbcnms/auth/types';
2523
import {brightGray, white} from '@fbcnms/ui/theme/colors';
2624
import {makeStyles} from '@material-ui/styles';
2725
import {useAxios} from '@fbcnms/ui/hooks';
28-
import {useState} from 'react';
26+
import {useEffect, useState} from 'react';
2927

3028
const useStyles = makeStyles(_ => ({
3129
input: {
@@ -38,6 +36,13 @@ const useStyles = makeStyles(_ => ({
3836
color: white,
3937
},
4038
}));
39+
type TabType =
40+
| 'automation'
41+
| 'admin'
42+
| 'inventory'
43+
| 'nms'
44+
| 'workorders'
45+
| 'hub';
4146

4247
export type DialogProps = {
4348
error: string,
@@ -50,15 +55,25 @@ export type DialogProps = {
5055
// If true, enable all networks for an organization
5156
shouldEnableAllNetworks: boolean,
5257
setShouldEnableAllNetworks: boolean => void,
58+
edit: boolean,
59+
getProjectTabs?: () => Array<{id: TabType, name: string}>,
60+
// flag to display advanced fields
61+
hideAdvancedFields: boolean,
5362
};
5463

5564
type Props = {
5665
onClose: () => void,
57-
onCreateOrg: (org: CreateOrgType) => void,
66+
onCreateOrg: (org: $Shape<OrganizationPlainAttributes>) => void,
5867
onCreateUser: (user: CreateUserType) => void,
5968
// flag to display create user tab
6069
addUser: boolean,
6170
setAddUser: () => void,
71+
open: boolean,
72+
organization: ?OrganizationPlainAttributes,
73+
// editing organization
74+
edit: boolean,
75+
// flag to display advanced fields
76+
hideAdvancedFields: boolean,
6277
};
6378

6479
type CreateUserType = {
@@ -72,11 +87,6 @@ type CreateUserType = {
7287
passwordConfirmation?: string,
7388
};
7489

75-
type CreateOrgType = {
76-
name: string,
77-
networkIDs: Array<string>,
78-
customDomains?: Array<string>,
79-
};
8090
/**
8191
* Create Orgnization Dilaog
8292
* This component displays a dialog with 2 tabs
@@ -91,13 +101,27 @@ export default function (props: Props) {
91101
});
92102

93103
const [organization, setOrganization] = useState<OrganizationPlainAttributes>(
94-
{},
104+
props.organization || {},
95105
);
96-
const [currentTab, setCurrentTab] = useState(props.addUser ? 1 : 0);
106+
const [currentTab, setCurrentTab] = useState(0);
97107
const [shouldEnableAllNetworks, setShouldEnableAllNetworks] = useState(false);
98108
const [user, setUser] = useState<CreateUserType>({});
99109
const [createError, setCreateError] = useState('');
100110
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]);
101125

102126
if (isLoading) {
103127
return <LoadingFillerBackdrop />;
@@ -116,23 +140,34 @@ export default function (props: Props) {
116140
allNetworks,
117141
shouldEnableAllNetworks,
118142
setShouldEnableAllNetworks,
143+
edit: props.edit,
144+
hideAdvancedFields: props.hideAdvancedFields,
119145
};
120146
const onSave = async () => {
121147
if (currentTab === 0) {
122148
if (!organization.name) {
123149
setCreateError('Name cannot be empty');
124150
return;
125151
}
126-
const payload = {
152+
const newOrg = {
127153
name: organization.name,
128154
networkIDs: shouldEnableAllNetworks
129155
? allNetworks
130156
: Array.from(organization.networkIDs || []),
131157
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: '',
133168
};
134169

135-
props.onCreateOrg(payload);
170+
props.onCreateOrg(newOrg);
136171
setCurrentTab(currentTab + 1);
137172
setCreateError('');
138173
props.setAddUser();
@@ -151,7 +186,7 @@ export default function (props: Props) {
151186
return;
152187
}
153188

154-
const payload: CreateUserType = {
189+
const newUser: CreateUserType = {
155190
email: user.email,
156191
password: user.password,
157192
role: user.role,
@@ -160,17 +195,17 @@ export default function (props: Props) {
160195
? []
161196
: Array.from(user.networkIDs || []),
162197
};
163-
props.onCreateUser(payload);
198+
props.onCreateUser(newUser);
164199
}
165200
};
166201

167202
return (
168203
<Dialog
169-
open={true}
204+
open={props.open}
170205
onClose={props.onClose}
171206
maxWidth={'sm'}
172207
fullWidth={true}>
173-
<DialogTitle>Add Organization</DialogTitle>
208+
<DialogTitle>{organizationDialogTitle}</DialogTitle>
174209
<Tabs
175210
indicatorColor="primary"
176211
value={currentTab}

0 commit comments

Comments
 (0)