fix(dashboard): Load product variant edit page and fix product detail query key (#10029)
**What** - Fixes Edit Variant form so it properly loads the product variant - Fixes the query key for product details to prevent the cache from being shared between queries for the same ID but with different params. Resolves CMRC-685 Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
This commit is contained in:
co-authored by
Frane Polić
parent
81208b6e1d
commit
904f0926f1
@@ -5,10 +5,7 @@ export type TQueryKey<TKey, TListQuery = any, TDetailQuery = string> = {
|
||||
lists: () => readonly [...TQueryKey<TKey>["all"], "list"]
|
||||
list: (
|
||||
query?: TListQuery
|
||||
) => readonly [
|
||||
...ReturnType<TQueryKey<TKey>["lists"]>,
|
||||
{ query: TListQuery | undefined },
|
||||
]
|
||||
) => readonly [...ReturnType<TQueryKey<TKey>["lists"]>, { query: TListQuery }]
|
||||
details: () => readonly [...TQueryKey<TKey>["all"], "detail"]
|
||||
detail: (
|
||||
id: TDetailQuery,
|
||||
@@ -16,7 +13,7 @@ export type TQueryKey<TKey, TListQuery = any, TDetailQuery = string> = {
|
||||
) => readonly [
|
||||
...ReturnType<TQueryKey<TKey>["details"]>,
|
||||
TDetailQuery,
|
||||
{ query: TListQuery | undefined },
|
||||
{ query: TListQuery }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -26,7 +23,7 @@ export type UseQueryOptionsWrapper<
|
||||
// Type thrown in case the queryFn rejects
|
||||
E = Error,
|
||||
// Query key type
|
||||
TQueryKey extends QueryKey = QueryKey,
|
||||
TQueryKey extends QueryKey = QueryKey
|
||||
> = Omit<
|
||||
UseQueryOptions<TQueryFn, E, TQueryFn, TQueryKey>,
|
||||
"queryKey" | "queryFn"
|
||||
@@ -35,20 +32,22 @@ export type UseQueryOptionsWrapper<
|
||||
export const queryKeysFactory = <
|
||||
T,
|
||||
TListQueryType = any,
|
||||
TDetailQueryType = string,
|
||||
TDetailQueryType = string
|
||||
>(
|
||||
globalKey: T
|
||||
) => {
|
||||
const queryKeyFactory: TQueryKey<T, TListQueryType, TDetailQueryType> = {
|
||||
all: [globalKey],
|
||||
lists: () => [...queryKeyFactory.all, "list"],
|
||||
list: (query?: TListQueryType) => [...queryKeyFactory.lists(), { query }],
|
||||
list: (query?: TListQueryType) =>
|
||||
[...queryKeyFactory.lists(), query ? { query } : undefined].filter(
|
||||
(k) => !!k
|
||||
),
|
||||
details: () => [...queryKeyFactory.all, "detail"],
|
||||
detail: (id: TDetailQueryType, query?: TListQueryType) => [
|
||||
...queryKeyFactory.details(),
|
||||
id,
|
||||
{ query },
|
||||
],
|
||||
detail: (id: TDetailQueryType, query?: TListQueryType) =>
|
||||
[...queryKeyFactory.details(), id, query ? { query } : undefined].filter(
|
||||
(k) => !!k
|
||||
),
|
||||
}
|
||||
return queryKeyFactory
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user