mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 06:56:59 +00:00
Fix build failed for all providers (#9)
* Update type for cart data Signed-off-by: Chloe <pinkcloudvnn@gmail.com> * Fix build fails for all providers Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
parent
eca79f89aa
commit
c92eac49ec
17
packages/bigcommerce/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/bigcommerce/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@ -12,11 +12,13 @@ export type Navigation = any
|
|||||||
export type SiteTypes = {
|
export type SiteTypes = {
|
||||||
category: Category
|
category: Category
|
||||||
brand: Brand
|
brand: Brand
|
||||||
|
navigation?: Navigation
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetSiteInfoOperation<T extends SiteTypes = SiteTypes> = {
|
export type GetSiteInfoOperation<T extends SiteTypes = SiteTypes> = {
|
||||||
data: {
|
data: {
|
||||||
categories: T['category'][]
|
categories: T['category'][]
|
||||||
brands: T['brand'][]
|
brands: T['brand'][]
|
||||||
|
navigation?: T['navigation'][]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
packages/commercejs/src/customer/address/use-update-item.tsx
Normal file
17
packages/commercejs/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/kibocommerce/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/kibocommerce/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@ -15,14 +15,14 @@ const updateItem: CustomerAddressEndpoint['handlers']['updateItem'] = async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.shippingMethod) {
|
if (item.shippingMethodId) {
|
||||||
await fetch(selectFulfillmentOptions, {
|
await fetch(selectFulfillmentOptions, {
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
cartId,
|
cartId,
|
||||||
cartToken: cookies[anonymousCartTokenCookie],
|
cartToken: cookies[anonymousCartTokenCookie],
|
||||||
fulfillmentGroupId: item.shippingMethod.fulfillmentGroupId,
|
fulfillmentGroupId: item.fulfillmentGroupId,
|
||||||
fulfillmentMethodId: item.shippingMethod.id,
|
fulfillmentMethodId: item.shippingMethodId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -9,6 +9,7 @@ import useSubmitCheckout from './use-submit-checkout'
|
|||||||
import { useCheckoutContext } from '@components/checkout/context'
|
import { useCheckoutContext } from '@components/checkout/context'
|
||||||
import { AddressFields } from '../types/customer/address'
|
import { AddressFields } from '../types/customer/address'
|
||||||
import { useCart } from '../cart'
|
import { useCart } from '../cart'
|
||||||
|
import { FulfillmentGroup } from '../types/cart'
|
||||||
|
|
||||||
export default useCheckout as UseCheckout<typeof handler>
|
export default useCheckout as UseCheckout<typeof handler>
|
||||||
|
|
||||||
@ -30,13 +31,20 @@ export const handler: SWRHook<GetCheckoutHook> = {
|
|||||||
|
|
||||||
const { addressFields } = useCheckoutContext()
|
const { addressFields } = useCheckoutContext()
|
||||||
|
|
||||||
const { shippingMethod, ...restAddressFields } =
|
const { shippingMethodId, ...restAddressFields } =
|
||||||
addressFields as AddressFields
|
addressFields as AddressFields
|
||||||
|
|
||||||
const hasEnteredAddress = Object.values(restAddressFields).some(
|
const hasEnteredAddress = Object.values(restAddressFields).some(
|
||||||
(fieldValue) => !!fieldValue
|
(fieldValue) => !!fieldValue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const totalAmount =
|
||||||
|
cart?.checkout?.summary.fulfillmentTotal?.displayAmount
|
||||||
|
|
||||||
|
const shippingGroup = cart?.checkout?.fulfillmentGroups.find(
|
||||||
|
(group: FulfillmentGroup) => group?.type === 'shipping'
|
||||||
|
)
|
||||||
|
|
||||||
const response = useMemo(
|
const response = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
data: {
|
data: {
|
||||||
@ -44,10 +52,18 @@ export const handler: SWRHook<GetCheckoutHook> = {
|
|||||||
hasPayment: true,
|
hasPayment: true,
|
||||||
hasShipping: hasEnteredAddress,
|
hasShipping: hasEnteredAddress,
|
||||||
hasShippingMethods,
|
hasShippingMethods,
|
||||||
hasSelectedShippingMethod: !!shippingMethod?.id,
|
hasSelectedShippingMethod: !!shippingMethodId,
|
||||||
|
totalAmount,
|
||||||
|
shippingGroup,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[hasEnteredAddress, hasShippingMethods, shippingMethod]
|
[
|
||||||
|
hasEnteredAddress,
|
||||||
|
hasShippingMethods,
|
||||||
|
shippingMethodId,
|
||||||
|
totalAmount,
|
||||||
|
shippingGroup,
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
|
@ -6,6 +6,7 @@ import useUpdateItem, {
|
|||||||
} from '@vercel/commerce/customer/address/use-update-item'
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
import { useCheckoutContext } from '@components/checkout/context'
|
import { useCheckoutContext } from '@components/checkout/context'
|
||||||
import { CustomerAddressTypes } from '../../types/customer/address'
|
import { CustomerAddressTypes } from '../../types/customer/address'
|
||||||
|
import { useCart } from '../../cart'
|
||||||
|
|
||||||
export default useUpdateItem as UseUpdateItem<typeof handler>
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
@ -24,14 +25,21 @@ export const handler: MutationHook<UpdateItemHook<CustomerAddressTypes>> = {
|
|||||||
},
|
},
|
||||||
useHook: ({ fetch }) =>
|
useHook: ({ fetch }) =>
|
||||||
function useHook() {
|
function useHook() {
|
||||||
|
const { data: cart } = useCart()
|
||||||
|
|
||||||
const { setAddressFields, addressFields } = useCheckoutContext()
|
const { setAddressFields, addressFields } = useCheckoutContext()
|
||||||
return useCallback(
|
return useCallback(
|
||||||
async function updateItem(input) {
|
async function updateItem(input) {
|
||||||
const { id, ...rest } = input
|
const { id, ...rest } = input
|
||||||
await fetch({ input: { item: rest, itemId: id } })
|
const fulfillmentGroupId =
|
||||||
|
cart?.checkout?.fulfillmentGroups[0]._id || 'groupId'
|
||||||
|
await fetch({
|
||||||
|
input: { item: { ...rest, fulfillmentGroupId }, itemId: id },
|
||||||
|
})
|
||||||
setAddressFields({
|
setAddressFields({
|
||||||
...addressFields,
|
...addressFields,
|
||||||
shippingMethod: rest.shippingMethod,
|
shippingMethodId: rest.shippingMethodId,
|
||||||
|
fulfillmentGroupId,
|
||||||
})
|
})
|
||||||
return undefined
|
return undefined
|
||||||
},
|
},
|
||||||
|
@ -3,10 +3,8 @@ import * as Core from '@vercel/commerce/types/customer/address'
|
|||||||
export * from '@vercel/commerce/types/customer/address'
|
export * from '@vercel/commerce/types/customer/address'
|
||||||
|
|
||||||
export type AddressFields = Core.AddressFields & {
|
export type AddressFields = Core.AddressFields & {
|
||||||
shippingMethod?: {
|
shippingMethodId?: string
|
||||||
id: string
|
fulfillmentGroupId?: string
|
||||||
fulfillmentGroupId: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CustomerAddressTypes = Core.CustomerAddressTypes & {
|
export type CustomerAddressTypes = Core.CustomerAddressTypes & {
|
||||||
|
17
packages/saleor/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/saleor/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/saleor/src/customer/address/use-update-item.tsx
Normal file
17
packages/saleor/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/sfcc/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/sfcc/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/sfcc/src/customer/address/use-update-item.tsx
Normal file
17
packages/sfcc/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/shopify/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/shopify/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/shopify/src/customer/address/use-update-item.tsx
Normal file
17
packages/shopify/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/spree/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/spree/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/spree/src/customer/address/use-update-item.tsx
Normal file
17
packages/spree/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/swell/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/swell/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/swell/src/customer/address/use-update-item.tsx
Normal file
17
packages/swell/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/vendure/src/checkout/use-submit-checkout.tsx
Normal file
17
packages/vendure/src/checkout/use-submit-checkout.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useSubmitCheckout, {
|
||||||
|
UseSubmitCheckout,
|
||||||
|
} from '@vercel/commerce/checkout/use-submit-checkout'
|
||||||
|
|
||||||
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
17
packages/vendure/src/customer/address/use-update-item.tsx
Normal file
17
packages/vendure/src/customer/address/use-update-item.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||||
|
import useUpdateItem, {
|
||||||
|
UseUpdateItem,
|
||||||
|
} from '@vercel/commerce/customer/address/use-update-item'
|
||||||
|
|
||||||
|
export default useUpdateItem as UseUpdateItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@ -113,9 +113,7 @@ const CheckoutSidebarView: FC = () => {
|
|||||||
{checkoutData?.hasSelectedShippingMethod ? (
|
{checkoutData?.hasSelectedShippingMethod ? (
|
||||||
<li className="flex justify-between py-1">
|
<li className="flex justify-between py-1">
|
||||||
<span>Shipping</span>
|
<span>Shipping</span>
|
||||||
<span>
|
<span>{checkoutData?.totalAmount}</span>
|
||||||
{cartData?.checkout?.summary.fulfillmentTotal?.displayAmount}
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
) : (
|
) : (
|
||||||
<li className="flex justify-between py-1">
|
<li className="flex justify-between py-1">
|
||||||
|
@ -3,14 +3,9 @@ import useUpdateUpdateAddress from '@framework/customer/address/use-update-item'
|
|||||||
import SidebarLayout from '@components/common/SidebarLayout'
|
import SidebarLayout from '@components/common/SidebarLayout'
|
||||||
import { useUI } from '@components/ui/context'
|
import { useUI } from '@components/ui/context'
|
||||||
import { Button } from '@components/ui'
|
import { Button } from '@components/ui'
|
||||||
|
import useCheckout from '@framework/checkout/use-checkout'
|
||||||
import { useCheckoutContext } from '../context'
|
import { useCheckoutContext } from '../context'
|
||||||
|
|
||||||
type FulfillmentGroup = {
|
|
||||||
type: string
|
|
||||||
_id: string
|
|
||||||
availableFulfillmentOptions: FulfillmentOption[] | null
|
|
||||||
}
|
|
||||||
|
|
||||||
type FulfillmentOption = {
|
type FulfillmentOption = {
|
||||||
fulfillmentMethod?: {
|
fulfillmentMethod?: {
|
||||||
_id: string
|
_id: string
|
||||||
@ -28,9 +23,7 @@ const ShippingMethod = () => {
|
|||||||
const { addressFields } = useCheckoutContext()
|
const { addressFields } = useCheckoutContext()
|
||||||
|
|
||||||
const updateShippingMethod = useUpdateUpdateAddress()
|
const updateShippingMethod = useUpdateUpdateAddress()
|
||||||
const shippingGroup = cart?.checkout?.fulfillmentGroups.find(
|
const { data: checkoutData } = useCheckout()
|
||||||
(group: FulfillmentGroup) => group?.type === 'shipping'
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleSubmit = async (event: React.ChangeEvent<HTMLFormElement>) => {
|
const handleSubmit = async (event: React.ChangeEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -38,17 +31,13 @@ const ShippingMethod = () => {
|
|||||||
await updateShippingMethod({
|
await updateShippingMethod({
|
||||||
id: cart!.id,
|
id: cart!.id,
|
||||||
...addressFields,
|
...addressFields,
|
||||||
shippingMethod: {
|
shippingMethodId: event.target.shippingMethod.value,
|
||||||
fulfillmentGroupId:
|
|
||||||
cart!.checkout?.fulfillmentGroups[0]?._id ?? 'groupId',
|
|
||||||
id: event.target.shippingMethod.value,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setSidebarView('CHECKOUT_VIEW')
|
setSidebarView('CHECKOUT_VIEW')
|
||||||
}
|
}
|
||||||
|
|
||||||
return shippingGroup ? (
|
return checkoutData.shippingGroup ? (
|
||||||
<form className="h-full" onSubmit={handleSubmit}>
|
<form className="h-full" onSubmit={handleSubmit}>
|
||||||
<SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}>
|
<SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}>
|
||||||
<div className="px-4 sm:px-6 flex-1">
|
<div className="px-4 sm:px-6 flex-1">
|
||||||
@ -56,7 +45,7 @@ const ShippingMethod = () => {
|
|||||||
Shipping Methods
|
Shipping Methods
|
||||||
</h2>
|
</h2>
|
||||||
<div>
|
<div>
|
||||||
{shippingGroup.availableFulfillmentOptions?.map(
|
{checkoutData.shippingGroup.availableFulfillmentOptions?.map(
|
||||||
(option: FulfillmentOption) => (
|
(option: FulfillmentOption) => (
|
||||||
<div
|
<div
|
||||||
className="flex flex-row my-3 items-center justify-between"
|
className="flex flex-row my-3 items-center justify-between"
|
||||||
@ -69,7 +58,7 @@ const ShippingMethod = () => {
|
|||||||
type="radio"
|
type="radio"
|
||||||
value={option?.fulfillmentMethod?._id}
|
value={option?.fulfillmentMethod?._id}
|
||||||
defaultChecked={
|
defaultChecked={
|
||||||
shippingGroup.selectedFulfillmentOption
|
checkoutData.shippingGroup.selectedFulfillmentOption
|
||||||
?.fulfillmentMethod?._id ===
|
?.fulfillmentMethod?._id ===
|
||||||
option?.fulfillmentMethod?._id
|
option?.fulfillmentMethod?._id
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,11 @@ const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
|||||||
await addItem({
|
await addItem({
|
||||||
productId: String(product.id),
|
productId: String(product.id),
|
||||||
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
||||||
|
// Open Commerce provider only
|
||||||
|
...({
|
||||||
variant: variant ?? product.variants[0],
|
variant: variant ?? product.variants[0],
|
||||||
currencyCode: String(product.price.currencyCode),
|
currencyCode: String(product.price.currencyCode),
|
||||||
|
} as any),
|
||||||
})
|
})
|
||||||
openSidebar()
|
openSidebar()
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user