Minor fixes for checkout view

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe 2022-05-18 16:12:42 +07:00
parent c909152d39
commit 237a207caf

View File

@ -19,21 +19,18 @@ export const handler: SWRHook<GetCheckoutHook> = {
useHook: () => useHook: () =>
function useHook() { function useHook() {
const { data: cart } = useCart() const { data: cart } = useCart()
const hasShippingMethods = !!( const shippingTypeMethod =
cart?.checkout?.fulfillmentGroups && cart?.checkout?.fulfillmentGroups &&
cart.checkout.fulfillmentGroups.find( cart.checkout.fulfillmentGroups.find(
(group) => group?.type === 'shipping' (group) => group?.type === 'shipping'
) )
) const hasShippingMethods =
!!shippingTypeMethod?.availableFulfillmentOptions.length
const { cardFields, addressFields } = useCheckoutContext() const { addressFields } = useCheckoutContext()
const { shippingMethod, ...restAddressFields } = addressFields const { shippingMethod, ...restAddressFields } = addressFields
// Basic validation - check that at least one field has a value.
const hasEnteredCard = Object.values(cardFields).some(
(fieldValue) => !!fieldValue
)
const hasEnteredAddress = Object.values(restAddressFields).some( const hasEnteredAddress = Object.values(restAddressFields).some(
(fieldValue) => !!fieldValue (fieldValue) => !!fieldValue
) )
@ -41,13 +38,14 @@ export const handler: SWRHook<GetCheckoutHook> = {
const response = useMemo( const response = useMemo(
() => ({ () => ({
data: { data: {
hasPayment: hasEnteredCard, // example payment plugin does not need payment info
hasPayment: true,
hasShipping: hasEnteredAddress, hasShipping: hasEnteredAddress,
hasShippingMethods, hasShippingMethods,
hasSelectedShippingMethod: !!shippingMethod?.id, hasSelectedShippingMethod: !!shippingMethod?.id,
}, },
}), }),
[hasEnteredCard, hasEnteredAddress] [hasEnteredAddress, hasShippingMethods, shippingMethod]
) )
return useMemo( return useMemo(