parent
							
								
									ba0f1125b9
								
							
						
					
					
						commit
						b6c32a8dfa
					
				
				 11 changed files with 160 additions and 70 deletions
			
			
		| @ -0,0 +1,31 @@ | |||||||
|  | import proxy from "../proxy"; | ||||||
|  | const userFactor = { | ||||||
|  |   list: | ||||||
|  |     (data = {}) => | ||||||
|  |     async (dispatch) => | ||||||
|  |       await proxy.get("userFactor/list", data, { dispatch }), | ||||||
|  |   info: | ||||||
|  |     (data = {}) => | ||||||
|  |     async (dispatch) => | ||||||
|  |       await proxy.get("userFactor/info", data, { dispatch }), | ||||||
|  |   update: | ||||||
|  |     (data = {}, data2 = {}) => | ||||||
|  |     async (dispatch) => { | ||||||
|  |       await proxy.put("userFactor/update", data); | ||||||
|  |       await proxy.get("userFactor/list", data2, { dispatch }); | ||||||
|  |     }, | ||||||
|  |   add: | ||||||
|  |     (data = {}, data2 = {}) => | ||||||
|  |     async (dispatch) => { | ||||||
|  |       await proxy.post("userFactor/add", data, { dispatch }); | ||||||
|  |       await proxy.get("userFactor/list", data2, { dispatch }); | ||||||
|  |     }, | ||||||
|  |   del: | ||||||
|  |     (data = {}, data2 = {}) => | ||||||
|  |     async (dispatch) => { | ||||||
|  |       await proxy.delete("userFactor/delete", data); | ||||||
|  |       await proxy.get("userFactor/list", data2, { dispatch }); | ||||||
|  |     }, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default userFactor; | ||||||
| @ -0,0 +1,44 @@ | |||||||
|  | import { toast } from "react-toastify"; | ||||||
|  | 
 | ||||||
|  | const initialState = { | ||||||
|  |   loading: false, | ||||||
|  |   error: null, | ||||||
|  |   list: [], | ||||||
|  |   info: null, | ||||||
|  |   sum: null, | ||||||
|  |   checkEmpty: false, | ||||||
|  | }; | ||||||
|  | export default function userFactor(state = initialState, action) { | ||||||
|  |   let { type, data, message } = action; | ||||||
|  |   switch (type) { | ||||||
|  |     case "userFactor/list": | ||||||
|  |       const checkEmpty = data.filter( | ||||||
|  |         (item) => item.condition === 2 && item.product.productType === (1 || 3) | ||||||
|  |       ); | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         loading: false, | ||||||
|  |         list: data, | ||||||
|  |         checkEmpty: checkEmpty.length > 0 ? false : true, | ||||||
|  |         error: null, | ||||||
|  |       }; | ||||||
|  |     case "userFactor/info": | ||||||
|  |       return { ...state, loading: false, info: data, error: null }; | ||||||
|  |     case "userFactor/update": | ||||||
|  |       return { ...state, loading: false, error: null }; | ||||||
|  |     case "userFactor/add": | ||||||
|  |       console.log(data); | ||||||
|  |       toast.success("درخواست شما با موفقیت انجام شد."); | ||||||
|  |       return { ...state, loading: false, error: null, sum: data.payPrice }; | ||||||
|  |     case "userFactor/delete": | ||||||
|  |       return { ...state, loading: false, error: null }; | ||||||
|  |     /////////////
 | ||||||
|  |     case "loading": | ||||||
|  |       return { ...state, loading: true }; | ||||||
|  |     case "error": | ||||||
|  |       toast.error(data.message); | ||||||
|  |       return { ...state, loading: false, error: data.message }; | ||||||
|  |     default: | ||||||
|  |       return state; | ||||||
|  |   } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue