@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.
@@ -2575,21 +2575,22 @@ function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
2575
2575
  var useUpdatePlusMemberDeliveryOptions = ({
2576
2576
  options
2577
2577
  }) => {
2578
- const { cart, mutateCart: mutate, metafieldIdentifiers } = useCartContext();
2578
+ const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
2579
2579
  const { trigger: updateCartDeliveryOptions2, isMutating } = useUpdateCartDeliveryOptions(
2580
- mutate,
2580
+ mutateCart,
2581
2581
  metafieldIdentifiers
2582
2582
  );
2583
2583
  const handler = react.useCallback(
2584
2584
  async (_, { arg }) => {
2585
+ const currentCart = arg?.cart || cartContextData;
2585
2586
  const { deliveryData } = arg;
2586
- const firstDeliveryGroup = cart?.deliveryGroups?.[0];
2587
+ const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
2587
2588
  const deliveryGroupId = firstDeliveryGroup?.id;
2588
2589
  const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
2589
2590
  if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
2590
2591
  return null;
2591
2592
  }
2592
- const deliveryGroup = cart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2593
+ const deliveryGroup = currentCart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2593
2594
  const matchedOption = deliveryGroup?.deliveryOptions?.find(
2594
2595
  (option) => option?.code === selectedOptionCode
2595
2596
  );
@@ -2603,14 +2604,15 @@ var useUpdatePlusMemberDeliveryOptions = ({
2603
2604
  }
2604
2605
  ];
2605
2606
  const updatedCart = await updateCartDeliveryOptions2({
2606
- selectedDeliveryOptions: deliveryOptions
2607
+ selectedDeliveryOptions: deliveryOptions,
2608
+ cartId: currentCart?.id
2607
2609
  });
2608
- if (updatedCart && mutate) {
2609
- mutate(updatedCart);
2610
+ if (updatedCart && mutateCart) {
2611
+ mutateCart(updatedCart);
2610
2612
  }
2611
2613
  return updatedCart;
2612
2614
  },
2613
- [cart, updateCartDeliveryOptions2, mutate]
2615
+ [cartContextData, updateCartDeliveryOptions2, mutateCart]
2614
2616
  );
2615
2617
  return useSWRMutation__default.default("update-cart-delivery-options", handler, options);
2616
2618
  };