You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
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; |
|
} |
|
}
|
|
|