fix(admin-ui): Patch admin path issue (#5154)
This commit is contained in:
6
.changeset/tasty-experts-kick.md
Normal file
6
.changeset/tasty-experts-kick.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/admin-ui": patch
|
||||
"@medusajs/admin": patch
|
||||
---
|
||||
|
||||
fix(admin-ui): Patch admin path issue
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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)
|
||||
|
||||
22
packages/admin-ui/ui/src/utils/get-admin-path.ts
Normal file
22
packages/admin-ui/ui/src/utils/get-admin-path.ts
Normal 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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user