@anker-in/shopify-react 0.1.1-beta.11 → 0.1.1-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2566,21 +2566,22 @@ function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
2566
2566
  var useUpdatePlusMemberDeliveryOptions = ({
2567
2567
  options
2568
2568
  }) => {
2569
- const { cart, mutateCart: mutate, metafieldIdentifiers } = useCartContext();
2569
+ const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
2570
2570
  const { trigger: updateCartDeliveryOptions2, isMutating } = useUpdateCartDeliveryOptions(
2571
- mutate,
2571
+ mutateCart,
2572
2572
  metafieldIdentifiers
2573
2573
  );
2574
2574
  const handler = useCallback(
2575
2575
  async (_, { arg }) => {
2576
+ const currentCart = arg?.cart || cartContextData;
2576
2577
  const { deliveryData } = arg;
2577
- const firstDeliveryGroup = cart?.deliveryGroups?.[0];
2578
+ const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
2578
2579
  const deliveryGroupId = firstDeliveryGroup?.id;
2579
2580
  const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
2580
2581
  if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
2581
2582
  return null;
2582
2583
  }
2583
- const deliveryGroup = cart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2584
+ const deliveryGroup = currentCart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2584
2585
  const matchedOption = deliveryGroup?.deliveryOptions?.find(
2585
2586
  (option) => option?.code === selectedOptionCode
2586
2587
  );
@@ -2594,14 +2595,15 @@ var useUpdatePlusMemberDeliveryOptions = ({
2594
2595
  }
2595
2596
  ];
2596
2597
  const updatedCart = await updateCartDeliveryOptions2({
2597
- selectedDeliveryOptions: deliveryOptions
2598
+ selectedDeliveryOptions: deliveryOptions,
2599
+ cartId: currentCart?.id
2598
2600
  });
2599
- if (updatedCart && mutate) {
2600
- mutate(updatedCart);
2601
+ if (updatedCart && mutateCart) {
2602
+ mutateCart(updatedCart);
2601
2603
  }
2602
2604
  return updatedCart;
2603
2605
  },
2604
- [cart, updateCartDeliveryOptions2, mutate]
2606
+ [cartContextData, updateCartDeliveryOptions2, mutateCart]
2605
2607
  );
2606
2608
  return useSWRMutation("update-cart-delivery-options", handler, options);
2607
2609
  };