feat(medusa,dashboard,admin-sdk): Run admin dashboard from Medusa instance (#7330)
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
import { Navigate, useLocation, useRouteError } from "react-router-dom"
|
||||
|
||||
import { ExclamationCircle } from "@medusajs/icons"
|
||||
import { Text } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { isAxiosError } from "../../../lib/is-axios-error"
|
||||
|
||||
// WIP - Need to allow wrapping <Outlet> with ErrorBoundary for more granular error handling.
|
||||
export const ErrorBoundary = () => {
|
||||
const error = useRouteError()
|
||||
const location = useLocation()
|
||||
const { t } = useTranslation()
|
||||
|
||||
let code: number | null = null
|
||||
|
||||
if (isAxiosError(error)) {
|
||||
if (error.response?.status === 401) {
|
||||
return <Navigate to="/login" state={{ from: location }} replace />
|
||||
}
|
||||
|
||||
code = error.response?.status ?? null
|
||||
}
|
||||
|
||||
let title: string
|
||||
let message: string
|
||||
|
||||
switch (code) {
|
||||
case 400:
|
||||
title = t("errorBoundary.badRequestTitle")
|
||||
message = t("errorBoundary.badRequestMessage")
|
||||
break
|
||||
case 404:
|
||||
title = t("errorBoundary.notFoundTitle")
|
||||
message = t("errorBoundary.notFoundMessage")
|
||||
break
|
||||
case 500:
|
||||
title = t("errorBoundary.internalServerErrorTitle")
|
||||
message = t("errorBoundary.internalServerErrorMessage")
|
||||
break
|
||||
default:
|
||||
title = t("errorBoundary.defaultTitle")
|
||||
message = t("errorBoundary.defaultMessage")
|
||||
break
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex size-full min-h-screen items-center justify-center">
|
||||
<div className="text-ui-fg-subtle flex flex-col items-center gap-y-2">
|
||||
<ExclamationCircle />
|
||||
<Text size="small" leading="compact" weight="plus">
|
||||
{title}
|
||||
</Text>
|
||||
<Text size="small" className="text-ui-fg-muted">
|
||||
{message}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { ErrorBoundary } from "./error-boundary"
|
||||
@@ -0,0 +1,23 @@
|
||||
import i18n from "i18next"
|
||||
import LanguageDetector from "i18next-browser-languagedetector"
|
||||
import { initReactI18next } from "react-i18next"
|
||||
|
||||
import { defaultI18nOptions } from "../../../i18n/config"
|
||||
|
||||
export const I18n = () => {
|
||||
if (i18n.isInitialized) {
|
||||
return null
|
||||
}
|
||||
|
||||
i18n
|
||||
.use(
|
||||
new LanguageDetector(null, {
|
||||
lookupCookie: "lng",
|
||||
lookupLocalStorage: "lng",
|
||||
})
|
||||
)
|
||||
.use(initReactI18next)
|
||||
.init(defaultI18nOptions)
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./i18n"
|
||||
Reference in New Issue
Block a user