import { ArrowUturnLeft, MinusMini } from "@medusajs/icons"
import { IconButton, Text, clx } from "@medusajs/ui"
import { Collapsible as RadixCollapsible } from "radix-ui"
import { Fragment, useEffect, useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import { Link, useLocation } from "react-router-dom"
import { Divider } from "../../common/divider"
import { INavItem, NavItem } from "../nav-item"
import { Shell } from "../shell"
import { useDashboardExtension } from "../../../extensions"
import { UserMenu } from "../user-menu"
export const SettingsLayout = () => {
return (
)
}
const useSettingRoutes = (): INavItem[] => {
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("returnReasons.domain"),
to: "/settings/return-reasons",
},
{
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 = (): INavItem[] => {
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 = (): INavItem[] => {
const { t } = useTranslation()
return useMemo(
() => [
{
label: t("profile.domain"),
to: "/settings/profile",
},
],
[t]
)
}
/**
* 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 { getMenu } = useDashboardExtension()
const routes = useSettingRoutes()
const developerRoutes = useDeveloperRoutes()
const myAccountRoutes = useMyAccountRoutes()
const extensionRoutes = getMenu("settingsExtensions")
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 RadixCollapsibleSection = ({
label,
items,
}: {
label: string
items: INavItem[]
}) => {
return (
)
}
const UserSection = () => {
return (
)
}