ScreeningResults

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.0 kB
2
Indexable
Never
import { initializer } from "../helpers/functions";
import { categories } from "../services/londi-constants";

export const screeningResultsReducer = (state = initializer, action) => {
  switch (action.type) {
    case "classOptions":
      return { ...state, options: "classOptions" };
    case "schoolGrade":
      return {
        ...state,
        schoolGrade: action.payload,
        options: "",
      };
    case "testTimeOptions":
      return { ...state, options: "testTimeOptions" };
    case "testTime":
      return {
        ...state,
        testTime: action.payload,
        options: "",
      };
    case "options":
      return {
        ...state,
        options: "",
      };
    case "clearReading":
      return {
        ...state,
        screeningResultReading: undefined,
      };
    case "clearWriting":
      return {
        ...state,
        screeningResultWriting: undefined,
      };
    case "clearCounting":
      return {
        ...state,
        screeningResultCounting: undefined,
      };
    case "germanNativeOptions":
      return { ...state, options: "germanNativeOptions" };
    case "germanSecondaryLanguage":
      return {
        ...state,
        germanSecondaryLanguage: action.payload,
        options: "",
      };
    case "screenResultsEstimated":
      return {
        ...state,
        screenResultsEstimated: action.payload,
        options: "",
      };
    case "readingOptions":
      return { ...state, options: "readingOptions" };
    case "readingSecondTestOptions":
      return { ...state, options: "readingSecondTestOptions" };
    case "reading":
      return {
        ...state,
        screeningResultReading: {
          category: categories.Reading,
          result: action.payload,
        },
        options: "",
      };
    case "writingOptions":
      return { ...state, options: "writingOptions" };
    case "writing":
      return {
        ...state,
        screeningResultWriting: {
          category: categories.Writing,
          result: action.payload,
        },
        options: "",
      };
    case "countingOptions":
      return { ...state, options: "countingOptions" };
    case "counting":
      return {
        ...state,
        screeningResultCounting: {
          category: categories.Math,
          result: action.payload,
        },
        options: "",
      };
    case "ageOptions":
      return { ...state, options: "ageOptions" };
    case "age":
      return {
        ...state,
        age: action.payload,
        options: "",
      };
    case "valueOptions":
      return {
        ...state,
        options: "valueOptions",
        selectedValue: action.payload.id,
      };
    case "value":
      const { key, value } = action.payload;
      return {
        ...state,
        value: { ...state.value, [key]: value },
        options: "",
      };
    case "readingTest":
      return {
        ...state,
        readingResults: action.payload,
        options: "",
      };
    case "readingTestId":
      return {
        ...state,
        readingTestId: action.payload,
        options: "",
      };
    case "readingSecondTest":
      return {
        ...state,
        readingSecondTestResults: action.payload,
        options: "",
      };
    case "readingSecondTestId":
      return {
        ...state,
        readingSecondTestId: action.payload,
        options: "",
      };
    case "writingTest":
      return {
        ...state,
        writingResults: action.payload,
        options: "",
      };
    case "writingTestId":
      return {
        ...state,
        writingTestId: action.payload,
        options: "",
      };
    case "countingTest":
      return {
        ...state,
        countingResults: action.payload,
        options: "",
      };
    case "countingTestId":
      return {
        ...state,
        countingTestId: action.payload,
        options: "",
      };
    default:
      return state;
  }
};