forked from crowetic/commerce
update remove item from cart, landing page fetch, image normalization
This commit is contained in:
parent
d0a04a8fe9
commit
abd86329d5
@ -31,27 +31,30 @@ export default useRemoveItem as UseRemoveItem<typeof handler>
|
||||
|
||||
export const handler = {
|
||||
fetchOptions: {
|
||||
query: checkoutLineItemRemoveMutation,
|
||||
query: 'cart',
|
||||
method: 'removeItem',
|
||||
},
|
||||
async fetcher({
|
||||
input: { itemId },
|
||||
options,
|
||||
fetch,
|
||||
}: HookFetcherContext<RemoveCartItemBody>) {
|
||||
const data = await fetch<Mutation, MutationCheckoutLineItemsRemoveArgs>({
|
||||
...options,
|
||||
variables: { checkoutId: getCheckoutId(), lineItemIds: [itemId] },
|
||||
})
|
||||
return checkoutToCart(data.checkoutLineItemsRemove)
|
||||
const response = await fetch<Mutation, MutationCheckoutLineItemsRemoveArgs>(
|
||||
{
|
||||
...options,
|
||||
variables: [itemId],
|
||||
}
|
||||
)
|
||||
return checkoutToCart(response)
|
||||
},
|
||||
useHook: ({
|
||||
fetch,
|
||||
}: MutationHookContext<Cart | null, RemoveCartItemBody>) => <
|
||||
T extends LineItem | undefined = undefined
|
||||
>(
|
||||
ctx: { item?: T } = {}
|
||||
item
|
||||
) => {
|
||||
const { item } = ctx
|
||||
// const { item } = ctx
|
||||
const { mutate } = useCart()
|
||||
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
||||
const itemId = input?.id ?? item?.id
|
||||
|
@ -21,9 +21,10 @@ const getAllProducts = async (options: {
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
const { results } = await config.fetchSwell('products', 'get')
|
||||
const { results } = await config.fetchSwell('products', 'list', {
|
||||
limit: variables.first,
|
||||
})
|
||||
const products = results.map((product) => normalizeProduct(product)) ?? []
|
||||
|
||||
return {
|
||||
products,
|
||||
}
|
||||
|
@ -46,11 +46,25 @@ const normalizeProductOption = ({
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeProductImages = (images) =>
|
||||
images?.map(({ file, id }) => ({
|
||||
url: file.url,
|
||||
id,
|
||||
type SwellImage = {
|
||||
file: {
|
||||
url: String
|
||||
height: Number
|
||||
width: Number
|
||||
}
|
||||
id: string
|
||||
}
|
||||
const normalizeProductImages = (images) => {
|
||||
if (!images) {
|
||||
return [{ url: '/' }]
|
||||
}
|
||||
return images?.map(({ file, ...rest }: SwellImage) => ({
|
||||
url: file?.url,
|
||||
height: file.height,
|
||||
width: file.width,
|
||||
...rest,
|
||||
}))
|
||||
}
|
||||
|
||||
const normalizeProductVariants = (variants) => {
|
||||
return variants?.map(({ id, name, values, price, stock_status }) => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user