wishlists-actions.js
31 lines
| 1 | import { |
| 2 | fetchWishlistsStart as fetchStart, |
| 3 | fetchWishlistsSuccess as fetchSuccess, |
| 4 | fetchWishlistsFailure as fetchFailure, |
| 5 | createWishlistsStart as createStart, |
| 6 | createWishlistsSuccess as createSuccess, |
| 7 | createWishlistsFailure as createFailure, |
| 8 | } from './wishlists-reducer'; |
| 9 | import wishlistApi from '../../utils/wishlist-api' |
| 10 | |
| 11 | export const fetchWishlists = () => async ( dispatch ) => { |
| 12 | dispatch( fetchStart() ); |
| 13 | |
| 14 | try { |
| 15 | const { lists } = await wishlistApi.fetchWishlists(); |
| 16 | dispatch( fetchSuccess( { lists } ) ); |
| 17 | } catch ( error ) { |
| 18 | dispatch( fetchFailure( { error: error.message } ) ); |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | export const createWishlist = ( args ) => async ( dispatch ) => { |
| 23 | dispatch( createStart() ); |
| 24 | try { |
| 25 | const { wishlist_data: data } = await wishlistApi.createWishlists( args ); |
| 26 | dispatch( createSuccess( { data } ) ); |
| 27 | } catch ( error ) { |
| 28 | dispatch( createFailure( { error: error.message } ) ); |
| 29 | } |
| 30 | }; |
| 31 |