@@ -20,9 +20,12 @@ import TableHead from '@material-ui/core/TableHead'
2020import TableRow from '@material-ui/core/TableRow'
2121import IconButton from '@material-ui/core/IconButton'
2222import TextField from '@material-ui/core/TextField'
23- import FormHelperText from "@material-ui/core/FormHelperText"
24- import FormControl from "@material-ui/core/FormControl"
25- import FormLabel from "@material-ui/core/FormLabel"
23+ import FormHelperText from '@material-ui/core/FormHelperText'
24+ import FormControl from '@material-ui/core/FormControl'
25+ import FormLabel from '@material-ui/core/FormLabel'
26+ import RadioGroup from '@material-ui/core/RadioGroup'
27+ import FormControlLabel from '@material-ui/core/FormControlLabel'
28+ import Radio from '@material-ui/core/Radio'
2629import Dialog from '@material-ui/core/Dialog'
2730import DialogActions from '@material-ui/core/DialogActions'
2831import DialogContent from '@material-ui/core/DialogContent'
@@ -37,7 +40,7 @@ import FileCopyIcon from '@material-ui/icons/FileCopy'
3740import axios from 'axios'
3841import { AppContext } from './MainFrame'
3942import pwdGenerator from 'generate-password'
40- import dateformat from 'dateformat' ;
43+ import dateformat from 'dateformat'
4144
4245const style = ( theme ) => ( {
4346 box : {
@@ -96,6 +99,15 @@ const style = (theme) => ({
9699 position : 'relative' ,
97100 bottom : 5 ,
98101 } ,
102+ radioButton : {
103+ '&$radioChecked' : { color : theme . palette . primary . main } ,
104+ } ,
105+ radioChecked : { } ,
106+ radioGroup : {
107+ position : 'relative' ,
108+ bottom : 12 ,
109+ left : 10 ,
110+ } ,
99111} )
100112
101113function not ( a , b ) {
@@ -254,7 +266,7 @@ function Users(props) {
254266 )
255267
256268 async function handleSave ( ) {
257- if ( userEditing . userName === '' || right === undefined || right . length === 0 ) {
269+ if ( userEditing . userName === '' || right === undefined || right . length === 0 ) {
258270 setErrorMessage ( 'Missing Field' )
259271 return
260272 }
@@ -280,12 +292,10 @@ function Users(props) {
280292 setErrorMessage ( 'An error occured while creating user. Please contact the system admin.' )
281293 return
282294 }
283- }
284- catch ( e ) {
295+ } catch ( e ) {
285296 console . error ( e )
286297 setErrorMessage ( 'An error occured while creating user. Please contact the system admin.' )
287298 }
288-
289299 } else {
290300 try {
291301 let res = await axios . patch (
@@ -306,8 +316,7 @@ function Users(props) {
306316 setErrorMessage ( 'An error occured while updating user. Please contact the system admin.' )
307317 return
308318 }
309- }
310- catch ( e ) {
319+ } catch ( e ) {
311320 console . error ( e )
312321 setErrorMessage ( 'An error occured while updating user. Please contact the system admin.' )
313322 }
@@ -364,6 +373,12 @@ function Users(props) {
364373 setUserEditing ( { ...userEditing , email : e . target . value } )
365374 }
366375
376+ function handleActiveChange ( e ) {
377+ //convert to boolean
378+ let isTrueSet = e . target . value === 'true'
379+ setUserEditing ( { ...userEditing , active : isTrueSet } )
380+ }
381+
367382 function handleAddUser ( ) {
368383 setUserEditing ( { } )
369384 setLeft ( permissions )
@@ -495,12 +510,6 @@ function Users(props) {
495510 >
496511 < DialogTitle id = "form-dialog-title" > User Detail</ DialogTitle >
497512 < DialogContent >
498- { /*
499- <DialogContentText>
500- To subscribe to this website, please enter your email address here. We will send updates
501- occasionally.
502- </DialogContentText>
503- */ }
504513 < TextField
505514 required
506515 error = { userEditing && userEditing . userName === '' }
@@ -509,7 +518,7 @@ function Users(props) {
509518 label = "Username"
510519 type = "text"
511520 variant = "outlined"
512- helperText = { userEditing && userEditing . userName === '' ? " Field is Required" : "" }
521+ helperText = { userEditing && userEditing . userName === '' ? ' Field is Required' : '' }
513522 fullWidth
514523 InputLabelProps = { {
515524 shrink : true ,
@@ -567,19 +576,67 @@ function Users(props) {
567576 className = { classes . input }
568577 onChange = { handleEmailChange }
569578 />
570- { userEditing && userEditing . createdAt && (
571- < Grid container spacing = { 2 } >
572- < Grid item >
573- < Typography variant = "outline" > Created</ Typography >
579+ < FormControl component = "fieldset" className = { classes . formControl } >
580+ < Grid container >
581+ < Grid item >
582+ < FormLabel component = "legend" > Active:</ FormLabel >
583+ </ Grid >
584+ < Grid item >
585+ < RadioGroup
586+ aria-label = "active-state"
587+ name = "active-state"
588+ className = { classes . radioGroup }
589+ value = { ( userEditing && userEditing . active ) || '' }
590+ onChange = { handleActiveChange }
591+ >
592+ < Grid container >
593+ < Grid item >
594+ < FormControlLabel
595+ value = "true"
596+ control = {
597+ < Radio
598+ classes = { { root : classes . radioButton , checked : classes . radioChecked } }
599+ />
600+ }
601+ label = "Active"
602+ />
603+ </ Grid >
604+ < Grid item >
605+ < FormControlLabel
606+ value = "false"
607+ control = {
608+ < Radio
609+ classes = { { root : classes . radioButton , checked : classes . radioChecked } }
610+ />
611+ }
612+ label = "Inactive"
613+ />
614+ </ Grid >
615+ </ Grid >
616+ </ RadioGroup >
617+ </ Grid >
574618 </ Grid >
575- < Grid item >
576- < Typography variant = "outline" >
577- { userEditing && dateformat ( userEditing . createdAt , 'm/d/yyyy h:MMtt' ) }
578- </ Typography >
619+ </ FormControl >
620+ { userEditing && userEditing . createdAt && (
621+ < Grid container spacing = { 2 } >
622+ < Grid item >
623+ < Typography variant = "outline" > Created</ Typography >
624+ </ Grid >
625+ < Grid item >
626+ < Typography variant = "outline" >
627+ { userEditing && dateformat ( userEditing . createdAt , 'm/d/yyyy h:MMtt' ) }
628+ </ Typography >
629+ </ Grid >
579630 </ Grid >
580- </ Grid > ) }
631+ ) }
581632 < FormControl error = { right . length === 0 } >
582- < Grid container spacing = { 2 } justify = "center" alignItems = "center" className = { classes . root } >
633+ < Grid
634+ container
635+ spacing = { 2 }
636+ justify = "center"
637+ alignItems = "center"
638+ className = { classes . root }
639+ >
583640 < Grid item role = "list" >
584641 < FormLabel variant = "outline" > Roles</ FormLabel >
585642 { /* <Typography variant="outline">Roles</Typography> */ }
@@ -635,10 +692,9 @@ function Users(props) {
635692 { customList ( right ) }
636693 </ Grid >
637694 </ Grid >
638- { right . length === 0 &&
639- < FormHelperText >
640- At Least One Role Must be Selected
641- </ FormHelperText > }
695+ { right . length === 0 && (
696+ < FormHelperText > At Least One Role Must be Selected</ FormHelperText >
697+ ) }
642698 </ FormControl >
643699 </ DialogContent >
644700 < DialogActions >
0 commit comments