import { ArrowUturnLeft, MinusMini } from "@medusajs/icons" import { IconButton, Text, clx } from "@medusajs/ui" import * as Collapsible from "@radix-ui/react-collapsible" import { Fragment, useEffect, useMemo, useState } from "react" import { useTranslation } from "react-i18next" import { Link, useLocation } from "react-router-dom" import { settingsRouteRegex } from "../../../lib/extension-helpers" import { Divider } from "../../common/divider" import { NavItem, NavItemProps } from "../nav-item" import { Shell } from "../shell" import routes from "virtual:medusa/routes/links" import { UserMenu } from "../user-menu" export const SettingsLayout = () => { return ( ) } const useSettingRoutes = (): NavItemProps[] => { const { t } = useTranslation() return useMemo( () => [ { label: t("store.domain"), to: "/settings/store", }, { label: t("users.domain"), to: "/settings/users", }, { label: t("regions.domain"), to: "/settings/regions", }, { label: t("taxRegions.domain"), to: "/settings/tax-regions", }, { label: t("salesChannels.domain"), to: "/settings/sales-channels", }, { label: t("productTypes.domain"), to: "/settings/product-types", }, { label: t("productTags.domain"), to: "/settings/product-tags", }, { label: t("stockLocations.domain"), to: "/settings/locations", }, ], [t] ) } const useDeveloperRoutes = (): NavItemProps[] => { const { t } = useTranslation() return useMemo( () => [ { label: t("apiKeyManagement.domain.publishable"), to: "/settings/publishable-api-keys", }, { label: t("apiKeyManagement.domain.secret"), to: "/settings/secret-api-keys", }, { label: t("workflowExecutions.domain"), to: "/settings/workflows", }, ], [t] ) } const useMyAccountRoutes = (): NavItemProps[] => { const { t } = useTranslation() return useMemo( () => [ { label: t("profile.domain"), to: "/settings/profile", }, ], [t] ) } const useExtensionRoutes = (): NavItemProps[] => { const links = routes.links return useMemo(() => { const settingsLinks = links.filter((link) => settingsRouteRegex.test(link.path) ) return settingsLinks.map((link) => ({ label: link.label, to: link.path, })) }, [links]) } /** * Ensure that the `from` prop is not another settings route, to avoid * the user getting stuck in a navigation loop. */ const getSafeFromValue = (from: string) => { if (from.startsWith("/settings")) { return "/orders" } return from } const SettingsSidebar = () => { const routes = useSettingRoutes() const developerRoutes = useDeveloperRoutes() const extensionRoutes = useExtensionRoutes() const myAccountRoutes = useMyAccountRoutes() const { t } = useTranslation() return ( ) } const Header = () => { const [from, setFrom] = useState("/orders") const { t } = useTranslation() const location = useLocation() useEffect(() => { if (location.state?.from) { setFrom(getSafeFromValue(location.state.from)) } }, [location]) return (
{t("app.nav.settings.header")}
) } const CollapsibleSection = ({ label, items, }: { label: string items: NavItemProps[] }) => { return (
{label}
) } const UserSection = () => { return (
) }