{"size": 1865, "ext": "js", "max_stars_repo_path": "src/forms/formReducer.js", "max_stars_repo_name": "ikanedo/react-simple-validate", "max_stars_repo_stars_event_min_datetime": "2018-02-24T05:25:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-06T12:48:38.000Z", "max_issues_repo_path": "src/forms/formReducer.js", "max_issues_repo_name": "ikanedo/react-redux-simple-validate", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/forms/formReducer.js", "max_forks_repo_name": "ikanedo/react-redux-simple-validate", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.4698795181, "max_line_length": 56, "alphanum_fraction": 0.4563002681}
import * as CONST from './formConstants';

export default function forms(state = {}, action = {}) {
  const form = state[action.formName || ''] || {};
  const formValues = form.values || {};
  const formErrors = form.errors || {};

  switch (action.type) {
    case CONST.FORM_DATA_REPLACE:
    case CONST.FORM_INITIAL_DATA:
      return {
        ...state,
        [action.formName]: {
          errors: action.errors,
          values: action.values
        }
      };
    case CONST.FORM_DATA_MERGE:
      return {
        ...state,
        [action.formName]: {
          errors: {
            ...formErrors,
            ...action.errors
          },
          values: {
            ...formValues,
            ...action.values
          }
        }
      };
    case CONST.FORM_INPUT_CHANGE:
      return {
        ...state,
        [action.formName]: {
          errors: { ...formErrors },
          values: {
            ...formValues,
            ...action.formInput
          }
        }
      };
    case CONST.FORM_RESET:
      return {
        ...state,
        [action.formName]: {
          errors: {},
          values: {}
        }
      };
    case CONST.FORM_VALIDATE:
      return {
        ...state,
        [action.formName]: {
          values: { ...formValues },
          errors: { ...action.errors }
        }
      };
    case CONST.FORM_SINGLE_VALIDATE:
      return {
        ...state,
        [action.formName]: {
          values: { ...formValues },
          errors: {
            ...formErrors,
            ...action.errors
          }
        }
      };
    case CONST.FORM_TRIGGER_VALIDATION:
      return {
        ...state,
        [action.formName]: {
          values: { ...formValues },
          errors: { ...formErrors },
          isTriggerValidation: action.trigger
        }
      };
    default:
      return state;
  }
}
