From 9a46c11f2acab1eba10c2cad6854c0a7f4a0ee13 Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Thu, 25 May 2023 20:27:18 +0200 Subject: [PATCH] fix(admin-ui): Ensure that default invite link uses __BASE__ if set (#4173) * ensure default invite link uses __BASE__ if it exists * add changeset --- .changeset/itchy-peaches-tell.md | 5 +++++ .../ui/src/components/templates/user-table.tsx | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/itchy-peaches-tell.md diff --git a/.changeset/itchy-peaches-tell.md b/.changeset/itchy-peaches-tell.md new file mode 100644 index 0000000000..e5a8845bbb --- /dev/null +++ b/.changeset/itchy-peaches-tell.md @@ -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 diff --git a/packages/admin-ui/ui/src/components/templates/user-table.tsx b/packages/admin-ui/ui/src/components/templates/user-table.tsx index d653d34ce4..b791d4eaba 100644 --- a/packages/admin-ui/ui/src/components/templates/user-table.tsx +++ b/packages/admin-ui/ui/src/components/templates/user-table.tsx @@ -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 = ({ ) } + 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 ( = ({ 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",