mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Merge pull request #7 from reactioncommerce/fix-failed-build
Fix typing error
This commit is contained in:
commit
1cfca949ef
@ -5,9 +5,7 @@ import type {
|
|||||||
HookFetcherContext,
|
HookFetcherContext,
|
||||||
} from '@vercel/commerce/utils/types'
|
} from '@vercel/commerce/utils/types'
|
||||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||||
import useUpdateItem, {
|
import useUpdateItem, { UseUpdateItem } from '@vercel/commerce/cart/use-update-item'
|
||||||
UseUpdateItem,
|
|
||||||
} from '@vercel/commerce/cart/use-update-item'
|
|
||||||
import type { LineItem, UpdateItemHook } from '@vercel/commerce/types/cart'
|
import type { LineItem, UpdateItemHook } from '@vercel/commerce/types/cart'
|
||||||
import { handler as removeItemHandler } from './use-remove-item'
|
import { handler as removeItemHandler } from './use-remove-item'
|
||||||
import useCart from './use-cart'
|
import useCart from './use-cart'
|
||||||
|
@ -7,6 +7,7 @@ import useCheckout, {
|
|||||||
} from '@vercel/commerce/checkout/use-checkout'
|
} from '@vercel/commerce/checkout/use-checkout'
|
||||||
import useSubmitCheckout from './use-submit-checkout'
|
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 { useCart } from '../cart'
|
import { useCart } from '../cart'
|
||||||
|
|
||||||
export default useCheckout as UseCheckout<typeof handler>
|
export default useCheckout as UseCheckout<typeof handler>
|
||||||
@ -25,11 +26,12 @@ export const handler: SWRHook<GetCheckoutHook> = {
|
|||||||
(group) => group?.type === 'shipping'
|
(group) => group?.type === 'shipping'
|
||||||
)
|
)
|
||||||
const hasShippingMethods =
|
const hasShippingMethods =
|
||||||
!!shippingTypeMethod?.availableFulfillmentOptions.length
|
!!shippingTypeMethod?.availableFulfillmentOptions?.length
|
||||||
|
|
||||||
const { addressFields } = useCheckoutContext()
|
const { addressFields } = useCheckoutContext()
|
||||||
|
|
||||||
const { shippingMethod, ...restAddressFields } = addressFields
|
const { shippingMethod, ...restAddressFields } =
|
||||||
|
addressFields as AddressFields
|
||||||
|
|
||||||
const hasEnteredAddress = Object.values(restAddressFields).some(
|
const hasEnteredAddress = Object.values(restAddressFields).some(
|
||||||
(fieldValue) => !!fieldValue
|
(fieldValue) => !!fieldValue
|
||||||
|
@ -1,9 +1,30 @@
|
|||||||
import * as Core from '@vercel/commerce/types/cart'
|
import * as Core from '@vercel/commerce/types/cart'
|
||||||
import { Checkout } from '../../schema'
|
import {
|
||||||
|
Checkout as CheckoutSchema,
|
||||||
|
FulfillmentOption as FulfillmentOptionSchema,
|
||||||
|
FulfillmentGroup as FulfillmentGroupSchema,
|
||||||
|
} from '../../schema'
|
||||||
import { ProductVariant } from './product'
|
import { ProductVariant } from './product'
|
||||||
|
|
||||||
export * from '@vercel/commerce/types/cart'
|
export * from '@vercel/commerce/types/cart'
|
||||||
|
|
||||||
|
type FulfillmentOption = FulfillmentOptionSchema & {
|
||||||
|
fulfillmentMethod?: NonNullable<FulfillmentOptionSchema['fulfillmentMethod']>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FulfillmentGroup = {
|
||||||
|
availableFulfillmentOptions: FulfillmentOption[] | null
|
||||||
|
selectedFulfillmentOption: FulfillmentOption | null
|
||||||
|
data: FulfillmentGroupSchema['data']
|
||||||
|
type: string
|
||||||
|
_id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Checkout = {
|
||||||
|
fulfillmentGroups: FulfillmentGroup[]
|
||||||
|
summary: CheckoutSchema['summary']
|
||||||
|
}
|
||||||
|
|
||||||
export type Cart = Core.Cart & {
|
export type Cart = Core.Cart & {
|
||||||
checkout?: Checkout
|
checkout?: Checkout
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,9 @@ import {
|
|||||||
Cart as OCCart,
|
Cart as OCCart,
|
||||||
CartItemEdge,
|
CartItemEdge,
|
||||||
NavigationTreeItem,
|
NavigationTreeItem,
|
||||||
|
Checkout as OCCheckout,
|
||||||
} from '../../schema'
|
} from '../../schema'
|
||||||
import { Cart, LineItem } from '../types/cart'
|
import { Cart, Checkout, LineItem, FulfillmentGroup } from '../types/cart'
|
||||||
|
|
||||||
const normalizeProductImages = (images: ImageInfo[], name: string) =>
|
const normalizeProductImages = (images: ImageInfo[], name: string) =>
|
||||||
images.map((image) => ({
|
images.map((image) => ({
|
||||||
@ -256,7 +257,32 @@ export function normalizeCart(cart: OCCart): Cart {
|
|||||||
totalPrice: cart.checkout?.summary?.total?.amount ?? 0,
|
totalPrice: cart.checkout?.summary?.total?.amount ?? 0,
|
||||||
discounts: [],
|
discounts: [],
|
||||||
taxesIncluded: !!cart.checkout?.summary?.taxTotal?.amount,
|
taxesIncluded: !!cart.checkout?.summary?.taxTotal?.amount,
|
||||||
checkout: cart.checkout ? cart.checkout : undefined,
|
checkout: cart.checkout ? normalizeCheckout(cart.checkout) : undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterNullValue<T>(
|
||||||
|
items: (T | null | undefined)[] | null | undefined
|
||||||
|
): T[] {
|
||||||
|
return items?.filter((item: T | null | undefined): item is T => !!item) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeCheckout(checkout: OCCheckout): Checkout {
|
||||||
|
const fulfillmentGroups = filterNullValue(checkout.fulfillmentGroups).map(
|
||||||
|
(group) => ({
|
||||||
|
selectedFulfillmentOption: group.selectedFulfillmentOption,
|
||||||
|
type: group.type,
|
||||||
|
_id: group._id,
|
||||||
|
data: group.data,
|
||||||
|
availableFulfillmentOptions: filterNullValue(
|
||||||
|
group.availableFulfillmentOptions
|
||||||
|
),
|
||||||
|
})
|
||||||
|
) as FulfillmentGroup[]
|
||||||
|
|
||||||
|
return {
|
||||||
|
...checkout,
|
||||||
|
fulfillmentGroups,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,15 @@ 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 { useCheckoutContext } from '../context'
|
import { useCheckoutContext } from '../context'
|
||||||
import { Key, ReactChild, ReactFragment, ReactPortal } from 'react'
|
|
||||||
|
|
||||||
type FulfillmentGroup = {
|
type FulfillmentGroup = {
|
||||||
type: string
|
type: string
|
||||||
|
_id: string
|
||||||
|
availableFulfillmentOptions: FulfillmentOption[] | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type FulfillmentOption = {
|
type FulfillmentOption = {
|
||||||
fulfillmentMethod: {
|
fulfillmentMethod?: {
|
||||||
_id: string
|
_id: string
|
||||||
displayName: string
|
displayName: string
|
||||||
}
|
}
|
||||||
@ -55,7 +56,7 @@ const ShippingMethod = () => {
|
|||||||
Shipping Methods
|
Shipping Methods
|
||||||
</h2>
|
</h2>
|
||||||
<div>
|
<div>
|
||||||
{shippingGroup.availableFulfillmentOptions.map(
|
{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"
|
||||||
|
@ -16,7 +16,9 @@ export type State = {
|
|||||||
|
|
||||||
type CheckoutContextType = State & {
|
type CheckoutContextType = State & {
|
||||||
setCardFields: (cardFields: CardFields) => void
|
setCardFields: (cardFields: CardFields) => void
|
||||||
setAddressFields: (addressFields: AddressFields) => void
|
setAddressFields: <T extends AddressFields = AddressFields>(
|
||||||
|
addressFields: T
|
||||||
|
) => void
|
||||||
clearCheckoutFields: () => void
|
clearCheckoutFields: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user