fix: remove logic unnecessarily tied to components and error handling
This commit is contained in:
parent
75a2ecd3c2
commit
26a051ff07
10 changed files with 123 additions and 112 deletions
|
|
@ -61,46 +61,44 @@ const initialValues = {
|
|||
confirmPassword: ''
|
||||
}
|
||||
|
||||
const initialState = {
|
||||
username: null,
|
||||
role: null,
|
||||
result: ''
|
||||
}
|
||||
|
||||
const reducer = (state, action) => {
|
||||
const { type, payload } = action
|
||||
return { ...state, ...payload, result: type }
|
||||
}
|
||||
|
||||
const Register = () => {
|
||||
const classes = useStyles()
|
||||
const history = useHistory()
|
||||
const token = QueryParams().get('t')
|
||||
|
||||
const initialState = {
|
||||
username: null,
|
||||
role: null,
|
||||
result: ''
|
||||
}
|
||||
|
||||
const reducer = (state, action) => {
|
||||
const { type, payload } = action
|
||||
return { ...state, ...payload, result: type }
|
||||
}
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState)
|
||||
|
||||
const { error: queryError, loading } = useQuery(VALIDATE_REGISTER_LINK, {
|
||||
variables: { token: token },
|
||||
onCompleted: ({ validateRegisterLink: info }) => {
|
||||
if (!info) {
|
||||
dispatch({
|
||||
return dispatch({
|
||||
type: 'failure'
|
||||
})
|
||||
} else {
|
||||
dispatch({
|
||||
type: 'success',
|
||||
payload: {
|
||||
username: info.username,
|
||||
role: info.role
|
||||
}
|
||||
})
|
||||
}
|
||||
dispatch({
|
||||
type: 'success',
|
||||
payload: {
|
||||
username: info.username,
|
||||
role: info.role
|
||||
}
|
||||
})
|
||||
},
|
||||
onError: () => {
|
||||
onError: () =>
|
||||
dispatch({
|
||||
type: 'failure'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const [register, { error: mutationError }] = useMutation(REGISTER, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue