import { toast } from "react-toastify"; const initialState = { loading: false, error: null, list: [], info: null, sum: null, checkEmpty: false, hasPhysical: false, }; export default function userFactor(state = initialState, action) { let { type, data } = action; switch (type) { case "userProduct/list": const checkEmpty = data.filter( (item) => item.condition === 2 ); 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/update": return { ...state, loading: false, error: null }; case "userProduct/add": 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; } }