@instockng/api-client 1.0.18 → 1.0.20

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.
@@ -1353,6 +1353,7 @@ export declare function useAddCartItem(cartId: string, options?: UseMutationOpti
1353
1353
  fbp?: string;
1354
1354
  ttp?: string;
1355
1355
  ttclid?: string;
1356
+ refreshRecommendations?: boolean;
1356
1357
  }>): import("@tanstack/react-query").UseMutationResult<{
1357
1358
  id: string;
1358
1359
  brand: {
@@ -1612,6 +1613,7 @@ export declare function useAddCartItem(cartId: string, options?: UseMutationOpti
1612
1613
  fbp?: string;
1613
1614
  ttp?: string;
1614
1615
  ttclid?: string;
1616
+ refreshRecommendations?: boolean;
1615
1617
  }, unknown>;
1616
1618
  /**
1617
1619
  * Hook to update cart item quantity using RPC
@@ -129,8 +129,12 @@ export function useAddCartItem(cartId, options) {
129
129
  const queryClient = useQueryClient();
130
130
  return useMutation({
131
131
  mutationFn: (data) => addCartItem(cartId, data.sku, data.quantity, data.fbc, data.fbp, data.ttp, data.ttclid),
132
- onSuccess: () => {
132
+ onSuccess: (_, variables) => {
133
133
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
134
+ // Refresh recommendations only if cart is not visible (refreshRecommendations flag is true)
135
+ if (variables.refreshRecommendations) {
136
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.recommendations(cartId) });
137
+ }
134
138
  },
135
139
  ...options,
136
140
  });
@@ -175,6 +179,8 @@ export function useRemoveCartItem(cartId, options) {
175
179
  mutationFn: (itemId) => removeCartItem(cartId, itemId),
176
180
  onSuccess: () => {
177
181
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
182
+ // Refresh recommendations when item is removed
183
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.recommendations(cartId) });
178
184
  },
179
185
  ...options,
180
186
  });
@@ -226,7 +232,7 @@ export function useCheckoutCart(cartId, options) {
226
232
  */
227
233
  export function useGetCartRecommendations(cartId, limit, options) {
228
234
  return useQueryUnwrapped({
229
- queryKey: ['carts', cartId, 'recommendations', limit],
235
+ queryKey: cartId ? queryKeys.public.carts.recommendations(cartId, limit) : ['public', 'carts', 'recommendations'],
230
236
  queryFn: () => fetchCartRecommendations(cartId, limit),
231
237
  enabled: !!cartId,
232
238
  ...options,
@@ -12,6 +12,7 @@ export declare const queryKeys: {
12
12
  carts: {
13
13
  all: readonly ["public", "carts"];
14
14
  detail: (id: string) => readonly ["public", "carts", string];
15
+ recommendations: (id: string, limit?: number) => readonly ["public", "carts", string, "recommendations", number] | readonly ["public", "carts", string, "recommendations"];
15
16
  };
16
17
  orders: {
17
18
  all: readonly ["public", "orders"];
@@ -13,6 +13,9 @@ export const queryKeys = {
13
13
  carts: {
14
14
  all: ['public', 'carts'],
15
15
  detail: (id) => ['public', 'carts', id],
16
+ recommendations: (id, limit) => limit !== undefined
17
+ ? ['public', 'carts', id, 'recommendations', limit]
18
+ : ['public', 'carts', id, 'recommendations'],
16
19
  },
17
20
  orders: {
18
21
  all: ['public', 'orders'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instockng/api-client",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "React Query hooks for OMS API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",