bugfix: invitation link copy option disapearing fixed. route problem for unauthorizrd users opening invitation link fixed.
This commit is contained in:
@@ -61,6 +61,10 @@ function formatApiMessage(err: unknown): string {
|
||||
return 'Something went wrong';
|
||||
}
|
||||
|
||||
function canShareStaffInviteLink(member: StaffMemberDto): boolean {
|
||||
return !member.isOwner && member.invitationStatus !== 'ACTIVE';
|
||||
}
|
||||
|
||||
function PermissionGrid({
|
||||
state,
|
||||
onChange,
|
||||
@@ -140,6 +144,7 @@ export default function StaffPage() {
|
||||
const [invitePerms, setInvitePerms] = useState(() => emptyFeaturePermissionState());
|
||||
const [inviteLoading, setInviteLoading] = useState(false);
|
||||
const [copiedInviteMembershipId, setCopiedInviteMembershipId] = useState<string | null>(null);
|
||||
const [copyingInviteMembershipId, setCopyingInviteMembershipId] = useState<string | null>(null);
|
||||
const [lastInviteInfo, setLastInviteInfo] = useState<{
|
||||
membershipId: string;
|
||||
name: string;
|
||||
@@ -221,6 +226,42 @@ export default function StaffPage() {
|
||||
return () => clearTimeout(t);
|
||||
}, [success]);
|
||||
|
||||
async function copyStaffInviteLink(member: StaffMemberDto) {
|
||||
if (!canShareStaffInviteLink(member)) return;
|
||||
|
||||
setCopyingInviteMembershipId(member.id);
|
||||
setError('');
|
||||
try {
|
||||
let invitationUrl = pendingInviteLinks[member.id]?.invitationUrl;
|
||||
if (!invitationUrl || member.invitationStatus === 'EXPIRED') {
|
||||
const res = await staffApi.getInvitationLink(member.id);
|
||||
invitationUrl = res.data.invitationUrl;
|
||||
if (currentOrganization?.id) {
|
||||
const nextLinks = {
|
||||
...pendingInviteLinks,
|
||||
[member.id]: {
|
||||
membershipId: member.id,
|
||||
email: member.email,
|
||||
invitationUrl,
|
||||
},
|
||||
};
|
||||
setPendingInviteLinks(nextLinks);
|
||||
writeStoredInviteLinks(currentOrganization.id, nextLinks);
|
||||
}
|
||||
}
|
||||
await navigator.clipboard.writeText(invitationUrl);
|
||||
setCopiedInviteMembershipId(member.id);
|
||||
setTimeout(() => setCopiedInviteMembershipId(null), 1500);
|
||||
if (member.invitationStatus === 'EXPIRED') {
|
||||
await load();
|
||||
}
|
||||
} catch (e) {
|
||||
setError(formatApiMessage(e));
|
||||
} finally {
|
||||
setCopyingInviteMembershipId(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function submitInvite() {
|
||||
setInviteLoading(true);
|
||||
setError('');
|
||||
@@ -388,34 +429,60 @@ export default function StaffPage() {
|
||||
? ' Invitation is pending until they open the link, set a password, and log in.'
|
||||
: ' Invitation was accepted immediately.'}
|
||||
</p>
|
||||
{lastInviteInfo.invitationUrl && (
|
||||
{lastInviteInfo.invitationStatus === 'PENDING' && (
|
||||
<div className="space-y-2 pt-1 border-t border-border/60">
|
||||
<p className="text-xs font-medium text-text-secondary uppercase tracking-wide">
|
||||
Invite link
|
||||
</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<code className="text-sm px-2 py-1.5 rounded-[var(--radius-sm)] bg-background-card border border-border font-mono break-all">
|
||||
{lastInviteInfo.invitationUrl && (
|
||||
<code className="block text-sm px-2 py-1.5 rounded-[var(--radius-sm)] bg-background-card border border-border font-mono break-all">
|
||||
{lastInviteInfo.invitationUrl}
|
||||
</code>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={async () => {
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
isLoading={copyingInviteMembershipId === lastInviteInfo.membershipId}
|
||||
onClick={() => {
|
||||
const member = members.find((item) => item.id === lastInviteInfo.membershipId);
|
||||
if (member) {
|
||||
void copyStaffInviteLink(member);
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
setCopyingInviteMembershipId(lastInviteInfo.membershipId);
|
||||
setError('');
|
||||
try {
|
||||
await navigator.clipboard.writeText(lastInviteInfo.invitationUrl as string);
|
||||
const res = await staffApi.getInvitationLink(lastInviteInfo.membershipId);
|
||||
if (currentOrganization?.id) {
|
||||
const nextLinks = {
|
||||
...pendingInviteLinks,
|
||||
[lastInviteInfo.membershipId]: {
|
||||
membershipId: lastInviteInfo.membershipId,
|
||||
email: lastInviteInfo.email,
|
||||
invitationUrl: res.data.invitationUrl,
|
||||
},
|
||||
};
|
||||
setPendingInviteLinks(nextLinks);
|
||||
writeStoredInviteLinks(currentOrganization.id, nextLinks);
|
||||
}
|
||||
setLastInviteInfo({ ...lastInviteInfo, invitationUrl: res.data.invitationUrl });
|
||||
await navigator.clipboard.writeText(res.data.invitationUrl);
|
||||
setCopiedInviteMembershipId(lastInviteInfo.membershipId);
|
||||
setTimeout(() => setCopiedInviteMembershipId(null), 1500);
|
||||
} catch {
|
||||
setError('Could not copy invitation link');
|
||||
} catch (e) {
|
||||
setError(formatApiMessage(e));
|
||||
} finally {
|
||||
setCopyingInviteMembershipId(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{copiedInviteMembershipId === lastInviteInfo.membershipId ? 'Copied' : 'Copy link'}
|
||||
</Button>
|
||||
</div>
|
||||
})();
|
||||
}}
|
||||
>
|
||||
{copiedInviteMembershipId === lastInviteInfo.membershipId ? 'Copied' : 'Copy link'}
|
||||
</Button>
|
||||
<p className="text-xs text-text-muted">
|
||||
Share this link manually via SMS or email. They must set password first.
|
||||
Share this link manually via SMS or email. A new link is generated if the previous one expired or was lost.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -470,21 +537,14 @@ export default function StaffPage() {
|
||||
<td className="px-6 py-1.5 align-middle">
|
||||
{!m.isOwner && (
|
||||
<div className="flex min-h-[36px] items-center justify-end gap-1">
|
||||
{m.invitationStatus === 'PENDING' && pendingInviteLinks[m.id]?.invitationUrl && (
|
||||
{canShareStaffInviteLink(m) && (
|
||||
<button
|
||||
type="button"
|
||||
className="p-2 rounded-md text-text-secondary hover:bg-background-card/80 hover:text-text-primary"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(pendingInviteLinks[m.id].invitationUrl);
|
||||
setCopiedInviteMembershipId(m.id);
|
||||
setTimeout(() => setCopiedInviteMembershipId(null), 1500);
|
||||
} catch {
|
||||
setError('Could not copy invitation link');
|
||||
}
|
||||
}}
|
||||
aria-label="Copy invite link"
|
||||
title="Copy invite link"
|
||||
className="p-2 rounded-md text-text-secondary hover:bg-background-card/80 hover:text-text-primary disabled:opacity-50"
|
||||
disabled={copyingInviteMembershipId === m.id}
|
||||
onClick={() => void copyStaffInviteLink(m)}
|
||||
aria-label="Copy invitation link"
|
||||
title="Copy invitation link (generates a new link if needed)"
|
||||
>
|
||||
{copiedInviteMembershipId === m.id ? (
|
||||
<Check className="w-4 h-4" />
|
||||
|
||||
Reference in New Issue
Block a user