Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
99 lines
3.5 KiB
TypeScript
99 lines
3.5 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { Loader2, MailOpen } from "lucide-react";
|
|
import { ApiError, acceptMyInvite, listMyInvites, type WorkspaceInvite } from "@/lib/api";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { roleLabel } from "@/components/team/roles";
|
|
import { useApiToken } from "@/lib/use-api-token";
|
|
import type { WorkspaceRole } from "@/lib/types";
|
|
import { friendlyErrorMessage } from "@/src/shared/errors/friendly";
|
|
|
|
export interface MyInvitationsProps {
|
|
/** Called with the joined workspace id after a successful accept. */
|
|
onAccepted: (workspaceId: string | undefined) => void;
|
|
}
|
|
|
|
function messageFor(err: unknown, fallback: string): string {
|
|
return friendlyErrorMessage(err, fallback);
|
|
}
|
|
|
|
/**
|
|
* Pending workspace invitations addressed to the signed-in user's email
|
|
* (GET /me/invites), each with a one-click Join. Renders nothing when there
|
|
* are none, so it can sit at the top of the workspace page unconditionally.
|
|
*/
|
|
export function MyInvitations({ onAccepted }: Readonly<MyInvitationsProps>) {
|
|
const getApiToken = useApiToken();
|
|
const [invites, setInvites] = React.useState<readonly WorkspaceInvite[]>([]);
|
|
const [pendingId, setPendingId] = React.useState<string | null>(null);
|
|
const [error, setError] = React.useState("");
|
|
|
|
React.useEffect(() => {
|
|
let cancelled = false;
|
|
void (async () => {
|
|
try {
|
|
const token = await getApiToken();
|
|
const rows = await listMyInvites({ token });
|
|
if (!cancelled) setInvites(rows);
|
|
} catch {
|
|
// Guests and signed-out visitors have no inbox; nothing to show.
|
|
if (!cancelled) setInvites([]);
|
|
}
|
|
})();
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [getApiToken]);
|
|
|
|
const accept = async (invite: WorkspaceInvite) => {
|
|
setPendingId(invite.id);
|
|
setError("");
|
|
try {
|
|
const token = await getApiToken();
|
|
const result = await acceptMyInvite(invite.id, { token });
|
|
setInvites((prev) => prev.filter((i) => i.id !== invite.id));
|
|
onAccepted(result.workspace_id ?? invite.workspace_id);
|
|
} catch (err) {
|
|
setError(messageFor(err, "Couldn't join this workspace."));
|
|
} finally {
|
|
setPendingId(null);
|
|
}
|
|
};
|
|
|
|
if (invites.length === 0) return null;
|
|
|
|
return (
|
|
<Card className="mb-6 border-primary/40 bg-primary/5">
|
|
<CardContent className="space-y-3 py-4">
|
|
<p className="flex items-center gap-2 font-medium">
|
|
<MailOpen className="size-4 text-primary" aria-hidden />
|
|
You have {invites.length} workspace invitation{invites.length === 1 ? "" : "s"}
|
|
</p>
|
|
<ul className="space-y-2">
|
|
{invites.map((invite) => (
|
|
<li key={invite.id} className="flex flex-wrap items-center justify-between gap-2 text-sm">
|
|
<span>
|
|
<span className="font-medium">{invite.workspace_name || "A workspace"}</span>{" "}
|
|
<span className="text-muted-foreground">
|
|
as {roleLabel(invite.role as WorkspaceRole)}
|
|
</span>
|
|
</span>
|
|
<Button size="sm" onClick={() => void accept(invite)} disabled={pendingId !== null}>
|
|
{pendingId === invite.id && <Loader2 className="size-4 animate-spin" aria-hidden />}
|
|
Join
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{error && (
|
|
<p className="text-sm text-destructive" role="alert">
|
|
{error}
|
|
</p>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|