fix(dashboard): open edit variant modal in current context (#9203)
This commit is contained in:
1 parent
4923a6e823
commit
07f25de153
4 files changed
+21
-9
No files matched your search
@@ -91,6 +91,13 @@ export const RouteMap: RouteObject[] = [
|
|||||||
lazy: () =>
|
lazy: () =>
|
||||||
import("../../routes/products/product-edit"),
|
import("../../routes/products/product-edit"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "edit-variant",
|
||||||
|
lazy: () =>
|
||||||
|
import(
|
||||||
|
"../../routes/product-variants/product-variant-edit"
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "sales-channels",
|
path: "sales-channels",
|
||||||
lazy: () =>
|
lazy: () =>
|
||||||
|
|||||||
+2
-5
@@ -9,10 +9,7 @@ import { Divider } from "../../../../../components/common/divider"
|
|||||||
import { Form } from "../../../../../components/common/form"
|
import { Form } from "../../../../../components/common/form"
|
||||||
import { Combobox } from "../../../../../components/inputs/combobox"
|
import { Combobox } from "../../../../../components/inputs/combobox"
|
||||||
import { CountrySelect } from "../../../../../components/inputs/country-select"
|
import { CountrySelect } from "../../../../../components/inputs/country-select"
|
||||||
import {
|
import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
|
||||||
RouteDrawer,
|
|
||||||
useRouteModal,
|
|
||||||
} from "../../../../../components/modals"
|
|
||||||
import { useUpdateProductVariant } from "../../../../../hooks/api/products"
|
import { useUpdateProductVariant } from "../../../../../hooks/api/products"
|
||||||
import {
|
import {
|
||||||
transformNullableFormData,
|
transformNullableFormData,
|
||||||
@@ -115,7 +112,7 @@ export const ProductEditVariantForm = ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
handleSuccess()
|
handleSuccess("../")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+11
-3
@@ -1,7 +1,12 @@
|
|||||||
import { HttpTypes } from "@medusajs/types"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { Heading } from "@medusajs/ui"
|
import { Heading } from "@medusajs/ui"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { json, useLoaderData, useParams } from "react-router-dom"
|
import {
|
||||||
|
json,
|
||||||
|
useLoaderData,
|
||||||
|
useParams,
|
||||||
|
useSearchParams,
|
||||||
|
} from "react-router-dom"
|
||||||
import { RouteDrawer } from "../../../components/modals"
|
import { RouteDrawer } from "../../../components/modals"
|
||||||
import { useProduct } from "../../../hooks/api/products"
|
import { useProduct } from "../../../hooks/api/products"
|
||||||
import { ProductEditVariantForm } from "./components/product-edit-variant-form"
|
import { ProductEditVariantForm } from "./components/product-edit-variant-form"
|
||||||
@@ -14,6 +19,8 @@ export const ProductVariantEdit = () => {
|
|||||||
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { id, variant_id } = useParams()
|
const { id, variant_id } = useParams()
|
||||||
|
const [URLSearchParms] = useSearchParams()
|
||||||
|
const searchVariantId = URLSearchParms.get("variant_id")
|
||||||
|
|
||||||
const { product, isPending, isFetching, isError, error } = useProduct(
|
const { product, isPending, isFetching, isError, error } = useProduct(
|
||||||
id!,
|
id!,
|
||||||
@@ -24,13 +31,14 @@ export const ProductVariantEdit = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const variant = product?.variants.find(
|
const variant = product?.variants.find(
|
||||||
(v: HttpTypes.AdminProductVariant) => v.id === variant_id
|
(v: HttpTypes.AdminProductVariant) =>
|
||||||
|
v.id === (variant_id || searchVariantId)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isPending && !isFetching && !variant) {
|
if (!isPending && !isFetching && !variant) {
|
||||||
throw json({
|
throw json({
|
||||||
status: 404,
|
status: 404,
|
||||||
message: `Variant with ID ${variant_id} was not found.`,
|
message: `Variant with ID ${variant_id || searchVariantId} was not found.`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ const VariantActions = ({
|
|||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
label: t("actions.edit"),
|
label: t("actions.edit"),
|
||||||
to: `variants/${variant.id}/edit`,
|
to: `edit-variant?variant_id=${variant.id}`,
|
||||||
icon: <PencilSquare />,
|
icon: <PencilSquare />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user