Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): open edit variant modal in current context #9203

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading