refactor: getErrorMsg() to pure functions
This commit is contained in:
parent
26a051ff07
commit
86a245f6ba
4 changed files with 64 additions and 47 deletions
|
|
@ -50,6 +50,14 @@ const radioOptions = [
|
|||
}
|
||||
]
|
||||
|
||||
const getErrorMsg = (formikErrors, formikTouched, mutationError) => {
|
||||
if (!formikErrors || !formikTouched) return null
|
||||
if (mutationError) return 'Internal server error'
|
||||
if (formikErrors.username && formikTouched.username)
|
||||
return formikErrors.username
|
||||
return null
|
||||
}
|
||||
|
||||
const CreateUserModal = ({ state, dispatch }) => {
|
||||
const classes = useStyles()
|
||||
|
||||
|
|
@ -74,14 +82,6 @@ const CreateUserModal = ({ state, dispatch }) => {
|
|||
[classes.error]: formikErrors.role && formikTouched.role
|
||||
})
|
||||
|
||||
const getErrorMsg = (formikErrors, formikTouched) => {
|
||||
if (!formikErrors || !formikTouched) return null
|
||||
if (error) return 'Internal server error'
|
||||
if (formikErrors.username && formikTouched.username)
|
||||
return formikErrors.username
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{state.showCreateUserModal && !createUserURL && (
|
||||
|
|
@ -125,8 +125,10 @@ const CreateUserModal = ({ state, dispatch }) => {
|
|||
options={radioOptions}
|
||||
/>
|
||||
<div className={classes.footer}>
|
||||
{getErrorMsg(errors, touched) && (
|
||||
<ErrorMessage>{getErrorMsg(errors, touched)}</ErrorMessage>
|
||||
{getErrorMsg(errors, touched, error) && (
|
||||
<ErrorMessage>
|
||||
{getErrorMsg(errors, touched, error)}
|
||||
</ErrorMessage>
|
||||
)}
|
||||
<Button
|
||||
type="submit"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue