import { toast } from "react-toastify"; const initialState = { loading: false, error: null, list: null, info: null, sum: null, checkEmpty: false, hasPhysical: false, myList: null, }; export default function userProduct(state = initialState, action) { let { type, data } = action; switch (type) { case "userProduct/list": const checkEmpty = data.filter( (item) => item.condition === 2 && item.product.productType === (1 || 3) ); const hasPhysical = data.filter((item) => item.product.productType === 2).length > 0 ? true : false; return { ...state, loading: false, list: data, checkEmpty: checkEmpty.length > 0 ? false : true, error: null, hasPhysical: hasPhysical, }; case "userProduct/info": return { ...state, loading: false, info: data, error: null }; case "userProduct/myList": return { ...state, loading: false, myList: data, error: null }; case "userProduct/update": return { ...state, loading: false, error: null }; case "userProduct/add": if (window.location.pathname.indexOf("products") !== -1) { toast.success("درخواست شما با موفقیت انجام شد."); } return { ...state, loading: false, error: null, sum: data.payPrice }; case "userProduct/delete": return { ...state, loading: false, error: null }; case "userProduct/loading": return { ...state, loading: true }; case "userProduct/error": toast.error(data.message); return { ...state, loading: false, error: data.message }; default: return state; } }