Changeset 16237c4 for frontend/src/Store.js
- Timestamp:
- 09/08/22 12:38:24 (22 months ago)
- Branches:
- master
- Children:
- ee05663
- Parents:
- 717ceae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/Store.js
r717ceae r16237c4 4 4 5 5 const initialState = { 6 userInfo: localStorage.getItem("userInfo") 7 ? JSON.parse(localStorage.getItem("userInfo")) 8 : null, 6 9 cart: { 10 shippingAddress: localStorage.getItem("shippingAddress") 11 ? JSON.parse(localStorage.getItem("shippingAddress")) 12 : {}, 13 paymentMethod: localStorage.getItem("paymentMethod") 14 ? localStorage.getItem("paymentMethod") 15 : "", 7 16 cartItems: localStorage.getItem("cartItems") 8 17 ? JSON.parse(localStorage.getItem("cartItems")) … … 32 41 return { ...state, cart: { ...state.cart, cartItems } }; 33 42 } 43 case "CART_CLEAR": 44 return { ...state, cart: { ...state.cart, cartItems: [] } }; 45 case "USER_SIGNIN": 46 return { ...state, userInfo: action.payload }; 47 case "USER_SIGNOUT": 48 return { 49 ...state, 50 userInfo: null, 51 cart: { cartItems: [], shippingAddress: {}, paymentMethod: "" }, 52 }; 53 case "SAVE_SHIPPING_ADDRESS": 54 return { 55 ...state, 56 cart: { ...state.cart, shippingAddress: action.payload }, 57 }; 58 case "SAVE_PAYMENT_METHOD": 59 return { 60 ...state, 61 cart: { ...state.cart, paymentMethod: action.payload }, 62 }; 34 63 default: 35 64 return state;
Note:
See TracChangeset
for help on using the changeset viewer.