fix(admin-ui): Patch admin path issue (#5154)

This commit is contained in:
Oli Juhl
2023-09-20 16:31:15 +02:00
committed by GitHub
parent 8b189d2b90
commit 54531e38bc
4 changed files with 35 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/admin-ui": patch
"@medusajs/admin": patch
---
fix(admin-ui): Patch admin path issue

View File

@@ -14,6 +14,7 @@ import Table from "../molecules/table"
import DeletePrompt from "../organisms/delete-prompt"
import EditUser from "../organisms/edit-user-modal"
import { useTranslation } from "react-i18next"
import { getAdminPath, getFullAdminPath } from "../../utils/get-admin-path"
type UserListElement = {
entity: any
@@ -110,9 +111,9 @@ const UserTable: React.FC<UserTableProps> = ({
return store.invite_link_template
}
return `${window.location.origin}${
process.env.ADMIN_PATH ? `${process.env.ADMIN_PATH}/` : "/"
}invite?token={invite_token}`
const adminPath = getFullAdminPath()
return `${adminPath}invite?token={invite_token}`
}, [store])
const getInviteTableRow = (invite: Invite, index: number) => {

View File

@@ -2,6 +2,7 @@ import i18n from "i18next"
import LanguageDetector from "i18next-browser-languagedetector"
import Backend from "i18next-http-backend"
import { initReactI18next } from "react-i18next"
import { getFullAdminPath } from "../utils/get-admin-path"
export const supportedLanguages = [
{
@@ -22,10 +23,8 @@ export const supportedLanguages = [
},
]
const backendUrl = window.location.origin
const adminPath = process.env.ADMIN_PATH ? `${process.env.ADMIN_PATH}/` : "/"
const pathToLoadFrom = `${backendUrl}${adminPath}public/locales/{{lng}}/{{ns}}.json`
const adminPath = getFullAdminPath()
const pathToLoadFrom = `${adminPath}public/locales/{{lng}}/{{ns}}.json`
void i18n
.use(Backend)

View File

@@ -0,0 +1,22 @@
/**
* returns the full admin path using the window object
* @returns {string} - admin path
*/
export function getFullAdminPath() {
if (window) {
const origin = window.location.origin // returns base url with trailing slash
const adminPath = process.env.ADMIN_PATH ? `${process.env.ADMIN_PATH}/` : ""
let fullPath = `${origin}${adminPath}`
// safeguard against double slashes, which happens in case path is set to `/`
if (fullPath.endsWith("//")) {
fullPath = adminPath.slice(0, -1)
}
return fullPath
}
return ""
}