fix: remove logic unnecessarily tied to components and error handling

This commit is contained in:
Sérgio Salgado 2021-04-20 20:15:22 +01:00 committed by Josh Harvey
parent 75a2ecd3c2
commit 26a051ff07
10 changed files with 123 additions and 112 deletions

View file

@ -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, {