Skip to content

Commit

Permalink
fix(admin-ui): invalidate products query on category delete
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan committed Mar 15, 2023
1 parent 77d4622 commit 4fecc32
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-vans-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---

fix(admin-ui): invalidate products query on category delete
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useContext } from "react"
import clsx from "clsx"

import { ProductCategory } from "@medusajs/medusa"
import { useAdminDeleteProductCategory } from "medusa-react"
import { useAdminDeleteProductCategory, adminProductKeys } from "medusa-react"
import { useQueryClient } from "@tanstack/react-query"

import { ProductCategoriesContext } from "../pages"
import Tooltip from "../../../components/atoms/tooltip"
Expand Down Expand Up @@ -31,11 +32,9 @@ function ProductCategoryListItemDetails(
) {
const { item } = props
const notification = useNotification()

const queryClient = useQueryClient()
const hasChildren = !!item.category_children?.length

const productCategoriesPageContext = useContext(ProductCategoriesContext)

const { mutateAsync: deleteCategory } = useAdminDeleteProductCategory(item.id)

const actions = [
Expand All @@ -53,6 +52,8 @@ function ProductCategoryListItemDetails(
notification("Success", "Category deleted", "success")
} catch (e) {
notification("Error", "Category deletion failed", "error")
} finally {
await queryClient.invalidateQueries(adminProductKeys.all)
}
},
icon: <TrashIcon size={20} />,
Expand Down

0 comments on commit 4fecc32

Please sign in to comment.