Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Set max JSX depth to 9 (#8182)

James Brunton41e8158063e1
diff --git a/frontend/editor/src/cloud/components/shared/config/configSections/TeamSection.tsx b/frontend/editor/src/cloud/components/shared/config/configSections/TeamSection.tsx
index 4541486ab8..bf6c56793d 100644
--- a/frontend/editor/src/cloud/components/shared/config/configSections/TeamSection.tsx
+++ b/frontend/editor/src/cloud/components/shared/config/configSections/TeamSection.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from "react";
+import React, { useState, useEffect, type ReactNode } from "react";
import {
TextInput,
Group,
@@ -14,11 +14,571 @@ import { Button } from "@app/ui/Button";
import { ActionIcon } from "@app/ui/ActionIcon";
import { StatusBadge } from "@app/ui/StatusBadge";
import { useTranslation } from "react-i18next";
-import { useSaaSTeam } from "@app/contexts/SaaSTeamContext";
+import {
+ useSaaSTeam,
+ type TeamInvitation,
+ type TeamMember,
+} from "@app/contexts/SaaSTeamContext";
import { Icon } from "@app/ui/Icon";
import { Z_INDEX_OVER_CONFIG_MODAL } from "@app/styles/zIndex";
import apiClient from "@app/services/apiClient";
+const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+
+interface TransferOwnershipModalProps {
+ targetEmail: string | null;
+ error: string | null;
+ transferring: boolean;
+ onCancel: () => void;
+ onConfirm: () => void;
+}
+
+function TransferOwnershipModal({
+ targetEmail,
+ error,
+ transferring,
+ onCancel,
+ onConfirm,
+}: TransferOwnershipModalProps) {
+ const { t } = useTranslation();
+ return (
+ <Modal
+ opened={targetEmail !== null}
+ onClose={onCancel}
+ title={t("team.transferTitle", "Transfer team ownership")}
+ zIndex={Z_INDEX_OVER_CONFIG_MODAL + 1}
+ >
+ <Stack>
+ {error && <Alert color="red">{error}</Alert>}
+ <Text>
+ {t(
+ "team.transferBody",
+ "Make {{email}} the team owner? They will control team membership and organization billing settings. You will become a member. The team's subscription and wallet stay with the team.",
+ { email: targetEmail ?? undefined },
+ )}
+ </Text>
+ <Group justify="flex-end">
+ <Button variant="tertiary" disabled={transferring} onClick={onCancel}>
+ {t("common.cancel", "Cancel")}
+ </Button>
+ <Button accent="danger" disabled={transferring} onClick={onConfirm}>
+ {t("team.makeOwner", "Make owner")}
+ </Button>
+ </Group>
+ </Stack>
+ </Modal>
+ );
+}
+
+interface NoOwnerAlertProps {
+ show: boolean;
+ busy: boolean;
+ onClaim: () => void;
+}
+
+function NoOwnerAlert({ show, busy, onClaim }: NoOwnerAlertProps) {
+ const { t } = useTranslation();
+ if (!show) return null;
+ return (
+ <Alert title={t("team.noOwner", "This team has no owner")}>
+ <Text>
+ {t(
+ "team.recoverBody",
+ "An existing member can recover ownership to manage the team and its billing settings.",
+ )}
+ </Text>
+ <Button disabled={busy} onClick={onClaim}>
+ {t("team.recoverOwner", "Become team owner")}
+ </Button>
+ </Alert>
+ );
+}
+
+interface TeamNameEditorProps {
+ value: string;
+ saving: boolean;
+ onChange: (value: string) => void;
+ onSubmit: () => void;
+ onCancel: () => void;
+}
+
+function TeamNameEditor({
+ value,
+ saving,
+ onChange,
+ onSubmit,
+ onCancel,
+}: TeamNameEditorProps) {
+ const { t } = useTranslation();
+ return (
+ <Group gap="xs" align="center">
+ <TextInput
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ placeholder={t("team.namePlaceholder", "Team name")}
+ style={{ flex: 1, maxWidth: 300 }}
+ autoFocus
+ onKeyDown={(e) => {
+ if (e.key === "Enter") onSubmit();
+ if (e.key === "Escape") onCancel();
+ }}
+ />
+ <ActionIcon
+ onClick={onSubmit}
+ loading={saving}
+ disabled={!value.trim()}
+ aria-label={t("team.renameSubmit", "Save team name")}
+ >
+ <Icon name="check" size="1rem" />
+ </ActionIcon>
+ <ActionIcon
+ variant="tertiary"
+ onClick={onCancel}
+ disabled={saving}
+ aria-label={t("team.renameCancel", "Cancel rename")}
+ >
+ <Icon name="x" size="1rem" />
+ </ActionIcon>
+ </Group>
+ );
+}
+
+interface TeamNameDisplayProps {
+ name: string;
+ memberCount: number;
+ isLeader: boolean;
+ isPersonal: boolean;
+ onRename: () => void;
+}
+
+function TeamNameDisplay({
+ name,
+ memberCount,
+ isLeader,
+ isPersonal,
+ onRename,
+}: TeamNameDisplayProps) {
+ const { t } = useTranslation();
+ return (
+ <>
+ <Group gap="xs" align="center">
+ <Text fw={600} size="lg">
+ {name}
+ </Text>
+ {isLeader && !isPersonal && (
+ <ActionIcon
+ variant="tertiary"
+ size="sm"
+ onClick={onRename}
+ aria-label={t("team.editName", "Edit team name")}
+ >
+ <Icon name="pencil" size="1rem" />
+ </ActionIcon>
+ )}
+ {isLeader && (
+ <StatusBadge tone="info" showDot={false}>
+ {t("team.leader", "LEADER")}
+ </StatusBadge>
+ )}
+ {isPersonal && (
+ <StatusBadge tone="neutral" showDot={false}>
+ {t("team.personal", "Personal")}
+ </StatusBadge>
+ )}
+ </Group>
+ {!isPersonal && (
+ <Text size="sm" c="dimmed" mt={4}>
+ {t("team.memberCount", "{{count}} team members", {
+ count: memberCount,
+ })}
+ </Text>
+ )}
+ </>
+ );
+}
+
+interface TeamTitleProps {
+ editing: boolean;
+ name: string;
+ memberCount: number;
+ isLeader: boolean;
+ isPersonal: boolean;
+ draftName: string;
+ saving: boolean;
+ onDraftNameChange: (value: string) => void;
+ onStartRename: () => void;
+ onSubmitRename: () => void;
+ onCancelRename: () => void;
+}
+
+function TeamTitle({
+ editing,
+ name,
+ memberCount,
+ isLeader,
+ isPersonal,
+ draftName,
+ saving,
+ onDraftNameChange,
+ onStartRename,
+ onSubmitRename,
+ onCancelRename,
+}: TeamTitleProps) {
+ if (editing) {
+ return (
+ <TeamNameEditor
+ value={draftName}
+ saving={saving}
+ onChange={onDraftNameChange}
+ onSubmit={onSubmitRename}
+ onCancel={onCancelRename}
+ />
+ );
+ }
+ return (
+ <TeamNameDisplay
+ name={name}
+ memberCount={memberCount}
+ isLeader={isLeader}
+ isPersonal={isPersonal}
+ onRename={onStartRename}
+ />
+ );
+}
+
+interface TeamHeaderProps {
+ canLeave: boolean;
+ onLeave: () => void;
+ children: ReactNode;
+}
+
+function TeamHeader({ canLeave, onLeave, children }: TeamHeaderProps) {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Group justify="space-between" align="center">
+ <div style={{ flex: 1 }}>{children}</div>
+ {canLeave && (
+ <Button
+ accent="danger"
+ variant="secondary"
+ size="sm"
+ onClick={onLeave}
+ leftSection={<Icon name="log-out" size="1rem" />}
+ >
+ {t("team.leaveButton", "Leave Team")}
+ </Button>
+ )}
+ </Group>
+ </div>
+ );
+}
+
+interface DismissibleAlertProps {
+ message: string | null;
+ color: string;
+ onClose: () => void;
+}
+
+function DismissibleAlert({ message, color, onClose }: DismissibleAlertProps) {
+ if (!message) return null;
+ return (
+ <Alert color={color} onClose={onClose} withCloseButton>
+ {message}
+ </Alert>
+ );
+}
+
+interface InviteMemberFormProps {
+ show: boolean;
+ email: string;
+ inviting: boolean;
+ onEmailChange: (email: string) => void;
+ onSubmit: (e: React.FormEvent) => void;
+}
+
+function InviteMemberForm({
+ show,
+ email,
+ inviting,
+ onEmailChange,
+ onSubmit,
+}: InviteMemberFormProps) {
+ const { t } = useTranslation();
+ if (!show) return null;
+ const invalid = !EMAIL_PATTERN.test(email);
+ return (
+ <div>
+ <Text fw={600} size="md" mb="sm">
+ {t("team.invite.title", "Invite Team Member")}
+ </Text>
+ <form onSubmit={onSubmit}>
+ <Group>
+ <TextInput
+ type="email"
+ placeholder={t("team.invite.placeholder", "[email protected]")}
+ value={email}
+ onChange={(e) => onEmailChange(e.target.value)}
+ style={{ flex: 1 }}
+ required
+ error={
+ email && invalid
+ ? t("team.invite.invalidEmail", "Invalid email format")
+ : undefined
+ }
+ />
+ <Button
+ type="submit"
+ loading={inviting}
+ disabled={!email.trim() || invalid}
+ >
+ {t("team.invite.sendButton", "Send Invite")}
+ </Button>
+ </Group>
+ </form>
+ </div>
+ );
+}
+
+function ColumnHeader({ children }: { children: ReactNode }) {
+ return (
+ <Table.Th
+ style={{
+ fontWeight: 600,
+ fontSize: "0.875rem",
+ color: "var(--mantine-color-gray-7)",
+ }}
+ >
+ {children}
+ </Table.Th>
+ );
+}
+
+function MemberRoleBadge({ role }: { role: TeamMember["role"] }) {
+ const { t } = useTranslation();
+ const isOwner = role === "LEADER";
+ return (
+ <Badge
+ size="sm"
+ color={isOwner ? "blue" : undefined}
+ style={
+ isOwner
+ ? undefined
+ : {
+ backgroundColor: "var(--c-surface-raised)",
+ color: "var(--c-accent-fg)",
+ }
+ }
+ >
+ {isOwner
+ ? t("users.role.orgOwner", "Org Owner")
+ : t("users.role.member", "Member")}
+ </Badge>
+ );
+}
+
+interface MemberActionsMenuProps {
+ member: TeamMember;
+ onMakeOwner: () => void;
+ onRemove: () => void;
+}
+
+function MemberActionsMenu({
+ member,
+ onMakeOwner,
+ onRemove,
+}: MemberActionsMenuProps) {
+ const { t } = useTranslation();
+ if (member.role === "LEADER") return null;
+ return (
+ <Menu position="bottom-end" withinPortal zIndex={Z_INDEX_OVER_CONFIG_MODAL}>
+ <Menu.Target>
+ <ActionIcon
+ variant="tertiary"
+ aria-label={t("team.members.actions", "Member actions")}
+ >
+ <Icon name="ellipsis-vertical" size="1rem" />
+ </ActionIcon>
+ </Menu.Target>
+ <Menu.Dropdown>
+ <Menu.Item onClick={onMakeOwner}>
+ {t("team.makeOwner", "Make owner")}
+ </Menu.Item>
+ <Menu.Item
+ color="red"
+ leftSection={<Icon name="user-minus" size="1rem" />}
+ onClick={onRemove}
+ >
+ {t("team.members.remove", "Remove from Team")}
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ );
+}
+
+interface TeamMemberRowProps extends MemberActionsMenuProps {
+ showActions: boolean;
+}
+
+function TeamMemberRow({ showActions, ...actions }: TeamMemberRowProps) {
+ const { member } = actions;
+ return (
+ <Table.Tr>
+ <Table.Td>
+ <Text size="sm" fw={500}>
+ {member.username}
+ </Text>
+ </Table.Td>
+ <Table.Td>
+ <Text size="sm" c="dimmed">
+ {member.email}
+ </Text>
+ </Table.Td>
+ <Table.Td>
+ <MemberRoleBadge role={member.role} />
+ </Table.Td>
+ {showActions && (
+ <Table.Td>
+ <MemberActionsMenu {...actions} />
+ </Table.Td>
+ )}
+ </Table.Tr>
+ );
+}
+
+interface PendingInvitationRowProps {
+ invitation: TeamInvitation;
+ showActions: boolean;
+ onCancel: () => void;
+}
+
+function PendingInvitationRow({
+ invitation,
+ showActions,
+ onCancel,
+}: PendingInvitationRowProps) {
+ const { t } = useTranslation();
+ return (
+ <Table.Tr>
+ <Table.Td>
+ <Text size="sm" fw={500} c="dimmed" fs="italic">
+ {invitation.inviteeEmail.split("@")[0]}
+ </Text>
+ </Table.Td>
+ <Table.Td>
+ <Text size="sm" c="dimmed">
+ {invitation.inviteeEmail}
+ </Text>
+ </Table.Td>
+ <Table.Td>
+ <Badge size="sm" color="yellow" variant="light">
+ {t("team.members.pending", "PENDING")}
+ </Badge>
+ </Table.Td>
+ {showActions && (
+ <Table.Td>
+ <ActionIcon
+ variant="tertiary"
+ accent="danger"
+ onClick={onCancel}
+ aria-label={t("team.invite.cancelLabel", "Cancel invitation")}
+ >
+ <Icon name="x" size="1rem" />
+ </ActionIcon>
+ </Table.Td>
+ )}
+ </Table.Tr>
+ );
+}
+
+interface TeamMembersTableProps {
+ members: TeamMember[];
+ invitations: TeamInvitation[];
+ showActions: boolean;
+ onMakeOwner: (member: TeamMember) => void;
+ onRemove: (member: TeamMember) => void;
+ onCancelInvitation: (invitation: TeamInvitation) => void;
+}
+
+function TeamMemberRows({
+ members,
+ invitations,
+ showActions,
+ onMakeOwner,
+ onRemove,
+ onCancelInvitation,
+}: TeamMembersTableProps) {
+ const { t } = useTranslation();
+ if (members.length === 0 && invitations.length === 0) {
+ return (
+ <Table.Tr>
+ <Table.Td colSpan={showActions ? 4 : 3}>
+ <Text ta="center" c="dimmed" py="xl">
+ {t("team.members.empty", "No team members yet.")}
+ </Text>
+ </Table.Td>
+ </Table.Tr>
+ );
+ }
+ return (
+ <>
+ {members.map((member) => (
+ <TeamMemberRow
+ key={`member-${member.id}`}
+ member={member}
+ showActions={showActions}
+ onMakeOwner={() => onMakeOwner(member)}
+ onRemove={() => onRemove(member)}
+ />
+ ))}
+ {invitations
+ .filter((inv) => inv.status === "PENDING")
+ .map((invitation) => (
+ <PendingInvitationRow
+ key={`invitation-${invitation.invitationId}`}
+ invitation={invitation}
+ showActions={showActions}
+ onCancel={() => onCancelInvitation(invitation)}
+ />
+ ))}
+ </>
+ );
+}
+
+function TeamMembersTable(props: TeamMembersTableProps) {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Text fw={600} size="md" mb="sm">
+ {t("team.members.title", "Team Members")}
+ </Text>
+ <Table
+ horizontalSpacing="md"
+ verticalSpacing="sm"
+ withRowBorders
+ highlightOnHover
+ style={{
+ "--table-border-color": "var(--mantine-color-gray-3)",
+ }}
+ >
+ <Table.Thead>
+ <Table.Tr style={{ backgroundColor: "var(--mantine-color-gray-0)" }}>
+ <ColumnHeader>{t("team.members.nameColumn", "Name")}</ColumnHeader>
+ <ColumnHeader>
+ {t("team.members.emailColumn", "Email")}
+ </ColumnHeader>
+ <ColumnHeader>{t("team.members.roleColumn", "Role")}</ColumnHeader>
+ {props.showActions && <Table.Th style={{ width: 50 }}></Table.Th>}
+ </Table.Tr>
+ </Table.Thead>
+ <Table.Tbody>
+ <TeamMemberRows {...props} />
+ </Table.Tbody>
+ </Table>
+ </div>
+ );
+}
+
const TeamSection: React.FC = () => {
const { t } = useTranslation();
const {
@@ -215,6 +775,48 @@ const TeamSection: React.FC = () => {
}
};
+ const handleConfirmTransfer = async () => {
+ if (!transferTarget) return;
+ setTransferring(true);
+ setError(null);
+ try {
+ await transferLeadership(transferTarget.id);
+ setTransferTarget(null);
+ setSuccess(
+ t(
+ "team.transferSuccess",
+ "Team ownership transferred. Your role is now member.",
+ ),
+ );
+ } catch {
+ setError(
+ t(
+ "team.transferError",
+ "Ownership could not be transferred. Refresh the team and try again.",
+ ),
+ );
+ } finally {
+ setTransferring(false);
+ }
+ };
+
+ const handleClaimOwnership = async () => {
+ setTransferring(true);
+ try {
+ await claimLeadership();
+ setSuccess(t("team.recoverSuccess", "You are now the team owner."));
+ } catch {
+ setError(
+ t(
+ "team.transferError",
+ "Ownership could not be transferred. Refresh the team and try again.",
+ ),
+ );
+ } finally {
+ setTransferring(false);
+ }
+ };
+
if (!currentTeam) {
return (
<Alert color="gray">
@@ -223,420 +825,80 @@ const TeamSection: React.FC = () => {
);
}
+ const showMemberActions = isTeamLeader && !isPersonalTeam;
+
return (
<Stack gap="lg">
- <Modal
- opened={transferTarget !== null}
- onClose={() => !transferring && setTransferTarget(null)}
- title={t("team.transferTitle", "Transfer team ownership")}
- zIndex={Z_INDEX_OVER_CONFIG_MODAL + 1}
+ <TransferOwnershipModal
+ targetEmail={transferTarget?.email ?? null}
+ error={error}
+ transferring={transferring}
+ onCancel={() => !transferring && setTransferTarget(null)}
+ onConfirm={handleConfirmTransfer}
+ />
+
+ <NoOwnerAlert
+ show={
+ !isPersonalTeam &&
+ teamMembers.length > 0 &&
+ !teamMembers.some((m) => m.role === "LEADER")
+ }
+ busy={transferring}
+ onClaim={handleClaimOwnership}
+ />
+ <TeamHeader
+ canLeave={!isPersonalTeam && !isTeamLeader && !isEditingName}
+ onLeave={handleLeaveTeam}
>
- <Stack>
- {error && <Alert color="red">{error}</Alert>}
- <Text>
- {t(
- "team.transferBody",
- "Make {{email}} the team owner? They will control team membership and organization billing settings. You will become a member. The team's subscription and wallet stay with the team.",
- { email: transferTarget?.email },
- )}
- </Text>
- <Group justify="flex-end">
- <Button
- variant="tertiary"
- disabled={transferring}
- onClick={() => setTransferTarget(null)}
- >
- {t("common.cancel", "Cancel")}
- </Button>
- <Button
- accent="danger"
- disabled={transferring}
- onClick={async () => {
- if (!transferTarget) return;
- setTransferring(true);
- setError(null);
- try {
- await transferLeadership(transferTarget.id);
- setTransferTarget(null);
- setSuccess(
- t(
- "team.transferSuccess",
- "Team ownership transferred. Your role is now member.",
- ),
- );
- } catch {
- setError(
- t(
- "team.transferError",
- "Ownership could not be transferred. Refresh the team and try again.",
- ),
- );
- } finally {
- setTransferring(false);
- }
- }}
- >
- {t("team.makeOwner", "Make owner")}
- </Button>
- </Group>
- </Stack>
- </Modal>
-
- {!isPersonalTeam &&
- teamMembers.length > 0 &&
- !teamMembers.some((m) => m.role === "LEADER") && (
- <Alert title={t("team.noOwner", "This team has no owner")}>
- <Text>
- {t(
- "team.recoverBody",
- "An existing member can recover ownership to manage the team and its billing settings.",
- )}
- </Text>
- <Button
- disabled={transferring}
- onClick={async () => {
- setTransferring(true);
- try {
- await claimLeadership();
- setSuccess(
- t("team.recoverSuccess", "You are now the team owner."),
- );
- } catch {
- setError(
- t(
- "team.transferError",
- "Ownership could not be transferred. Refresh the team and try again.",
- ),
- );
- } finally {
- setTransferring(false);
- }
- }}
- >
- {t("team.recoverOwner", "Become team owner")}
- </Button>
- </Alert>
- )}
- {/* Header */}
- <div>
- <Group justify="space-between" align="center">
- <div style={{ flex: 1 }}>
- {isEditingName ? (
- <Group gap="xs" align="center">
- <TextInput
- value={newTeamName}
- onChange={(e) => setNewTeamName(e.target.value)}
- placeholder={t("team.namePlaceholder", "Team name")}
- style={{ flex: 1, maxWidth: 300 }}
- autoFocus
- onKeyDown={(e) => {
- if (e.key === "Enter") handleRenameSubmit();
- if (e.key === "Escape") handleCancelRename();
- }}
- />
- <ActionIcon
- onClick={handleRenameSubmit}
- loading={renamingTeam}
- disabled={!newTeamName.trim()}
- aria-label={t("team.renameSubmit", "Save team name")}
- >
- <Icon name="check" size="1rem" />
- </ActionIcon>
- <ActionIcon
- variant="tertiary"
- onClick={handleCancelRename}
- disabled={renamingTeam}
- aria-label={t("team.renameCancel", "Cancel rename")}
- >
- <Icon name="x" size="1rem" />
- </ActionIcon>
- </Group>
- ) : (
- <Group gap="xs" align="center">
- <Text fw={600} size="lg">
- {currentTeam.name}
- </Text>
- {isTeamLeader && !isPersonalTeam && (
- <ActionIcon
- variant="tertiary"
- size="sm"
- onClick={handleStartRename}
- aria-label={t("team.editName", "Edit team name")}
- >
- <Icon name="pencil" size="1rem" />
- </ActionIcon>
- )}
- {isTeamLeader && (
- <StatusBadge tone="info" showDot={false}>
- {t("team.leader", "LEADER")}
- </StatusBadge>
- )}
- {isPersonalTeam && (
- <StatusBadge tone="neutral" showDot={false}>
- {t("team.personal", "Personal")}
- </StatusBadge>
- )}
- </Group>
- )}
- {!isEditingName && !isPersonalTeam && (
- <Text size="sm" c="dimmed" mt={4}>
- {t("team.memberCount", "{{count}} team members", {
- count: currentTeam.seatsUsed,
- })}
- </Text>
- )}
- </div>
- {!isPersonalTeam && !isTeamLeader && !isEditingName && (
- <Button
- accent="danger"
- variant="secondary"
- size="sm"
- onClick={handleLeaveTeam}
- leftSection={<Icon name="log-out" size="1rem" />}
- >
- {t("team.leaveButton", "Leave Team")}
- </Button>
- )}
- </Group>
- </div>
-
- {/* Error/Success Messages */}
- {error && (
- <Alert color="red" onClose={() => setError(null)} withCloseButton>
- {error}
- </Alert>
- )}
-
- {success && (
- <Alert color="green" onClose={() => setSuccess(null)} withCloseButton>
- {success}
- </Alert>
- )}
-
- {/* Invite Members */}
- {isTeamLeader && (
- <div>
- <Text fw={600} size="md" mb="sm">
- {t("team.invite.title", "Invite Team Member")}
- </Text>
- <form onSubmit={handleInvite}>
- <Group>
- <TextInput
- type="email"
- placeholder={t("team.invite.placeholder", "[email protected]")}
- value={inviteEmail}
- onChange={(e) => setInviteEmail(e.target.value)}
- style={{ flex: 1 }}
- required
- error={
- inviteEmail && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inviteEmail)
- ? t("team.invite.invalidEmail", "Invalid email format")
- : undefined
- }
- />
- <Button
- type="submit"
- loading={inviting}
- disabled={
- !inviteEmail.trim() ||
- !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inviteEmail)
- }
- >
- {t("team.invite.sendButton", "Send Invite")}
- </Button>
- </Group>
- </form>
- </div>
- )}
-
- {/* Team Members Table */}
- <div>
- <Text fw={600} size="md" mb="sm">
- {t("team.members.title", "Team Members")}
- </Text>
- <Table
- horizontalSpacing="md"
- verticalSpacing="sm"
- withRowBorders
- highlightOnHover
- style={{
- "--table-border-color": "var(--mantine-color-gray-3)",
- }}
- >
- <Table.Thead>
- <Table.Tr
- style={{ backgroundColor: "var(--mantine-color-gray-0)" }}
- >
- <Table.Th
- style={{
- fontWeight: 600,
- fontSize: "0.875rem",
- color: "var(--mantine-color-gray-7)",
- }}
- >
- {t("team.members.nameColumn", "Name")}
- </Table.Th>
- <Table.Th
- style={{
- fontWeight: 600,
- fontSize: "0.875rem",
- color: "var(--mantine-color-gray-7)",
- }}
- >
- {t("team.members.emailColumn", "Email")}
- </Table.Th>
- <Table.Th
- style={{
- fontWeight: 600,
- fontSize: "0.875rem",
- color: "var(--mantine-color-gray-7)",
- }}
- >
- {t("team.members.roleColumn", "Role")}
- </Table.Th>
- {isTeamLeader && !isPersonalTeam && (
- <Table.Th style={{ width: 50 }}></Table.Th>
- )}
- </Table.Tr>
- </Table.Thead>
- <Table.Tbody>
- {teamMembers.length === 0 && teamInvitations.length === 0 ? (
- <Table.Tr>
- <Table.Td colSpan={isTeamLeader && !isPersonalTeam ? 4 : 3}>
- <Text ta="center" c="dimmed" py="xl">
- {t("team.members.empty", "No team members yet.")}
- </Text>
- </Table.Td>
- </Table.Tr>
- ) : (
- <>
- {/* Active Members */}
- {teamMembers.map((member) => (
- <Table.Tr key={`member-${member.id}`}>
- <Table.Td>
- <Text size="sm" fw={500}>
- {member.username}
- </Text>
- </Table.Td>
- <Table.Td>
- <Text size="sm" c="dimmed">
- {member.email}
- </Text>
- </Table.Td>
- <Table.Td>
- <Badge
- size="sm"
- color={member.role === "LEADER" ? "blue" : undefined}
- style={
- member.role !== "LEADER"
- ? {
- backgroundColor: "var(--c-surface-raised)",
- color: "var(--c-accent-fg)",
- }
- : undefined
- }
- >
- {member.role === "LEADER"
- ? t("users.role.orgOwner", "Org Owner")
- : t("users.role.member", "Member")}
- </Badge>
- </Table.Td>
- {isTeamLeader && !isPersonalTeam && (
- <Table.Td>
- {member.role !== "LEADER" && (
- <Menu
- position="bottom-end"
- withinPortal
- zIndex={Z_INDEX_OVER_CONFIG_MODAL}
- >
- <Menu.Target>
- <ActionIcon
- variant="tertiary"
- aria-label={t(
- "team.members.actions",
- "Member actions",
- )}
- >
- <Icon name="ellipsis-vertical" size="1rem" />
- </ActionIcon>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- onClick={() =>
- setTransferTarget({
- id: member.id,
- email: member.email,
- })
- }
- >
- {t("team.makeOwner", "Make owner")}
- </Menu.Item>
- <Menu.Item
- color="red"
- leftSection={
- <Icon name="user-minus" size="1rem" />
- }
- onClick={() =>
- handleRemove(member.id, member.email)
- }
- >
- {t("team.members.remove", "Remove from Team")}
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- )}
- </Table.Td>
- )}
- </Table.Tr>
- ))}
-
- {/* Pending Invitations */}
- {teamInvitations
- .filter((inv) => inv.status === "PENDING")
- .map((invitation) => (
- <Table.Tr key={`invitation-${invitation.invitationId}`}>
- <Table.Td>
- <Text size="sm" fw={500} c="dimmed" fs="italic">
- {invitation.inviteeEmail.split("@")[0]}
- </Text>
- </Table.Td>
- <Table.Td>
- <Text size="sm" c="dimmed">
- {invitation.inviteeEmail}
- </Text>
- </Table.Td>
- <Table.Td>
- <Badge size="sm" color="yellow" variant="light">
- {t("team.members.pending", "PENDING")}
- </Badge>
- </Table.Td>
- {isTeamLeader && !isPersonalTeam && (
- <Table.Td>
- <ActionIcon
- variant="tertiary"
- accent="danger"
- onClick={() =>
- handleCancelInvitation(
- invitation.invitationId,
- invitation.inviteeEmail,
- )
- }
- aria-label={t(
- "team.invite.cancelLabel",
- "Cancel invitation",
- )}
- >
- <Icon name="x" size="1rem" />
- </ActionIcon>
- </Table.Td>
- )}
- </Table.Tr>
- ))}
- </>
- )}
- </Table.Tbody>
- </Table>
- </div>
+ <TeamTitle
+ editing={isEditingName}
+ name={currentTeam.name}
+ memberCount={currentTeam.seatsUsed}
+ isLeader={isTeamLeader}
+ isPersonal={isPersonalTeam}
+ draftName={newTeamName}
+ saving={renamingTeam}
+ onDraftNameChange={setNewTeamName}
+ onStartRename={handleStartRename}
+ onSubmitRename={handleRenameSubmit}
+ onCancelRename={handleCancelRename}
+ />
+ </TeamHeader>
+
+ <DismissibleAlert
+ message={error}
+ color="red"
+ onClose={() => setError(null)}
+ />
+ <DismissibleAlert
+ message={success}
+ color="green"
+ onClose={() => setSuccess(null)}
+ />
+
+ <InviteMemberForm
+ show={isTeamLeader}
+ email={inviteEmail}
+ inviting={inviting}
+ onEmailChange={setInviteEmail}
+ onSubmit={handleInvite}
+ />
+
+ <TeamMembersTable
+ members={teamMembers}
+ invitations={teamInvitations}
+ showActions={showMemberActions}
+ onMakeOwner={(member) =>
+ setTransferTarget({ id: member.id, email: member.email })
+ }
+ onRemove={(member) => handleRemove(member.id, member.email)}
+ onCancelInvitation={(invitation) =>
+ handleCancelInvitation(
+ invitation.invitationId,
+ invitation.inviteeEmail,
+ )
+ }
+ />
</Stack>
);
};
diff --git a/frontend/editor/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx b/frontend/editor/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx
index 97f0eb7139..921e5b7578 100644
--- a/frontend/editor/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx
+++ b/frontend/editor/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from "react";
+import React, { useState, useEffect, type ReactNode } from "react";
import {
Card,
Text,
@@ -21,13 +21,417 @@ import auditService, {
import { Z_INDEX_OVER_CONFIG_MODAL } from "@app/styles/zIndex";
import { useAuditFilters } from "@app/hooks/useAuditFilters";
import AuditFiltersForm from "@app/components/shared/config/configSections/audit/AuditFiltersForm";
-import { Icon } from "@app/ui/Icon";
+import { Icon, type IconName } from "@app/ui/Icon";
+
interface AuditEventsTableProps {
loginEnabled?: boolean;
captureFileHash?: boolean;
capturePdfAuthor?: boolean;
}
+type SortKey = "timestamp" | "eventType" | "username" | "ipAddress";
+
+const EVENT_TYPE_COLORS: Record<string, string> = {
+ USER_LOGIN: "green",
+ USER_LOGOUT: "gray",
+ USER_FAILED_LOGIN: "red",
+ USER_PROFILE_UPDATE: "blue",
+ SETTINGS_CHANGED: "orange",
+ FILE_OPERATION: "cyan",
+ PDF_PROCESS: "violet",
+ UI_DATA: "gray",
+ HTTP_REQUEST: "indigo",
+};
+
+function getEventTypeColor(type: string): string {
+ return EVENT_TYPE_COLORS[type] || "blue";
+}
+
+function formatDate(dateString: string): string {
+ return new Date(dateString).toLocaleString();
+}
+
+interface EventFileInfo {
+ documentName: string;
+ author: string;
+ fileHash: string;
+}
+
+/** Reads the first file in an event's details; author and hash only when a column shows them. */
+function getEventFileInfo(
+ event: AuditEvent,
+ withAuthorAndHash: boolean,
+): EventFileInfo {
+ const info = { documentName: "", author: "", fileHash: "" };
+ if (!event.details || typeof event.details !== "object") return info;
+ const files = event.details.files;
+ if (!Array.isArray(files) || files.length === 0) return info;
+ const firstFile = files[0] as Record<string, unknown>;
+ info.documentName = typeof firstFile.name === "string" ? firstFile.name : "";
+ if (withAuthorAndHash) {
+ info.author =
+ typeof firstFile.pdfAuthor === "string" ? firstFile.pdfAuthor : "";
+ info.fileHash =
+ typeof firstFile.fileHash === "string"
+ ? firstFile.fileHash.substring(0, 16) + "..."
+ : "";
+ }
+ return info;
+}
+
+interface SortableHeaderProps {
+ label: string;
+ icon: IconName;
+ onSort: () => void;
+}
+
+function SortableHeader({ label, icon, onSort }: SortableHeaderProps) {
+ return (
+ <Table.Th
+ style={{
+ fontWeight: 600,
+ color: "var(--mantine-color-gray-7)",
+ padding: "0.5rem",
+ }}
+ fz="sm"
+ >
+ <Button
+ type="button"
+ variant="tertiary"
+ hover={false}
+ onClick={onSort}
+ style={{
+ display: "flex",
+ alignItems: "center",
+ gap: "0.5rem",
+ cursor: "pointer",
+ userSelect: "none",
+ }}
+ >
+ {label}
+ <Icon name={icon} size="0.9rem" />
+ </Button>
+ </Table.Th>
+ );
+}
+
+function ColumnHeader({
+ children,
+ centered = false,
+}: {
+ children: ReactNode;
+ centered?: boolean;
+}) {
+ return (
+ <Table.Th
+ style={{
+ fontWeight: 600,
+ color: "var(--mantine-color-gray-7)",
+ }}
+ fz="sm"
+ ta={centered ? "center" : undefined}
+ >
+ {children}
+ </Table.Th>
+ );
+}
+
+interface EventColumns {
+ showAuthor: boolean;
+ showFileHash: boolean;
+}
+
+interface EventsTableHeaderProps extends EventColumns {
+ getSortIcon: (key: SortKey) => IconName;
+ onSort: (key: SortKey) => void;
+}
+
+function EventsTableHeader({
+ showAuthor,
+ showFileHash,
+ getSortIcon,
+ onSort,
+}: EventsTableHeaderProps) {
+ const { t } = useTranslation();
+ return (
+ <Table.Thead>
+ <Table.Tr style={{ backgroundColor: "var(--mantine-color-gray-0)" }}>
+ <SortableHeader
+ label={t("audit.events.timestamp", "Timestamp")}
+ icon={getSortIcon("timestamp")}
+ onSort={() => onSort("timestamp")}
+ />
+ <SortableHeader
+ label={t("audit.events.type", "Type")}
+ icon={getSortIcon("eventType")}
+ onSort={() => onSort("eventType")}
+ />
+ <SortableHeader
+ label={t("audit.events.user", "User")}
+ icon={getSortIcon("username")}
+ onSort={() => onSort("username")}
+ />
+ <ColumnHeader>
+ {t("audit.events.documentName", "Document Name")}
+ </ColumnHeader>
+ {showAuthor && (
+ <ColumnHeader>{t("audit.events.author", "Author")}</ColumnHeader>
+ )}
+ {showFileHash && (
+ <ColumnHeader>{t("audit.events.fileHash", "File Hash")}</ColumnHeader>
+ )}
+ <ColumnHeader centered>
+ {t("audit.events.actions", "Actions")}
+ </ColumnHeader>
+ </Table.Tr>
+ </Table.Thead>
+ );
+}
+
+function NoEventsRow({ colSpan }: { colSpan: number }) {
+ const { t } = useTranslation();
+ return (
+ <Table.Tr>
+ <Table.Td colSpan={colSpan}>
+ <Group justify="center" py="xl">
+ <Stack align="center" gap={0}>
+ <Icon name="search" size="2rem" style={{ opacity: 0.4 }} />
+ <Text ta="center" c="dimmed" size="sm">
+ {t("audit.events.noEvents", "No events found")}
+ </Text>
+ </Stack>
+ </Group>
+ </Table.Td>
+ </Table.Tr>
+ );
+}
+
+interface AuditEventRowProps extends EventColumns {
+ event: AuditEvent;
+ loginEnabled: boolean;
+ onViewDetails: () => void;
+}
+
+function AuditEventRow({
+ event,
+ showAuthor,
+ showFileHash,
+ loginEnabled,
+ onViewDetails,
+}: AuditEventRowProps) {
+ const { t } = useTranslation();
+ const { documentName, author, fileHash } = getEventFileInfo(
+ event,
+ showAuthor || showFileHash,
+ );
+ return (
+ <Table.Tr>
+ <Table.Td>
+ <Text size="sm">{formatDate(event.timestamp)}</Text>
+ </Table.Td>
+ <Table.Td>
+ <Badge
+ variant="light"
+ size="sm"
+ color={getEventTypeColor(event.eventType)}
+ >
+ {event.eventType}
+ </Badge>
+ </Table.Td>
+ <Table.Td>
+ <Text size="sm">{event.username}</Text>
+ </Table.Td>
+ <Table.Td>
+ <Text size="sm" title={documentName}>
+ {documentName || "—"}
+ </Text>
+ </Table.Td>
+ {showAuthor && (
+ <Table.Td>
+ <Text size="sm">{author}</Text>
+ </Table.Td>
+ )}
+ {showFileHash && (
+ <Table.Td>
+ <Text
+ size="sm"
+ title={fileHash}
+ style={{ fontFamily: "monospace", fontSize: "0.75rem" }}
+ >
+ {fileHash}
+ </Text>
+ </Table.Td>
+ )}
+ <Table.Td ta="center">
+ <Button
+ variant="tertiary"
+ size="sm"
+ onClick={onViewDetails}
+ disabled={!loginEnabled}
+ >
+ {t("audit.events.viewDetails", "View Details")}
+ </Button>
+ </Table.Td>
+ </Table.Tr>
+ );
+}
+
+interface EventRowsProps extends EventColumns {
+ events: AuditEvent[];
+ loginEnabled: boolean;
+ onViewDetails: (event: AuditEvent) => void;
+}
+
+function EventRows({ events, onViewDetails, ...row }: EventRowsProps) {
+ if (events.length === 0) {
+ const colSpan = 5 + (row.showAuthor ? 1 : 0) + (row.showFileHash ? 1 : 0);
+ return <NoEventsRow colSpan={colSpan} />;
+ }
+ return (
+ <>
+ {events.map((event) => (
+ <AuditEventRow
+ key={event.id}
+ event={event}
+ onViewDetails={() => onViewDetails(event)}
+ {...row}
+ />
+ ))}
+ </>
+ );
+}
+
+interface EventsPaginationProps {
+ page: number;
+ total: number;
+ onChange: (page: number) => void;
+}
+
+function EventsPagination({ page, total, onChange }: EventsPaginationProps) {
+ if (total <= 1) return null;
+ return (
+ <Group justify="center" mt="md">
+ <Pagination value={page} onChange={onChange} total={total} />
+ </Group>
+ );
+}
+
+interface AuditEventsResultsProps
+ extends EventRowsProps, Omit<EventsTableHeaderProps, keyof EventColumns> {
+ loading: boolean;
+ error: string | null;
+ page: number;
+ totalPages: number;
+ onPageChange: (page: number) => void;
+}
+
+function AuditEventsResults({
+ loading,
+ error,
+ page,
+ totalPages,
+ onPageChange,
+ getSortIcon,
+ onSort,
+ ...rows
+}: AuditEventsResultsProps) {
+ const { t } = useTranslation();
+ if (loading) {
+ return (
+ <div style={{ display: "flex", justifyContent: "center" }}>
+ <Loader size="lg" my="xl" />
+ </div>
+ );
+ }
+ if (error) {
+ return (
+ <Alert
+ color="red"
+ title={t("audit.events.error", "Error loading events")}
+ >
+ {error}
+ </Alert>
+ );
+ }
+ return (
+ <div
+ style={{
+ overflowX: "auto",
+ overflowY: "hidden",
+ marginBottom: "1rem",
+ }}
+ >
+ <Table
+ horizontalSpacing="md"
+ verticalSpacing="sm"
+ withRowBorders
+ highlightOnHover
+ style={{
+ "--table-border-color": "var(--mantine-color-gray-3)",
+ }}
+ >
+ <EventsTableHeader
+ showAuthor={rows.showAuthor}
+ showFileHash={rows.showFileHash}
+ getSortIcon={getSortIcon}
+ onSort={onSort}
+ />
+ <Table.Tbody>
+ <EventRows {...rows} />
+ </Table.Tbody>
+ </Table>
+ <EventsPagination
+ page={page}
+ total={totalPages}
+ onChange={onPageChange}
+ />
+ </div>
+ );
+}
+
+function DetailField({
+ label,
+ children,
+}: {
+ label: string;
+ children: ReactNode;
+}) {
+ return (
+ <div>
+ <Text size="sm" fw={600} c="dimmed">
+ {label}
+ </Text>
+ {children}
+ </div>
+ );
+}
+
+function EventDetails({ event }: { event: AuditEvent | null }) {
+ const { t } = useTranslation();
+ if (!event) return null;
+ return (
+ <Stack gap="md">
+ <DetailField label={t("audit.events.timestamp", "Timestamp")}>
+ <Text size="sm">{formatDate(event.timestamp)}</Text>
+ </DetailField>
+ <DetailField label={t("audit.events.type", "Type")}>
+ <Text size="sm">{event.eventType}</Text>
+ </DetailField>
+ <DetailField label={t("audit.events.user", "User")}>
+ <Text size="sm">{event.username}</Text>
+ </DetailField>
+ <DetailField label={t("audit.events.ipAddress", "IP Address")}>
+ <Text size="sm">{event.ipAddress}</Text>
+ </DetailField>
+ <DetailField label={t("audit.events.details", "Details")}>
+ <Code block mah={300} style={{ overflow: "auto" }}>
+ {JSON.stringify(event.details, null, 2)}
+ </Code>
+ </DetailField>
+ </Stack>
+ );
+}
+
const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
loginEnabled = true,
captureFileHash = false,
@@ -40,13 +444,10 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [selectedEvent, setSelectedEvent] = useState<AuditEvent | null>(null);
- const [sortKey, setSortKey] = useState<
- "timestamp" | "eventType" | "username" | "ipAddress" | null
- >("timestamp");
+ const [sortKey, setSortKey] = useState<SortKey | null>("timestamp");
const [sortDir, setSortDir] = useState<"asc" | "desc">("desc");
const showAuthor = capturePdfAuthor;
const showFileHash = captureFileHash;
- const totalColumns = 5 + (showAuthor ? 1 : 0) + (showFileHash ? 1 : 0);
// Use shared filters hook
const { filters, eventTypes, users, handleFilterChange, handleClearFilters } =
@@ -142,14 +543,8 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
setCurrentPage(1);
};
- const formatDate = (dateString: string) => {
- return new Date(dateString).toLocaleString();
- };
-
// Sort handling
- const toggleSort = (
- key: "timestamp" | "eventType" | "username" | "ipAddress",
- ) => {
+ const toggleSort = (key: SortKey) => {
if (sortKey === key) {
setSortDir(sortDir === "asc" ? "desc" : "asc");
} else {
@@ -158,30 +553,11 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
}
};
- const getSortIcon = (
- key: "timestamp" | "eventType" | "username" | "ipAddress",
- ) => {
+ const getSortIcon = (key: SortKey): IconName => {
if (sortKey !== key) return "chevrons-up-down";
return sortDir === "asc" ? "chevron-up" : "chevron-down";
};
- // Event type colors
- const EVENT_TYPE_COLORS: Record<string, string> = {
- USER_LOGIN: "green",
- USER_LOGOUT: "gray",
- USER_FAILED_LOGIN: "red",
- USER_PROFILE_UPDATE: "blue",
- SETTINGS_CHANGED: "orange",
- FILE_OPERATION: "cyan",
- PDF_PROCESS: "violet",
- UI_DATA: "gray",
- HTTP_REQUEST: "indigo",
- };
-
- const getEventTypeColor = (type: string): string => {
- return EVENT_TYPE_COLORS[type] || "blue";
- };
-
// Apply sorting to current events
const sortedEvents = [...events].sort((a, b) => {
let aVal: string | number | undefined;
@@ -220,7 +596,6 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
{t("audit.events.title", "Audit Events")}
</Text>
- {/* Filters */}
<AuditFiltersForm
filters={filters}
eventTypes={eventTypes}
@@ -230,278 +605,22 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
disabled={!loginEnabled}
/>
- {/* Table */}
- {loading ? (
- <div style={{ display: "flex", justifyContent: "center" }}>
- <Loader size="lg" my="xl" />
- </div>
- ) : error ? (
- <Alert
- color="red"
- title={t("audit.events.error", "Error loading events")}
- >
- {error}
- </Alert>
- ) : (
- <>
- <div
- style={{
- overflowX: "auto",
- overflowY: "hidden",
- marginBottom: "1rem",
- }}
- >
- <Table
- horizontalSpacing="md"
- verticalSpacing="sm"
- withRowBorders
- highlightOnHover
- style={{
- "--table-border-color": "var(--mantine-color-gray-3)",
- }}
- >
- <Table.Thead>
- <Table.Tr
- style={{ backgroundColor: "var(--mantine-color-gray-0)" }}
- >
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- padding: "0.5rem",
- }}
- fz="sm"
- >
- <Button
- type="button"
- variant="tertiary"
- hover={false}
- onClick={() => toggleSort("timestamp")}
- style={{
- display: "flex",
- alignItems: "center",
- gap: "0.5rem",
- cursor: "pointer",
- userSelect: "none",
- }}
- >
- {t("audit.events.timestamp", "Timestamp")}
- <Icon name={getSortIcon("timestamp")} size="0.9rem" />
- </Button>
- </Table.Th>
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- padding: "0.5rem",
- }}
- fz="sm"
- >
- <Button
- type="button"
- variant="tertiary"
- hover={false}
- onClick={() => toggleSort("eventType")}
- style={{
- display: "flex",
- alignItems: "center",
- gap: "0.5rem",
- cursor: "pointer",
- userSelect: "none",
- }}
- >
- {t("audit.events.type", "Type")}
- <Icon name={getSortIcon("eventType")} size="0.9rem" />
- </Button>
- </Table.Th>
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- padding: "0.5rem",
- }}
- fz="sm"
- >
- <Button
- type="button"
- variant="tertiary"
- hover={false}
- onClick={() => toggleSort("username")}
- style={{
- display: "flex",
- alignItems: "center",
- gap: "0.5rem",
- cursor: "pointer",
- userSelect: "none",
- }}
- >
- {t("audit.events.user", "User")}
- <Icon name={getSortIcon("username")} size="0.9rem" />
- </Button>
- </Table.Th>
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- }}
- fz="sm"
- >
- {t("audit.events.documentName", "Document Name")}
- </Table.Th>
- {showAuthor && (
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- }}
- fz="sm"
- >
- {t("audit.events.author", "Author")}
- </Table.Th>
- )}
- {showFileHash && (
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- }}
- fz="sm"
- >
- {t("audit.events.fileHash", "File Hash")}
- </Table.Th>
- )}
- <Table.Th
- style={{
- fontWeight: 600,
- color: "var(--mantine-color-gray-7)",
- }}
- fz="sm"
- ta="center"
- >
- {t("audit.events.actions", "Actions")}
- </Table.Th>
- </Table.Tr>
- </Table.Thead>
- <Table.Tbody>
- {sortedEvents.length === 0 ? (
- <Table.Tr>
- <Table.Td colSpan={totalColumns}>
- <Group justify="center" py="xl">
- <Stack align="center" gap={0}>
- <Icon
- name="search"
- size="2rem"
- style={{ opacity: 0.4 }}
- />
- <Text ta="center" c="dimmed" size="sm">
- {t("audit.events.noEvents", "No events found")}
- </Text>
- </Stack>
- </Group>
- </Table.Td>
- </Table.Tr>
- ) : (
- sortedEvents.map((event) => {
- // Extract document name, author, hash from details.files if available
- let documentName = "";
- let author = "";
- let fileHash = "";
- if (event.details && typeof event.details === "object") {
- const details = event.details;
- const files = details.files;
- if (Array.isArray(files) && files.length > 0) {
- const firstFile = files[0] as Record<string, unknown>;
- documentName =
- typeof firstFile.name === "string"
- ? firstFile.name
- : "";
- if (showAuthor || showFileHash) {
- author =
- typeof firstFile.pdfAuthor === "string"
- ? firstFile.pdfAuthor
- : "";
- fileHash =
- typeof firstFile.fileHash === "string"
- ? firstFile.fileHash.substring(0, 16) + "..."
- : "";
- }
- }
- }
-
- return (
- <Table.Tr key={event.id}>
- <Table.Td>
- <Text size="sm">{formatDate(event.timestamp)}</Text>
- </Table.Td>
- <Table.Td>
- <Badge
- variant="light"
- size="sm"
- color={getEventTypeColor(event.eventType)}
- >
- {event.eventType}
- </Badge>
- </Table.Td>
- <Table.Td>
- <Text size="sm">{event.username}</Text>
- </Table.Td>
- <Table.Td>
- <Text size="sm" title={documentName}>
- {documentName || "—"}
- </Text>
- </Table.Td>
- {showAuthor && (
- <Table.Td>
- <Text size="sm">{author}</Text>
- </Table.Td>
- )}
- {showFileHash && (
- <Table.Td>
- <Text
- size="sm"
- title={fileHash}
- style={{
- fontFamily: "monospace",
- fontSize: "0.75rem",
- }}
- >
- {fileHash}
- </Text>
- </Table.Td>
- )}
- <Table.Td ta="center">
- <Button
- variant="tertiary"
- size="sm"
- onClick={() => setSelectedEvent(event)}
- disabled={!loginEnabled}
- >
- {t("audit.events.viewDetails", "View Details")}
- </Button>
- </Table.Td>
- </Table.Tr>
- );
- })
- )}
- </Table.Tbody>
- </Table>
-
- {/* Pagination */}
- {totalPages > 1 && (
- <Group justify="center" mt="md">
- <Pagination
- value={currentPage}
- onChange={setCurrentPage}
- total={totalPages}
- />
- </Group>
- )}
- </div>
- </>
- )}
+ <AuditEventsResults
+ loading={loading}
+ error={error}
+ events={sortedEvents}
+ showAuthor={showAuthor}
+ showFileHash={showFileHash}
+ loginEnabled={loginEnabled}
+ getSortIcon={getSortIcon}
+ onSort={toggleSort}
+ onViewDetails={setSelectedEvent}
+ page={currentPage}
+ totalPages={totalPages}
+ onPageChange={setCurrentPage}
+ />
</Stack>
- {/* Event Details Modal */}
<Modal
opened={selectedEvent !== null}
onClose={() => setSelectedEvent(null)}
@@ -509,42 +628,7 @@ const AuditEventsTable: React.FC<AuditEventsTableProps> = ({
size="lg"
zIndex={Z_INDEX_OVER_CONFIG_MODAL}
>
- {selectedEvent && (
- <Stack gap="md">
- <div>
- <Text size="sm" fw={600} c="dimmed">
- {t("audit.events.timestamp", "Timestamp")}
- </Text>
- <Text size="sm">{formatDate(selectedEvent.timestamp)}</Text>
- </div>
- <div>
- <Text size="sm" fw={600} c="dimmed">
- {t("audit.events.type", "Type")}
- </Text>
- <Text size="sm">{selectedEvent.eventType}</Text>
- </div>
- <div>
- <Text size="sm" fw={600} c="dimmed">
- {t("audit.events.user", "User")}
- </Text>
- <Text size="sm">{selectedEvent.username}</Text>
- </div>
- <div>
- <Text size="sm" fw={600} c="dimmed">
- {t("audit.events.ipAddress", "IP Address")}
- </Text>
- <Text size="sm">{selectedEvent.ipAddress}</Text>
- </div>
- <div>
- <Text size="sm" fw={600} c="dimmed">
- {t("audit.events.details", "Details")}
- </Text>
- <Code block mah={300} style={{ overflow: "auto" }}>
- {JSON.stringify(selectedEvent.details, null, 2)}
- </Code>
- </div>
- </Stack>
- )}
+ <EventDetails event={selectedEvent} />
</Modal>
</Card>
);
diff --git a/frontend/editor/src/saas/components/shared/config/configSections/McpSection.tsx b/frontend/editor/src/saas/components/shared/config/configSections/McpSection.tsx
index b1e37b4284..da561b2efa 100644
--- a/frontend/editor/src/saas/components/shared/config/configSections/McpSection.tsx
+++ b/frontend/editor/src/saas/components/shared/config/configSections/McpSection.tsx
@@ -56,10 +56,212 @@ function CopyInline({ value, label }: { value: string; label: string }) {
);
}
+interface McpClient {
+ value: string;
+ label: string;
+ file: string;
+ config: string;
+}
+
+/** Per-client connection snippets pointing at this deployment's /mcp endpoint. */
+function buildMcpClients(mcpUrl: string): McpClient[] {
+ return [
+ {
+ value: "claude-desktop",
+ label: "Claude Desktop",
+ file: "claude_desktop_config.json",
+ // Claude Desktop loads only stdio servers from this file, so the remote
+ // HTTP endpoint is bridged through the `mcp-remote` npm package (run via
+ // npx - needs Node.js installed). First launch opens a browser to sign in.
+ config: JSON.stringify(
+ {
+ mcpServers: {
+ "stirling-pdf": {
+ command: "npx",
+ args: ["-y", "mcp-remote", mcpUrl],
+ },
+ },
+ },
+ null,
+ 2,
+ ),
+ },
+ {
+ value: "claude-code",
+ label: "Claude Code",
+ file: ".mcp.json",
+ config: JSON.stringify(
+ { mcpServers: { "stirling-pdf": { type: "http", url: mcpUrl } } },
+ null,
+ 2,
+ ),
+ },
+ {
+ value: "codex",
+ label: "Codex CLI",
+ file: "~/.codex/config.toml",
+ config: `[mcp_servers.stirling-pdf]\nurl = "${mcpUrl}"`,
+ },
+ {
+ value: "vscode",
+ label: "VS Code",
+ file: ".vscode/mcp.json",
+ config: JSON.stringify(
+ { servers: { "stirling-pdf": { type: "http", url: mcpUrl } } },
+ null,
+ 2,
+ ),
+ },
+ ];
+}
+
+function McpGuestNotice({ onGoToAccount }: { onGoToAccount: () => void }) {
+ const { t } = useTranslation();
+ return (
+ <Paper withBorder p="md" radius="md">
+ <Stack gap={10}>
+ <Group
+ justify="space-between"
+ wrap="nowrap"
+ align="center"
+ style={{ gap: "1rem" }}
+ >
+ <Text size="sm" c="dimmed" style={{ flex: 1 }}>
+ {t(
+ "config.mcp.guestInfo",
+ "Guest users can't connect MCP clients. Create an account to use the MCP server and let your AI assistant run Stirling PDF tools on your behalf.",
+ )}
+ </Text>
+ <Button
+ size="sm"
+ variant="primary"
+ onClick={onGoToAccount}
+ style={{ flexShrink: 0 }}
+ >
+ {t("config.apiKeys.goToAccount", "Go to Account")}
+ </Button>
+ </Group>
+ </Stack>
+ </Paper>
+ );
+}
+
+function McpEndpointCard({ url }: { url: string }) {
+ const { t } = useTranslation();
+ return (
+ <Paper withBorder p="sm" radius="md">
+ <Group gap="xs" wrap="nowrap" align="center">
+ <Stack gap={2} style={{ flex: 1, minWidth: 0 }}>
+ <Text fw={500} size="sm">
+ {t("config.mcp.endpoint.label", "Your MCP endpoint")}
+ </Text>
+ <Code style={{ overflowX: "auto" }}>{url}</Code>
+ </Stack>
+ <CopyInline
+ value={url}
+ label={t("config.mcp.copy.endpointLabel", "Endpoint URL")}
+ />
+ </Group>
+ </Paper>
+ );
+}
+
+function McpClientPanel({ client }: { client: McpClient }) {
+ const { t } = useTranslation();
+ return (
+ <Tabs.Panel value={client.value} pt="sm">
+ <Stack gap="xs">
+ <Group justify="space-between" align="center" wrap="nowrap">
+ <Text size="xs" c="dimmed">
+ {t("config.mcp.setup.addTo", "Add to")} <Code>{client.file}</Code>
+ </Text>
+ <CopyInline
+ value={client.config}
+ label={t("config.mcp.copy.configLabel", "Config")}
+ />
+ </Group>
+ <Code block>{client.config}</Code>
+ </Stack>
+ </Tabs.Panel>
+ );
+}
+
+function McpClientTabs({ clients }: { clients: McpClient[] }) {
+ return (
+ <Tabs defaultValue="claude-desktop" variant="pills" radius="md" mt={4}>
+ <Tabs.List>
+ {clients.map((c) => (
+ <Tabs.Tab key={c.value} value={c.value}>
+ {c.label}
+ </Tabs.Tab>
+ ))}
+ </Tabs.List>
+ {clients.map((c) => (
+ <McpClientPanel key={c.value} client={c} />
+ ))}
+ </Tabs>
+ );
+}
+
+function McpClientSetupCard({ mcpUrl }: { mcpUrl: string }) {
+ const { t } = useTranslation();
+ const clients = useMemo(() => buildMcpClients(mcpUrl), [mcpUrl]);
+ return (
+ <Paper withBorder p="sm" radius="md">
+ <Stack gap="xs">
+ <Text fw={500} size="sm">
+ {t("config.mcp.setup.title", "Connect your AI assistant")}
+ </Text>
+ <Text size="xs" c="dimmed">
+ {t(
+ "config.mcp.setup.hint",
+ "Pick your client, paste the snippet into the file shown, then restart it. You'll sign in with your Stirling account on first use - no keys to copy.",
+ )}
+ </Text>
+ <McpClientTabs clients={clients} />
+ </Stack>
+ </Paper>
+ );
+}
+
+function McpUsageTip() {
+ const { t } = useTranslation();
+ return (
+ <Alert variant="light" color="blue" icon={<Icon name="info" size="1rem" />}>
+ <Group justify="space-between" align="center" wrap="nowrap" gap="sm">
+ <Text size="sm">
+ {t(
+ "config.mcp.tip",
+ "Every action your assistant runs is performed as your account and counts towards your usage, just like using the Stirling PDF API and Automation.",
+ )}
+ </Text>
+ <Button
+ size="sm"
+ variant="secondary"
+ style={{ flexShrink: 0 }}
+ leftSection={<Icon name="key" size={14} />}
+ onClick={() => openAppSettings("api-keys")}
+ >
+ {t("config.mcp.viewApiKeys", "View API keys")}
+ </Button>
+ </Group>
+ </Alert>
+ );
+}
+
+function McpConnectionGuide({ mcpUrl }: { mcpUrl: string }) {
+ return (
+ <>
+ <McpEndpointCard url={mcpUrl} />
+ <McpClientSetupCard mcpUrl={mcpUrl} />
+ <McpUsageTip />
+ </>
+ );
+}
+
// SaaS MCP guide: always shown, explains how to point an AI assistant at the
// OAuth-protected /mcp endpoint with per-client config.
export default function McpSection() {
- const { t } = useTranslation();
const { config } = useAppConfig();
const { user } = useAuth();
// Guests can't authorise an MCP client - the OAuth flow mints an anonymous
@@ -81,188 +283,13 @@ export default function McpSection() {
return trimTrailingSlash(raw);
}, [config?.baseUrl]);
- const mcpUrl = `${baseUrl}/mcp`;
-
- // Per-client connection snippets pointing at this deployment's /mcp endpoint.
- const clients = useMemo(
- () => [
- {
- value: "claude-desktop",
- label: "Claude Desktop",
- file: "claude_desktop_config.json",
- // Claude Desktop loads only stdio servers from this file, so the remote
- // HTTP endpoint is bridged through the `mcp-remote` npm package (run via
- // npx - needs Node.js installed). First launch opens a browser to sign in.
- config: JSON.stringify(
- {
- mcpServers: {
- "stirling-pdf": {
- command: "npx",
- args: ["-y", "mcp-remote", mcpUrl],
- },
- },
- },
- null,
- 2,
- ),
- },
- {
- value: "claude-code",
- label: "Claude Code",
- file: ".mcp.json",
- config: JSON.stringify(
- { mcpServers: { "stirling-pdf": { type: "http", url: mcpUrl } } },
- null,
- 2,
- ),
- },
- {
- value: "codex",
- label: "Codex CLI",
- file: "~/.codex/config.toml",
- config: `[mcp_servers.stirling-pdf]\nurl = "${mcpUrl}"`,
- },
- {
- value: "vscode",
- label: "VS Code",
- file: ".vscode/mcp.json",
- config: JSON.stringify(
- { servers: { "stirling-pdf": { type: "http", url: mcpUrl } } },
- null,
- 2,
- ),
- },
- ],
- [mcpUrl],
- );
-
return (
<div className="settings-section-container">
<Stack gap="md" className="settings-section-content">
{isAnonymous ? (
- <Paper withBorder p="md" radius="md">
- <Stack gap={10}>
- <Group
- justify="space-between"
- wrap="nowrap"
- align="center"
- style={{ gap: "1rem" }}
- >
- <Text size="sm" c="dimmed" style={{ flex: 1 }}>
- {t(
- "config.mcp.guestInfo",
- "Guest users can't connect MCP clients. Create an account to use the MCP server and let your AI assistant run Stirling PDF tools on your behalf.",
- )}
- </Text>
- <Button
- size="sm"
- variant="primary"
- onClick={goToAccount}
- style={{ flexShrink: 0 }}
- >
- {t("config.apiKeys.goToAccount", "Go to Account")}
- </Button>
- </Group>
- </Stack>
- </Paper>
+ <McpGuestNotice onGoToAccount={goToAccount} />
) : (
- <>
- {/* Endpoint */}
- <Paper withBorder p="sm" radius="md">
- <Group gap="xs" wrap="nowrap" align="center">
- <Stack gap={2} style={{ flex: 1, minWidth: 0 }}>
- <Text fw={500} size="sm">
- {t("config.mcp.endpoint.label", "Your MCP endpoint")}
- </Text>
- <Code style={{ overflowX: "auto" }}>{mcpUrl}</Code>
- </Stack>
- <CopyInline
- value={mcpUrl}
- label={t("config.mcp.copy.endpointLabel", "Endpoint URL")}
- />
- </Group>
- </Paper>
-
- {/* Per-client setup */}
- <Paper withBorder p="sm" radius="md">
- <Stack gap="xs">
- <Text fw={500} size="sm">
- {t("config.mcp.setup.title", "Connect your AI assistant")}
- </Text>
- <Text size="xs" c="dimmed">
- {t(
- "config.mcp.setup.hint",
- "Pick your client, paste the snippet into the file shown, then restart it. You'll sign in with your Stirling account on first use - no keys to copy.",
- )}
- </Text>
- <Tabs
- defaultValue="claude-desktop"
- variant="pills"
- radius="md"
- mt={4}
- >
- <Tabs.List>
- {clients.map((c) => (
- <Tabs.Tab key={c.value} value={c.value}>
- {c.label}
- </Tabs.Tab>
- ))}
- </Tabs.List>
- {clients.map((c) => (
- <Tabs.Panel key={c.value} value={c.value} pt="sm">
- <Stack gap="xs">
- <Group
- justify="space-between"
- align="center"
- wrap="nowrap"
- >
- <Text size="xs" c="dimmed">
- {t("config.mcp.setup.addTo", "Add to")}{" "}
- <Code>{c.file}</Code>
- </Text>
- <CopyInline
- value={c.config}
- label={t("config.mcp.copy.configLabel", "Config")}
- />
- </Group>
- <Code block>{c.config}</Code>
- </Stack>
- </Tabs.Panel>
- ))}
- </Tabs>
- </Stack>
- </Paper>
-
- {/* Tip / cross-link */}
- <Alert
- variant="light"
- color="blue"
- icon={<Icon name="info" size="1rem" />}
- >
- <Group
- justify="space-between"
- align="center"
- wrap="nowrap"
- gap="sm"
- >
- <Text size="sm">
- {t(
- "config.mcp.tip",
- "Every action your assistant runs is performed as your account and counts towards your usage, just like using the Stirling PDF API and Automation.",
- )}
- </Text>
- <Button
- size="sm"
- variant="secondary"
- style={{ flexShrink: 0 }}
- leftSection={<Icon name="key" size={14} />}
- onClick={() => openAppSettings("api-keys")}
- >
- {t("config.mcp.viewApiKeys", "View API keys")}
- </Button>
- </Group>
- </Alert>
- </>
+ <McpConnectionGuide mcpUrl={`${baseUrl}/mcp`} />
)}
</Stack>
</div>
diff --git a/frontend/oxlint.config.ts b/frontend/oxlint.config.ts
index abe882f2b1..fc20e9b31a 100644
--- a/frontend/oxlint.config.ts
+++ b/frontend/oxlint.config.ts
@@ -199,7 +199,7 @@ export default defineConfig({
"typescript/prefer-as-const": "error",
"typescript/prefer-namespace-keyword": "error",
"typescript/triple-slash-reference": "error",
- "react/jsx-max-depth": ["error", { max: 10 }],
+ "react/jsx-max-depth": ["error", { max: 9 }],
},
overrides: [
{
@@ -387,7 +387,10 @@ export default defineConfig({
{
// A provider stack nests one context per level in dependency order, so its
// depth counts providers rather than measuring how hard the tree is to read.
- files: ["editor/src/core/components/AppProviders.tsx"],
+ files: [
+ "editor/src/core/components/AppProviders.tsx",
+ ".storybook/preview.tsx",
+ ],
rules: {
"react/jsx-max-depth": "off",
},