-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ciatph/dev
v1.0.7
- Loading branch information
Showing
22 changed files
with
311 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import PropTypes from 'prop-types' | ||
import Button from '@mui/material/Button' | ||
import Box from '@mui/material/Box' | ||
import FormControlLabel from '@mui/material/FormControlLabel' | ||
import InputLabel from '@mui/material/InputLabel' | ||
import MenuItem from '@mui/material/MenuItem' | ||
import Select from '@mui/material/Select' | ||
import Switch from '@mui/material/Switch' | ||
import TextField from '@mui/material/TextField' | ||
import AlertMessage from '../alert_message' | ||
import styles from './styles' | ||
|
||
function UserForm (props) { | ||
const { state, loadstatus, onTextChange, onBtnClick, type = 'create' } = props | ||
|
||
return ( | ||
<Box | ||
component='form' | ||
noValidate | ||
autoComplete='off' | ||
sx={styles.container} | ||
> | ||
|
||
{type !== 'create' && | ||
<TextField | ||
id='uid' | ||
label='Enter UID' | ||
variant='outlined' | ||
size='small' | ||
disabled | ||
value={state.uid} | ||
/>} | ||
|
||
<TextField | ||
id='email' | ||
label='Enter email' | ||
variant='outlined' | ||
size='small' | ||
disabled={loadstatus.isLoading} | ||
value={state.email} | ||
onChange={onTextChange} | ||
/> | ||
|
||
<TextField | ||
id='displayname' | ||
label='Enter display name' | ||
variant='outlined' | ||
size='small' | ||
disabled={loadstatus.isLoading} | ||
value={state.displayname} | ||
onChange={onTextChange} | ||
/> | ||
|
||
<InputLabel sx={styles.formlabel} id='accountlevel-label'>Account Type</InputLabel> | ||
<Select | ||
labelId='accountlevel-label' | ||
id='account_level' | ||
size='small' | ||
disabled={loadstatus.isLoading} | ||
value={state.account_level} | ||
onChange={onTextChange} | ||
> | ||
<MenuItem value={1} size='small'>Superadmin</MenuItem> | ||
<MenuItem value={2} size='small'>Admin</MenuItem> | ||
</Select> | ||
|
||
<FormControlLabel control={ | ||
<Switch checked={state.disabled} id='disabled' name='disabled' onChange={onTextChange} />} | ||
label="Account Disabled" /> | ||
<FormControlLabel control={ | ||
<Switch checked={state.emailverified} id='emailverified' name='emailverified' onChange={onTextChange} />} | ||
label="Email Verified" /> | ||
|
||
<Button | ||
variant='contained' | ||
sx={styles.button} | ||
disabled={loadstatus.isLoading} | ||
onClick={onBtnClick} | ||
>Submit | ||
</Button> | ||
|
||
{(loadstatus.message !== '' || loadstatus.error !== '') && | ||
<AlertMessage | ||
severity={(loadstatus.error !== '') ? 'error' : 'success'} | ||
title={(loadstatus.error !== '') ? 'Error' : 'Success'} | ||
message={(loadstatus.error !== '') ? loadstatus.error : loadstatus.message} | ||
/> | ||
} | ||
</Box> | ||
) | ||
} | ||
|
||
UserForm.propTypes = { | ||
state: PropTypes.object, | ||
loadstatus: PropTypes.object, | ||
onTextChange: PropTypes.func, | ||
onBtnClick: PropTypes.func, | ||
type: PropTypes.string | ||
} | ||
|
||
export default UserForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const styles = { | ||
container: { | ||
width: '400px', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
'& .MuiTextField-root, button': { | ||
marginTop: (theme) => theme.spacing(2) | ||
} | ||
}, | ||
formlabel: { | ||
fontSize: '12px', | ||
marginTop: (theme) => theme.spacing(1), | ||
marginBottom: '4px' | ||
} | ||
} | ||
|
||
export default styles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useState } from 'react' | ||
import { useLocation } from 'react-router-dom' | ||
import { updateUser } from '../../utils/service' | ||
import UserForm from '../../components/common/userform' | ||
|
||
const defaultState = { | ||
email: '', displayname: '', account_level: '1', disabled: false, emailverified: false | ||
} | ||
|
||
const defaultLoadingState = { | ||
isLoading: false, error: '', message: '' | ||
} | ||
|
||
function UpdateUserContainer () { | ||
const location = useLocation() | ||
const [state, setState] = useState(location?.state || defaultState) | ||
const [loading, setLoading] = useState(defaultLoadingState) | ||
|
||
const onInputChange = (e) => { | ||
let { id, value, checked } = e.target | ||
const key = (id !== undefined) ? id : 'account_level' | ||
|
||
if (['emailverified', 'disabled'].includes(key)) { | ||
value = checked | ||
} | ||
|
||
setState({ ...state, [key]: value }) | ||
if (loading.error !== '' || loading.message !== '') { | ||
setLoading(defaultLoadingState) | ||
} | ||
} | ||
|
||
const onBtnUpdateClick = async () => { | ||
try { | ||
setLoading({ ...loading, isLoading: true }) | ||
await updateUser(state) | ||
setLoading(prev => ({ ...defaultLoadingState, message: 'User info updated.' })) | ||
} catch (err) { | ||
setLoading(prev => ({ ...defaultLoadingState, error: err.response ? err.response.data : err.message })) | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>Update User</h1> | ||
|
||
<UserForm | ||
state={state} | ||
loadstatus={loading} | ||
onTextChange={onInputChange} | ||
onBtnClick={onBtnUpdateClick} | ||
type='update' | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default UpdateUserContainer |
Oops, something went wrong.