1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- import React , { Fragment , useState , useEffect } from "react" ;
17+ import React , { Fragment , useEffect , useState } from "react" ;
1818import { Theme } from "@mui/material/styles" ;
1919import createStyles from "@mui/styles/createStyles" ;
2020import withStyles from "@mui/styles/withStyles" ;
@@ -23,7 +23,7 @@ import {
2323 modalStyleUtils ,
2424} from "../Common/FormComponents/common/styleLibrary" ;
2525import Grid from "@mui/material/Grid" ;
26- import { Button , Box , LinearProgress } from "@mui/material" ;
26+ import { Box , Button , LinearProgress } from "@mui/material" ;
2727import PageHeader from "../Common/PageHeader/PageHeader" ;
2828import PageLayout from "../Common/Layout/PageLayout" ;
2929import history from "../../../../src/history" ;
@@ -37,6 +37,7 @@ import { IAM_PAGES } from "../../../common/SecureComponent/permissions";
3737import { ErrorResponseHandler } from "../../../../src/common/types" ;
3838import api from "../../../../src/common/api" ;
3939import { setErrorSnackMessage } from "../../../../src/actions" ;
40+ import SectionTitle from "../Common/SectionTitle" ;
4041
4142interface IAddGroupProps {
4243 classes : any ;
@@ -100,48 +101,37 @@ const styles = (theme: Theme) =>
100101 ...modalStyleUtils ,
101102 } ) ;
102103
103- const AddGroupScreen = ( {
104- classes,
105- setErrorSnackMessage,
106- } : IAddGroupProps ) => {
104+ const AddGroupScreen = ( { classes, setErrorSnackMessage } : IAddGroupProps ) => {
107105 const [ groupName , setGroupName ] = useState < string > ( "" ) ;
108106 const [ saving , isSaving ] = useState < boolean > ( false ) ;
109107 const [ selectedUsers , setSelectedUsers ] = useState < string [ ] > ( [ ] ) ;
110108 const [ validGroup , setValidGroup ] = useState < boolean > ( false ) ;
111109
112-
113110 useEffect ( ( ) => {
114111 setValidGroup ( groupName . trim ( ) !== "" ) ;
115112 } , [ groupName , selectedUsers ] ) ;
116113
117114 useEffect ( ( ) => {
118115 if ( saving ) {
119116 const saveRecord = ( ) => {
120-
121- api
122- . invoke ( "POST" , "/api/v1/groups" , {
123- group : groupName ,
124- members : selectedUsers ,
125- } )
126- . then ( ( res ) => {
127- isSaving ( false ) ;
128- history . push ( `${ IAM_PAGES . GROUPS } ` ) ;
129- } )
130- . catch ( ( err : ErrorResponseHandler ) => {
131- isSaving ( false ) ;
132- setErrorSnackMessage ( err ) ;
133- } ) ;
134- }
135-
117+ api
118+ . invoke ( "POST" , "/api/v1/groups" , {
119+ group : groupName ,
120+ members : selectedUsers ,
121+ } )
122+ . then ( ( res ) => {
123+ isSaving ( false ) ;
124+ history . push ( `${ IAM_PAGES . GROUPS } ` ) ;
125+ } )
126+ . catch ( ( err : ErrorResponseHandler ) => {
127+ isSaving ( false ) ;
128+ setErrorSnackMessage ( err ) ;
129+ } ) ;
130+ } ;
131+
136132 saveRecord ( ) ;
137133 }
138-
139- } , [
140- saving ,
141- groupName ,
142- selectedUsers ,
143- setErrorSnackMessage ,
144- ] ) ;
134+ } , [ saving , groupName , selectedUsers , setErrorSnackMessage ] ) ;
145135
146136 //Fetch Actions
147137 const setSaving = ( event : React . FormEvent ) => {
@@ -150,99 +140,93 @@ const AddGroupScreen = ({
150140 isSaving ( true ) ;
151141 } ;
152142
153- const resetForm = ( ) => {
154- setGroupName ( "" ) ;
155- setSelectedUsers ( [ ] ) ;
143+ const resetForm = ( ) => {
144+ setGroupName ( "" ) ;
145+ setSelectedUsers ( [ ] ) ;
156146 } ;
157147
158-
159-
160148 return (
161149 < Fragment >
162150 < Grid item xs = { 12 } >
163151 < PageHeader
164152 label = { < BackLink to = { IAM_PAGES . GROUPS } label = { "Groups" } /> }
165153 />
166154 < PageLayout >
167- < Grid
168- item
169- xs = { 12 }
170- container
171- className = { classes . title }
172- align-items = "stretch"
155+ < Box
156+ sx = { {
157+ display : "grid" ,
158+ padding : "25px" ,
159+ gap : "25px" ,
160+ gridTemplateColumns : {
161+ md : "2fr 1.2fr" ,
162+ xs : "1fr" ,
163+ } ,
164+ border : "1px solid #eaeaea" ,
165+ } }
173166 >
174- < Grid item className = { classes . headIcon } >
175- < CreateGroupIcon />
176- </ Grid >
177- < Grid item className = { classes . headTitle } >
178- Create Group
179- </ Grid >
180- </ Grid >
181-
182- < Grid container align-items = "center" >
183- < Grid item xs = { 8 } >
184- < Box >
185- < form noValidate autoComplete = "off" onSubmit = { setSaving } >
186- < Grid container item spacing = "20" >
187-
188- < Grid item xs = { 12 } >
189- < Grid container >
190- < Grid item xs = { 12 } className = { classes . formFieldRow } >
191- < InputBoxWrapper
192- id = "group-name"
193- name = "group-name"
194- label = "Group Name"
195- autoFocus = { true }
196- value = { groupName }
197- onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
198- setGroupName ( e . target . value ) ;
199- } }
200- />
201- </ Grid >
202- < Grid item xs = { 12 } className = { classes . userSelector } >
203- < UsersSelectors
204- selectedUsers = { selectedUsers }
205- setSelectedUsers = { setSelectedUsers }
206- editMode = { true }
207- />
208- </ Grid >
209- </ Grid >
210- < Grid item xs = { 12 } className = { classes . modalButtonBar } >
211- < Button
212- type = "button"
213- variant = "outlined"
214- color = "primary"
215- className = { classes . spacerRight }
216- onClick = { resetForm }
217- >
218- Clear
219- </ Button >
220-
221- < Button
222- type = "submit"
223- variant = "contained"
224- color = "primary"
225- disabled = { saving || ! validGroup }
226- >
227- Save
228- </ Button >
229- </ Grid >
230- </ Grid >
231- { saving && (
232- < Grid item xs = { 12 } >
233- < LinearProgress />
234- </ Grid >
235- ) }
236- </ Grid >
237- </ form >
238- </ Box >
239- </ Grid >
240- < Grid item xs = { 4 } >
241- < Box >
242- < AddGroupHelpBox />
243- </ Box >
244- </ Grid >
245- </ Grid >
167+ < Box >
168+ < form noValidate autoComplete = "off" onSubmit = { setSaving } >
169+ < Grid container item spacing = "20" >
170+ < Grid item xs = { 12 } >
171+ < SectionTitle icon = { < CreateGroupIcon /> } >
172+ Create Group
173+ </ SectionTitle >
174+ </ Grid >
175+ < Grid item xs = { 12 } >
176+ < Grid container >
177+ < Grid item xs = { 12 } className = { classes . formFieldRow } >
178+ < InputBoxWrapper
179+ id = "group-name"
180+ name = "group-name"
181+ label = "Group Name"
182+ autoFocus = { true }
183+ value = { groupName }
184+ onChange = { (
185+ e : React . ChangeEvent < HTMLInputElement >
186+ ) => {
187+ setGroupName ( e . target . value ) ;
188+ } }
189+ />
190+ </ Grid >
191+ < Grid item xs = { 12 } className = { classes . userSelector } >
192+ < UsersSelectors
193+ selectedUsers = { selectedUsers }
194+ setSelectedUsers = { setSelectedUsers }
195+ editMode = { true }
196+ />
197+ </ Grid >
198+ </ Grid >
199+ < Grid item xs = { 12 } className = { classes . modalButtonBar } >
200+ < Button
201+ type = "button"
202+ variant = "outlined"
203+ color = "primary"
204+ className = { classes . spacerRight }
205+ onClick = { resetForm }
206+ >
207+ Clear
208+ </ Button >
209+
210+ < Button
211+ type = "submit"
212+ variant = "contained"
213+ color = "primary"
214+ disabled = { saving || ! validGroup }
215+ >
216+ Save
217+ </ Button >
218+ </ Grid >
219+ </ Grid >
220+ { saving && (
221+ < Grid item xs = { 12 } >
222+ < LinearProgress />
223+ </ Grid >
224+ ) }
225+ </ Grid >
226+ </ form >
227+ </ Box >
228+ < AddGroupHelpBox />
229+ </ Box >
246230 </ PageLayout >
247231 </ Grid >
248232 </ Fragment >
0 commit comments