2017-11-09 17:36:07 +01:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* AuthPage actions
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
ON_CHANGE_INPUT,
|
2017-11-09 18:07:55 +01:00
|
|
|
SET_ERRORS,
|
2017-11-09 17:36:07 +01:00
|
|
|
SET_FORM,
|
2017-11-10 14:20:33 +01:00
|
|
|
SUBMIT,
|
|
|
|
|
SUBMIT_ERROR,
|
|
|
|
|
SUBMIT_SUCCEEDED,
|
2017-11-09 17:36:07 +01:00
|
|
|
} from './constants';
|
|
|
|
|
|
|
|
|
|
export function onChangeInput({ target }) {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CHANGE_INPUT,
|
|
|
|
|
key: target.name,
|
|
|
|
|
value: target.value,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 18:07:55 +01:00
|
|
|
export function setErrors(formErrors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ERRORS,
|
|
|
|
|
formErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 17:36:07 +01:00
|
|
|
export function setForm(formType, email) {
|
|
|
|
|
let data;
|
|
|
|
|
|
|
|
|
|
switch (formType) {
|
|
|
|
|
case 'forgot-password':
|
|
|
|
|
data = {
|
|
|
|
|
email: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'login':
|
|
|
|
|
data = {
|
2017-11-14 11:46:18 +01:00
|
|
|
identifier: '',
|
2017-11-09 17:36:07 +01:00
|
|
|
password: '',
|
|
|
|
|
rememberMe: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'register':
|
|
|
|
|
data = {
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
|
|
|
|
confirmPassword: '',
|
|
|
|
|
email: '',
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case 'register-success':
|
|
|
|
|
data = {
|
|
|
|
|
email,
|
|
|
|
|
};
|
|
|
|
|
break;
|
2017-11-20 14:21:08 +01:00
|
|
|
case 'reset-password':
|
|
|
|
|
data = {
|
|
|
|
|
password: '',
|
|
|
|
|
passwordConfirmation: '',
|
|
|
|
|
code: email,
|
|
|
|
|
};
|
|
|
|
|
break;
|
2017-11-09 17:36:07 +01:00
|
|
|
default:
|
|
|
|
|
data = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_FORM,
|
|
|
|
|
data,
|
2017-11-14 14:27:16 +01:00
|
|
|
formType,
|
2017-11-09 17:36:07 +01:00
|
|
|
};
|
|
|
|
|
}
|
2017-11-10 14:20:33 +01:00
|
|
|
|
|
|
|
|
export function submit() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 14:21:08 +01:00
|
|
|
export function submitError(formErrors) {
|
2017-11-10 14:20:33 +01:00
|
|
|
return {
|
|
|
|
|
type: SUBMIT_ERROR,
|
2017-11-20 14:21:08 +01:00
|
|
|
formErrors,
|
2017-11-10 14:20:33 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitSucceeded() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_SUCCEEDED,
|
|
|
|
|
};
|
|
|
|
|
}
|