feat(dashboard): collection product management (#7333)

* feat: implement collection management

* fix: toasts

* fix: use query keys from the lib

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Frane Polić
2024-05-16 09:07:36 +02:00
committed by GitHub
parent b78703b8c6
commit d5ac0633f5
6 changed files with 337 additions and 248 deletions

View File

@@ -10,6 +10,7 @@ import { queryClient } from "../../lib/medusa"
import { queryKeysFactory } from "../../lib/query-key-factory"
import {
CreateProductCollectionReq,
UpdateProductCollectionProductsReq,
UpdateProductCollectionReq,
} from "../../types/api-payloads"
import {
@@ -86,6 +87,29 @@ export const useUpdateCollection = (
})
}
export const useUpdateCollectionProducts = (
id: string,
options?: UseMutationOptions<
ProductCollectionRes,
Error,
UpdateProductCollectionProductsReq
>
) => {
return useMutation({
mutationFn: (payload: UpdateProductCollectionProductsReq) =>
client.collections.updateProducts(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: collectionsQueryKeys.lists() })
queryClient.invalidateQueries({
queryKey: collectionsQueryKeys.detail(id),
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}
export const useCreateCollection = (
options?: UseMutationOptions<
ProductCollectionRes,