fix(admin-ui): display SC update notification (#3755)

Co-authored-by: fPolic <frane@medusajs.com>
This commit is contained in:
Frane Polić
2023-04-06 15:21:03 +02:00
committed by GitHub
parent 9bbe1edbda
commit 72b76bbd3c
2 changed files with 18 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---
fix(admin-ui): display SC update notification

View File

@@ -1,6 +1,7 @@
import { Product, SalesChannel } from "@medusajs/medusa"
import { useAdminUpdateProduct } from "medusa-react"
import SalesChannelsModal from "../../forms/product/sales-channels-modal"
import useNotification from "../../../hooks/use-notification"
type Props = {
product: Product
@@ -9,13 +10,19 @@ type Props = {
}
const ChannelsModal = ({ product, open, onClose }: Props) => {
const { mutate } = useAdminUpdateProduct(product.id)
const notification = useNotification()
const onUpdate = (channels: SalesChannel[]) => {
// @ts-ignore
mutate({
sales_channels: channels.map((c) => ({ id: c.id })),
})
const { mutateAsync } = useAdminUpdateProduct(product.id)
const onUpdate = async (channels: SalesChannel[]) => {
try {
await mutateAsync({
sales_channels: channels.map((c) => ({ id: c.id })),
})
notification("Success", "Successfully updated sales channels", "success")
} catch (e) {
notification("Error", "Failed to update sales channels", "error")
}
}
return (