fix(admin-ui): Ensure that default invite link uses __BASE__ if set (#4173)

* ensure default invite link uses __BASE__ if it exists

* add changeset
This commit is contained in:
Kasper Fabricius Kristensen
2023-05-25 20:27:18 +02:00
committed by GitHub
parent 92f01cefbc
commit 9a46c11f2a
2 changed files with 17 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---
fix(admin-ui): Ensures that the default invite link uses the **BASE** in constructing the link if it exists
@@ -1,7 +1,7 @@
import { Invite, User } from "@medusajs/medusa"
import copy from "copy-to-clipboard"
import { useAdminStore } from "medusa-react"
import React, { useEffect, useState } from "react"
import React, { useEffect, useMemo, useState } from "react"
import useNotification from "../../hooks/use-notification"
import Medusa from "../../services/api"
import ClipboardCopyIcon from "../fundamentals/icons/clipboard-copy-icon"
@@ -103,6 +103,16 @@ const UserTable: React.FC<UserTableProps> = ({
)
}
const inviteLink = useMemo(() => {
if (store?.invite_link_template) {
return store.invite_link_template
}
return `${window.location.origin}${
__BASE__ ? `${__BASE__}/` : "/"
}invite?token={invite_token}`
}, [store])
const getInviteTableRow = (invite: Invite, index: number) => {
return (
<Table.Row
@@ -128,11 +138,7 @@ const UserTable: React.FC<UserTableProps> = ({
label: "Copy invite link",
disabled: isLoading,
onClick: () => {
const link_template =
store?.invite_link_template ??
`${window.location.origin}/invite?token={invite_token}`
copy(link_template.replace("{invite_token}", invite.token))
copy(inviteLink.replace("{invite_token}", invite.token))
notification(
"Success",
"Invite link copied to clipboard",