Hook changes
This commit is contained in:
19
lib/bigcommerce/cart/use-add-item.tsx
Normal file
19
lib/bigcommerce/cart/use-add-item.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Fetcher } from '@lib/commerce'
|
||||
import { default as useCartAddItem } from '@lib/commerce/cart/use-add-item'
|
||||
import { Cart } from '.'
|
||||
|
||||
async function fetcher(fetch: Fetcher<Cart>, { item }: { item: any }) {
|
||||
const res = await fetch({ url: '/api/cart' })
|
||||
|
||||
// {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// },
|
||||
// body: JSON.stringify({ product }),
|
||||
// }
|
||||
}
|
||||
|
||||
export default function useAddItem() {
|
||||
return useCartAddItem<Cart, { item: any }>(fetcher)
|
||||
}
|
||||
@@ -21,19 +21,17 @@ async function getError(res: Response) {
|
||||
return { message: await getText(res) }
|
||||
}
|
||||
|
||||
async function fetcher(url: string, query: string) {
|
||||
const res = await fetch(url)
|
||||
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
throw await getError(res)
|
||||
}
|
||||
|
||||
export const bigcommerceConfig: CommerceConfig = {
|
||||
locale: 'en-us',
|
||||
fetcher,
|
||||
async fetcher({ url, query }) {
|
||||
const res = await fetch(url!)
|
||||
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
throw await getError(res)
|
||||
},
|
||||
}
|
||||
|
||||
export type BigcommerceConfig = Partial<CommerceConfig>
|
||||
|
||||
Reference in New Issue
Block a user