Skip to content

Commit e65c5ab

Browse files
committed
fix(herbatika): scope product list cache by customer
1 parent 3d2296b commit e65c5ab

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

apps/herbatika/src/components/product-lists/use-account-product-lists.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export function useAccountProductLists() {
6363
const [deleteListId, setDeleteListId] = useState<string | null>(null);
6464
const [statusError, setStatusError] = useState<string | null>(null);
6565

66+
const customerId = authQuery.customer?.id ?? null;
6667
const listsQuery = useProductLists({
68+
customerId,
6769
limit: 100,
6870
enabled: authQuery.isAuthenticated,
6971
});

apps/herbatika/src/components/product-lists/use-product-list-picker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ export function useProductListPicker({
6262
const [activeListKey, setActiveListKey] = useState<string | null>(null);
6363
const [error, setError] = useState<string | null>(null);
6464

65+
const customerId = authQuery.customer?.id ?? null;
6566
const shouldFetchLists = isOpen && authQuery.isAuthenticated;
66-
const listsQuery = useProductLists({ limit: 100, enabled: shouldFetchLists });
67+
const listsQuery = useProductLists({
68+
customerId,
69+
limit: 100,
70+
enabled: shouldFetchLists,
71+
});
6772
const listIds = useMemo(
6873
() => listsQuery.productLists.map((list) => list.id).filter(Boolean),
6974
[listsQuery.productLists],

apps/herbatika/src/lib/storefront/product-lists.client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ export const listProductLists = async (
176176
input: ProductListListInput = {},
177177
signal?: AbortSignal,
178178
) => {
179-
const { enabled: _enabled, limit = 20, offset = 0, ...query } = input;
179+
const {
180+
enabled: _enabled,
181+
customerId: _customerId,
182+
limit = 20,
183+
offset = 0,
184+
...query
185+
} = input;
180186
const response = await storefrontSdk.client.fetch<ProductListListResponse>(
181187
PRODUCT_LISTS_PATH,
182188
{

apps/herbatika/src/lib/storefront/product-lists.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const productListQueryKeys = {
9898
type: input?.type,
9999
limit: input?.limit,
100100
offset: input?.offset,
101+
customerId: input?.customerId ?? null,
101102
},
102103
] as const,
103104
detail: (id?: string | null) =>

apps/herbatika/src/lib/storefront/product-lists.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type ProductListListInput = {
6969
type?: StoreProductListType;
7070
limit?: number;
7171
offset?: number;
72+
customerId?: string | null;
7273
enabled?: boolean;
7374
};
7475

0 commit comments

Comments
 (0)