Skip to content

Commit

Permalink
fix(dashboard): open edit variant modal in current context (#9203)
Browse files Browse the repository at this point in the history
  • Loading branch information
fPolic committed Sep 19, 2024
1 parent 4923a6e commit 07f25de
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export const RouteMap: RouteObject[] = [
lazy: () =>
import("../../routes/products/product-edit"),
},
{
path: "edit-variant",
lazy: () =>
import(
"../../routes/product-variants/product-variant-edit"
),
},
{
path: "sales-channels",
lazy: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { Divider } from "../../../../../components/common/divider"
import { Form } from "../../../../../components/common/form"
import { Combobox } from "../../../../../components/inputs/combobox"
import { CountrySelect } from "../../../../../components/inputs/country-select"
import {
RouteDrawer,
useRouteModal,
} from "../../../../../components/modals"
import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
import { useUpdateProductVariant } from "../../../../../hooks/api/products"
import {
transformNullableFormData,
Expand Down Expand Up @@ -115,7 +112,7 @@ export const ProductEditVariantForm = ({
},
{
onSuccess: () => {
handleSuccess()
handleSuccess("../")
},
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { HttpTypes } from "@medusajs/types"
import { Heading } from "@medusajs/ui"
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 { useProduct } from "../../../hooks/api/products"
import { ProductEditVariantForm } from "./components/product-edit-variant-form"
Expand All @@ -14,6 +19,8 @@ export const ProductVariantEdit = () => {

const { t } = useTranslation()
const { id, variant_id } = useParams()
const [URLSearchParms] = useSearchParams()
const searchVariantId = URLSearchParms.get("variant_id")

const { product, isPending, isFetching, isError, error } = useProduct(
id!,
Expand All @@ -24,13 +31,14 @@ export const ProductVariantEdit = () => {
)

const variant = product?.variants.find(
(v: HttpTypes.AdminProductVariant) => v.id === variant_id
(v: HttpTypes.AdminProductVariant) =>
v.id === (variant_id || searchVariantId)
)

if (!isPending && !isFetching && !variant) {
throw json({
status: 404,
message: `Variant with ID ${variant_id} was not found.`,
message: `Variant with ID ${variant_id || searchVariantId} was not found.`,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const VariantActions = ({
actions: [
{
label: t("actions.edit"),
to: `variants/${variant.id}/edit`,
to: `edit-variant?variant_id=${variant.id}`,
icon: <PencilSquare />,
},
{
Expand Down

0 comments on commit 07f25de

Please sign in to comment.