medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.92k stars 2.6k forks source link

is medusa v2 admin ui path parameters working? #9794

Closed Rohit-Bera closed 2 weeks ago

Rohit-Bera commented 3 weeks ago

Bug report

I have implemented admin ui routes to get custom development , in that i cannot access path parameters

Describe the bug

when we are passing the path parameters in browser URL , it is not printed in the page or in the console.

System information

Medusa version (including plugins): v2 Node.js version: v20.13.1 Database: postgresql Browser (if relevant): chrome

Steps to reproduce the behavior

1) create page.tsx in the src/admin/routes/brand/[id]/page.tsx 2) paste this code

import { useParams } from "react-router-dom"
import { Container } from "@medusajs/ui"

const CustomPage = () => {
  const { id } = useParams()

console.log("id: ",id);

  return (
    <Container className="divide-y p-0">
      <div className="flex items-center justify-between px-6 py-4">
        <Heading level="h1">Passed ID: {id}</Heading>
      </div>
    </Container>
  )
}

export default CustomPage

3) run the app.

Expected behavior

Screenshots

https://github.com/user-attachments/assets/6c43ce8b-6a42-476f-be87-675079645b20

Screenshot 2024-10-25 at 3 32 51 PM Screenshot 2024-10-25 at 3 32 58 PM

Code snippets

src/admin/routes/brand/page.tsx

import { Table, Container, Heading, Alert } from "@medusajs/ui"
import { useEffect, useState } from "react"
import { defineRouteConfig } from "@medusajs/admin-sdk"
import { TagSolid } from "@medusajs/icons"
import { PromptDemo } from "../../../components/Prompt";

const BrandsPage = () => {
  const [brands, setBrands] = useState<
    Record<string, string>[]
  >([])

  useEffect(() => {
    fetch(`/admin/brand`, {
      credentials: "include",
    })
    .then((res) => res.json())
    .then(({ brands: brandsData }) => {
      setBrands(brandsData)
    })
  }, [])

  console.log("brands :",brands)

  return (
    <Container className="divide-y p-0">
      <div className="flex items-center justify-between px-6 py-4">
        <Heading level="h2">Brands</Heading>
      </div>
      <div className="flex h-full flex-col overflow-hidden !border-t-0">
        <Table>
          <Table.Header>
            // table code
            ))}
          </Table.Body>
        </Table>
      </div>
    </Container>
  )
}

export default BrandsPage

export const config = defineRouteConfig({
  label: "Brands",
  icon: TagSolid,
})

src/admin/brand/[id]/page.tsx

import {  Table , Container , Heading, Label } from "@medusajs/ui" 
import { useState ,useEffect } from "react"
import { defineRouteConfig, RouteConfig } from "@medusajs/admin-sdk"
import { TagSolid } from "@medusajs/icons";
import { useParams } from "react-router-dom";

const BrandsDetailPage = () => {

    const { id } = useParams();

    console.log("id :", id)

    return <Container className="divide-y p-0">
        <div className="flex items-center justify-between px-6 py-4">
            <Heading level="h2">Brands</Heading>
        </div>
        <div className="flex h-full flex-col overflow-hidden !border-t-0">
            <Label>Brand details</Label>
            <Label> Brand ID: {id}</Label>
        </div>
    </Container>
}

export const config: RouteConfig = {
    label: "BrandsDetailPage",
    icon: TagSolid,
}

export default BrandsDetailPage
jgatto1 commented 3 weeks ago

Same issue here. I can't navigate to nested pages like src/admin/routes/demo/[id]/page.tsx, the page stays in /src/admin/routes/demo/page.tsx

kasperkristensen commented 3 weeks ago

Hey @Rohit-Bera and @jgatto1

useParams does work, but the issue is a bug in 2.0.0 that prevents nested pages as a whole from working. The issue has been resolved and will be part of 2.0.1, which will be released soon. In the meantime, you can get around the issue by adding this resolution in your package.json:

"resolutions": {
    "@medusajs/admin-bundler": "2.0.1-snapshot-20241023094231",
    "@medusajs/dashboard": "2.0.1-snapshot-20241023094231"
  },

if you are using npm then it should be an override instead

jgatto1 commented 3 weeks ago

Thanks @kasperkristensen it worked!

jeepman32 commented 1 week ago

Hey @kasperkristensen, I've experienced a similar problem. Would it be worth opening a new ticket to describe what happened and what I did to fix it?