Finished functionally complete client registration workflow
This commit is contained in:
91
src/actions/auth/reducer.actions.js
Normal file
91
src/actions/auth/reducer.actions.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
IS_SENDING_AUTH_REQUEST,
|
||||
SET_AUTH_REQUEST_ERROR,
|
||||
CLEAR_AUTH_REQUEST_ERROR,
|
||||
SET_AUTH_REQUEST_SUCCESS,
|
||||
CLEAR_AUTH_REQUEST_SUCCESS,
|
||||
SET_SELF_USER,
|
||||
SET_FORM_EMAIL,
|
||||
SET_FORM_PASSWORD,
|
||||
SET_FORM_PASSWORD_CONFIRMATION
|
||||
} from "../../constants/auth.constants";
|
||||
import { parseError } from "../common.actions";
|
||||
|
||||
export function isSendingAuthRequest(sendingRequest) {
|
||||
return {
|
||||
type: IS_SENDING_AUTH_REQUEST,
|
||||
data: sendingRequest
|
||||
};
|
||||
}
|
||||
|
||||
export function setAuthRequestError(exception) {
|
||||
let rawError = parseError(exception);
|
||||
if (rawError.email) {
|
||||
rawError["Email"] = rawError.email;
|
||||
delete rawError["email"];
|
||||
}
|
||||
if (rawError.password1) {
|
||||
rawError["Password"] = rawError.password1;
|
||||
delete rawError["password1"];
|
||||
}
|
||||
if (rawError.password2) {
|
||||
rawError["Password Confirmation"] = rawError.password2;
|
||||
delete rawError["password2"];
|
||||
}
|
||||
if (rawError.non_field_errors) {
|
||||
rawError["Non Field Errors"] = rawError.non_field_errors;
|
||||
delete rawError["non_field_errors"];
|
||||
}
|
||||
|
||||
return {
|
||||
type: SET_AUTH_REQUEST_ERROR,
|
||||
data: parseError(exception)
|
||||
};
|
||||
}
|
||||
|
||||
export function clearAuthRequestError() {
|
||||
return {
|
||||
type: CLEAR_AUTH_REQUEST_ERROR
|
||||
};
|
||||
}
|
||||
|
||||
export function setAuthRequestSuccess(response) {
|
||||
return {
|
||||
type: SET_AUTH_REQUEST_SUCCESS,
|
||||
data: response.detail || response
|
||||
}
|
||||
}
|
||||
|
||||
export function clearAuthRequestSuccess() {
|
||||
return {
|
||||
type: CLEAR_AUTH_REQUEST_SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
export function setSelfUser(selfUser) {
|
||||
return {
|
||||
type: SET_SELF_USER,
|
||||
data: selfUser
|
||||
};
|
||||
}
|
||||
|
||||
export function setFormEmail(email) {
|
||||
return {
|
||||
type: SET_FORM_EMAIL,
|
||||
data: email
|
||||
};
|
||||
}
|
||||
|
||||
export function setFormPassword(password) {
|
||||
return {
|
||||
type: SET_FORM_PASSWORD,
|
||||
data: password
|
||||
};
|
||||
}
|
||||
|
||||
export function setFormPasswordConfirmation(passwordConfirmation) {
|
||||
return {
|
||||
type: SET_FORM_PASSWORD_CONFIRMATION,
|
||||
data: passwordConfirmation
|
||||
};
|
||||
}
|
10
src/actions/auth/saga.actions.js
Normal file
10
src/actions/auth/saga.actions.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import {
|
||||
SEND_REGISTER_REQUEST
|
||||
} from "../../constants/auth.constants";
|
||||
|
||||
export function sendRegisterRequest(postbody) {
|
||||
return {
|
||||
type: SEND_REGISTER_REQUEST,
|
||||
data: postbody
|
||||
}
|
||||
}
|
13
src/actions/common.actions.js
Normal file
13
src/actions/common.actions.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Given an exception return the list of errors, the singular error, or generic error
|
||||
* @param {object|string} exception - axios returned exception
|
||||
*/
|
||||
export function parseError(exception) {
|
||||
let response = exception.response || {};
|
||||
let data = response.data || {};
|
||||
let err = "" + exception;
|
||||
if (response.status) {
|
||||
err = `${response.status} ${response.statusText}`;
|
||||
}
|
||||
return data || err
|
||||
}
|
Reference in New Issue
Block a user