docs: refactored versioning in api reference + modified v2 content (#7274)

This commit is contained in:
Shahed Nasser
2024-05-09 17:23:49 +03:00
committed by GitHub
parent 6da2964998
commit 5d0ffe8ff4
16 changed files with 1107 additions and 92 deletions

View File

@@ -11,11 +11,13 @@ import { useMemo } from "react"
import { config } from "../../config"
import { usePathname } from "next/navigation"
import VersionSwitcher from "../VersionSwitcher"
import { useVersion } from "../../providers/version"
const Navbar = () => {
const { setMobileSidebarOpen, mobileSidebarOpen } = useSidebar()
const pathname = usePathname()
const { isLoading } = usePageLoading()
const { isVersioningEnabled } = useVersion()
const navbarItems = useMemo(
() =>
@@ -38,9 +40,7 @@ const Navbar = () => {
mobileSidebarOpen,
}}
additionalActionsBefore={
<>
{process.env.NEXT_PUBLIC_VERSIONING === "true" && <VersionSwitcher />}
</>
<>{isVersioningEnabled && <VersionSwitcher />}</>
}
additionalActionsAfter={<FeedbackModal />}
isLoading={isLoading}

View File

@@ -10,10 +10,9 @@ type PageHeadingProps = {
const PageHeading = ({ className }: PageHeadingProps) => {
const { area } = useArea()
const { version } = useVersion()
const { version, isVersioningEnabled } = useVersion()
const versionText =
process.env.NEXT_PUBLIC_VERSIONING === "true" ? ` V${version}` : ""
const versionText = isVersioningEnabled ? ` V${version}` : ""
return (
<h1 className={className}>

View File

@@ -1,22 +0,0 @@
"use client"
import { Note } from "docs-ui"
import { useVersion } from "../../providers/version"
const VersionNote = () => {
const { version } = useVersion()
return (
<>
{version === "2" && (
<Note type="warning" title="Production Warning">
Medusa v2.0 is in development and not suitable for production
environments. As such, the API reference is incomplete and subject to
change, so please use it with caution.
</Note>
)}
</>
)
}
export default VersionNote

View File

@@ -1,11 +1,13 @@
"use client"
import { Toggle } from "docs-ui"
import { useVersion } from "../../providers/version"
import clsx from "clsx"
import { usePathname } from "next/navigation"
import { useVersion } from "../../providers/version"
const VersionSwitcher = () => {
const { version, changeVersion } = useVersion()
const pathname = usePathname()
const { version } = useVersion()
return (
<div className="flex gap-0.5 justify-center items-center">
@@ -19,7 +21,14 @@ const VersionSwitcher = () => {
</span>
<Toggle
checked={version === "2"}
onCheckedChange={(checked) => changeVersion(checked ? "2" : "1")}
onCheckedChange={(checked) => {
let newPath = pathname.replace("/v2", "")
if (checked) {
newPath += `/v2`
}
location.href = location.href.replace(pathname, newPath)
}}
/>
<span
className={clsx(