forked from vercel/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
87 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { swellConfig } from '../..' | ||
|
||
const fetchSwellApi = async ( | ||
query: string, | ||
method: string, | ||
variables: [] = [] | ||
) => { | ||
const fetchApi = async (query: string, method: string, variables: [] = []) => { | ||
const { swell } = swellConfig | ||
return await swell[query][method](...variables) | ||
return swell[query][method](...variables) | ||
} | ||
export default fetchSwellApi | ||
export default fetchApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import useCart, { UseCart } from '@commerce/cart/use-cart' | ||
import { Cart } from '@commerce/types' | ||
import { SWRHook } from '@commerce/utils/types' | ||
import { useMemo } from 'react' | ||
import { normalizeCart } from '../utils/normalize' | ||
import { checkoutCreate, checkoutToCart } from './utils' | ||
|
||
export default useCart as UseCart<typeof handler> | ||
|
||
export const handler: SWRHook<Cart | null> = { | ||
export const handler: SWRHook<Cart | null, {}, any, { isEmpty?: boolean }> = { | ||
fetchOptions: { | ||
query: 'cart', | ||
method: 'get', | ||
}, | ||
async fetcher({ options, fetch }) { | ||
async fetcher({ fetch }) { | ||
const cart = await checkoutCreate(fetch) | ||
|
||
return cart ? normalizeCart(cart) : null | ||
}, | ||
useHook: ({ useData }) => (input) => { | ||
return useData({ | ||
swrOptions: { | ||
revalidateOnFocus: false, | ||
...input?.swrOptions, | ||
}, | ||
const response = useData({ | ||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, | ||
}) | ||
return useMemo( | ||
() => | ||
Object.create(response, { | ||
isEmpty: { | ||
get() { | ||
return (response.data?.lineItems.length ?? 0) <= 0 | ||
}, | ||
enumerable: true, | ||
}, | ||
}), | ||
[response] | ||
) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.