import { ASK } from 'constants';
import { grabValue } from './utils.reducer';

const initialState = {
    data: {},
};

export default function reducer(state = initialState, action) {

    switch (action.type) {

        case ASK:
        return {
            ...state,
            data: {
                ...state.data,
                ...action.payload.items.reduce((existing, ask) => {

                    if(ask.question) {

                        let code = ask.question.code;

                        existing[code] = {
                          ...state.data[code],
                          ...ask,
                          question: {
                              ...ask.question,
                              validationList: [
                                  ...(ask.question.attribute.dataType.validationList ? ask.question.attribute.dataType.validationList : [])
                              ],
                              type: ask.question.attribute.dataType.className,
                              attributeCode: ask.question.attribute.code
                          },
                          answerList: {
                              ...(state.data[code] ? state.data[code].answerList : {}),
                              ...ask.answerList,
                              answerList: [
                                  ...(state.data[code] ? (state.data[code].answerList ? state.data[code].answerList : {}).answerList : []),
                                  ...ask.answerList.answerList.map((existing, newAnswer) => {

                                     existing.value = grabValue(existing);
                                     return existing;
                                  })
                              ]
                          }
                        };
                    }

                  return existing;

                }, {}),
            }
        };

        default:
        return state;
    }
}

@@ -1064,691 +1064,8 @@
 ode%0A
-                          %7D,%0A                          answerList: %7B%0A                              ...(state.data%5Bcode%5D ? state.data%5Bcode%5D.answerList : %7B%7D),%0A                              ...ask.answerList,%0A                              answerList: %5B%0A                                  ...(state.data%5Bcode%5D ? (state.data%5Bcode%5D.answerList ? state.data%5Bcode%5D.answerList : %7B%7D).answerList : %5B%5D),%0A                                  ...ask.answerList.answerList.map((existing, newAnswer) =%3E %7B%0A%0A                                     existing.value = grabValue(existing);%0A                                     return existing;%0A                                  %7D)%0A                              %5D%0A
     

Update ask.reducer.js