-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added useCart hook #92
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useCartTotals, useCartData, useUpdateCartItemQuantity, useRemoveItemFromCart } from '~/api/api-hooks'; | ||
import { useEcomAPI } from '~/api/ecom-api-context-provider'; | ||
|
||
export const useCart = () => { | ||
const ecomAPI = useEcomAPI(); | ||
const { data: cartData } = useCartData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it would be better to rename values returned from hooks to not rename it during assignment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't do that, because it's a |
||
const { data: cartTotals } = useCartTotals(); | ||
const { trigger: updateItemQuantity } = useUpdateCartItemQuantity(); | ||
const { trigger: removeItem } = useRemoveItemFromCart(); | ||
|
||
const checkout = async () => { | ||
const checkoutResponse = await ecomAPI.checkout(); | ||
|
||
if (checkoutResponse.status === 'success') { | ||
window.location.href = checkoutResponse.body.checkoutUrl; | ||
} else { | ||
alert('checkout is not configured'); | ||
} | ||
}; | ||
|
||
return { | ||
cartData, | ||
cartTotals, | ||
updateItemQuantity, | ||
removeItem, | ||
checkout, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type? or is it too verbose for such return data ?