const initialState = { homeData: [], faqList: [], loading: true, error: null, searchResult: [], contactData: null, }; export default function publicApi(state = initialState, action) { let { type, data } = action; switch (type) { case "public/homePage": return { ...state, loading: false, error: null, homeData: data }; case "public/faq": return { ...state, loading: false, error: null, faqList: data }; case "public/faq/activate": return { ...state, loading: false, error: null, faqList: state.faqList.map((item) => item.id === data ? { ...item, active: !item.active } : { ...item, active: false } ), }; case "public/faq/search": console.log(data); return { ...state, loading: false, error: null, searchResult: state.faqList.filter( (item) => item.title.indexOf(data) !== -1 || item.description.indexOf(data) !== -1 ), }; case "public/contact": return { ...state, loading: false, error: null, contactData: data }; case "loading": return { ...state, loading: true }; case "error": return { ...state, loading: false, error: data.message }; default: return state; } }