error validation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BUILDER_CHANGE, BUILDER_TITLE, BUILDER_ID, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP, BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from './types';
|
||||
import { BUILDER_CHANGE, BUILDER_ERROR, BUILDER_TITLE, BUILDER_ID, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP, BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from './types';
|
||||
|
||||
export const changeTutorialBuilder = () => (dispatch) => {
|
||||
dispatch({
|
||||
@@ -35,9 +35,19 @@ export const addStep = (index) => (dispatch, getState) => {
|
||||
type: BUILDER_ADD_STEP,
|
||||
payload: steps
|
||||
});
|
||||
dispatch(addErrorStep(index));
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const addErrorStep = (index) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
error.steps.splice(index, 0, {});
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
};
|
||||
|
||||
export const removeStep = (index) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
steps.splice(index, 1);
|
||||
@@ -45,9 +55,19 @@ export const removeStep = (index) => (dispatch, getState) => {
|
||||
type: BUILDER_DELETE_STEP,
|
||||
payload: steps
|
||||
});
|
||||
dispatch(removeErrorStep(index));
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const removeErrorStep = (index) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
error.steps.splice(index, 1);
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
};
|
||||
|
||||
export const changeContent = (index, property, content) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = steps[index];
|
||||
@@ -79,5 +99,83 @@ export const changeStepIndex = (fromIndex, toIndex) => (dispatch, getState) => {
|
||||
type: BUILDER_CHANGE_ORDER,
|
||||
payload: steps
|
||||
});
|
||||
dispatch(changeErrorStepIndex(fromIndex, toIndex));
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const changeErrorStepIndex = (fromIndex, toIndex) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
var errorStep = error.steps[fromIndex];
|
||||
error.steps.splice(fromIndex, 1);
|
||||
error.steps.splice(toIndex, 0, errorStep);
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
};
|
||||
|
||||
export const setError = (index, property) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
console.log(index);
|
||||
if(index !== undefined){
|
||||
error.steps[index][property] = true;
|
||||
}
|
||||
else {
|
||||
error[property] = true;
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const deleteError = (index, property) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
if(index !== undefined){
|
||||
delete error.steps[index][property];
|
||||
}
|
||||
else {
|
||||
delete error[property];
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const setSubmitError = () => (dispatch, getState) => {
|
||||
var builder = getState().builder;
|
||||
if(builder.id === ''){
|
||||
dispatch(setError(undefined, 'id'));
|
||||
}
|
||||
if(builder.title === ''){
|
||||
dispatch(setError(undefined, 'title'));
|
||||
}
|
||||
for(var i = 0; i < builder.steps.length; i++){
|
||||
if(i === 0 && builder.steps[i].hardware.length < 1){
|
||||
dispatch(setError(i, 'hardware'));
|
||||
}
|
||||
if(builder.steps[i].headline === ''){
|
||||
dispatch(setError(i, 'headline'));
|
||||
}
|
||||
if(builder.steps[i].text === ''){
|
||||
dispatch(setError(i, 'text'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const checkError = () => (dispatch, getState) => {
|
||||
dispatch(setSubmitError());
|
||||
var error = getState().builder.error;
|
||||
if(error.id || error.title){
|
||||
return false;
|
||||
}
|
||||
for(var i = 0; i < error.steps.length; i++){
|
||||
if(Object.keys(error.steps[i]).length > 0){
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,3 +24,4 @@ export const BUILDER_DELETE_STEP = 'BUILDER_DELETE_STEP';
|
||||
export const BUILDER_CHANGE_STEP = 'BUILDER_CHANGE_STEP';
|
||||
export const BUILDER_CHANGE_ORDER = 'BUILDER_CHANGE_ORDER';
|
||||
export const BUILDER_DELETE_PROPERTY = 'BUILDER_DELETE_PROPERTY';
|
||||
export const BUILDER_ERROR = 'BUILDER_ERROR';
|
||||
|
||||
Reference in New Issue
Block a user