Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(teams): accept and reject team invitations in settings (#2840)

dev-rbb5fe9b744b16
diff --git a/js/app/packages/app/component/settings/Settings.tsx b/js/app/packages/app/component/settings/Settings.tsx
index aefc1194c4..e46d91792c 100644
--- a/js/app/packages/app/component/settings/Settings.tsx
+++ b/js/app/packages/app/component/settings/Settings.tsx
@@ -12,7 +12,6 @@ import { Tabs } from '@core/component/Tabs';
import { Account } from './Account';
import { Shortcuts } from './Shortcuts';
import { Team } from './Team';
-import { useUserTeamsQuery } from '@queries/team/teams';
import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';
import type { ValidHotkey } from '@core/hotkey/types';
import { SplitHeaderLeft, SplitHeaderRight } from '../split-layout/components/SplitHeader';
@@ -39,8 +38,6 @@ type SettingsPanelProps = {
export function SettingsPanel(props: SettingsPanelProps) {
const { settingsOpen, closeSettings, activeTabId, setActiveTabId } = useSettingsState();
const permissions = usePermissions();
- const userTeamsQuery = useUserTeamsQuery();
- const hasTeam = () => (userTeamsQuery.data?.length ?? 0) > 0;
const teamsFlag = useFeatureFlag('enable-teams-settings', { enabledOverride: ENABLE_TEAMS_OVERRIDE });
// Set up hotkey scope for settings panel
@@ -65,7 +62,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
];
tabs.push({ value: 'Shortcuts', label: 'Shortcuts' });
- if (teamsFlag().enabled && hasTeam()) { tabs.push({ value: 'Team', label: 'Team' }) }
+ if (teamsFlag().enabled) { tabs.push({ value: 'Team', label: 'Team' }) }
if (permissions()?.includes('write:stripe_subscription') && !isNativeMobilePlatform()) { tabs.push({ value: 'Subscription', label: 'Subscription' }) }
if (ENABLE_APP_STORE_QR_CODE && !isNativeMobilePlatform()) { tabs.push({ value: 'Mobile App', label: 'App' }) }
if (isNativeMobilePlatform() && DEV_MODE_ENV) { tabs.push({ value: 'Mobile', label: 'Mobile Dev Tools' }) }
@@ -215,7 +212,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
<Show when={activeTabId() === 'Shortcuts'}>
<Shortcuts />
</Show>
- <Show when={activeTabId() === 'Team' && teamsFlag().enabled && hasTeam()}>
+ <Show when={activeTabId() === 'Team' && teamsFlag().enabled}>
<Suspense>
<Team />
</Suspense>
diff --git a/js/app/packages/app/component/settings/Team.tsx b/js/app/packages/app/component/settings/Team.tsx
index 36027d550e..9d92b3f17d 100644
--- a/js/app/packages/app/component/settings/Team.tsx
+++ b/js/app/packages/app/component/settings/Team.tsx
@@ -14,7 +14,7 @@ import { Dialog } from '@kobalte/core/dialog';
import { Select } from '@kobalte/core/select';
import { useUserId } from '@core/context/user';
import { useDisplayName, tryMacroId } from '@core/user';
-import { createMemo, createSignal, For, Show } from 'solid-js';
+import { createMemo, createSignal, For, Match, Show, Suspense, Switch } from 'solid-js';
import type { CollectionNode } from '@kobalte/core';
import {
useUserTeamsQuery,
@@ -27,6 +27,11 @@ import {
useDeleteTeamInviteMutation,
useInviteToTeamMutation,
} from '@queries/team/invites';
+import {
+ useUserInvitesQuery,
+ useJoinTeamMutation,
+ useRejectInvitationMutation,
+} from '@queries/team/invitations';
import { useRemoveUserFromTeamMutation, usePatchTeamUserTierMutation } from '@queries/team/members';
import { TeamRole } from '@service-auth/generated/schemas/teamRole';
import { TeamUserTier } from '@service-auth/generated/schemas/teamUserTier';
@@ -162,8 +167,8 @@ function InviteRow(props: {
return (
<div class="flex items-center justify-between py-2 border-b border-edge-muted last:border-b-0">
<div class="flex items-center gap-3 min-w-0 flex-1">
- <div class="w-8 h-8 rounded-full border border-edge-muted flex items-center justify-center shrink-0">
- <EnvelopeIcon class="size-4 text-ink-muted" />
+ <div class="w-8 h-8 rounded-full bg-accent/10 flex items-center justify-center shrink-0">
+ <EnvelopeIcon class="size-4 text-accent" />
</div>
<div class="min-w-0 flex-1">
<div class="text-sm text-ink truncate">{props.invite.email}</div>
@@ -183,20 +188,115 @@ function InviteRow(props: {
);
}
-export function Team() {
- const userId = useUserId();
- const userTeamsQuery = useUserTeamsQuery();
+function InviterName(props: { inviterId: string }) {
+ const [displayName] = useDisplayName(tryMacroId(props.inviterId));
+ return <span class="font-medium">{displayName()}</span>;
+}
- const team = createMemo(() => {
- const teams = userTeamsQuery.data;
- if (!teams || teams.length === 0) return null;
- return teams[0];
- });
+function UserInviteRow(props: {
+ invite: TeamInviteDetails;
+ onAccept: () => void;
+ onDecline: () => void;
+ isAccepting: boolean;
+ isDeclining: boolean;
+}) {
+ return (
+ <div class="flex items-center justify-between py-3 border-b border-edge-muted last:border-b-0 gap-3">
+ <div class="flex items-center gap-3 min-w-0 flex-1">
+ <div class="w-8 h-8 rounded-full bg-accent/10 flex items-center justify-center shrink-0">
+ <EnvelopeIcon class="size-4 text-accent" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <div class="text-sm text-ink">
+ <InviterName inviterId={props.invite.invited_by} /> invited you to join a team
+ </div>
+ <div class="text-xs text-ink-muted">
+ as {props.invite.team_role}
+ </div>
+ </div>
+ </div>
+ <div class="flex items-center gap-2 shrink-0">
+ <Button
+ variant="tertiary"
+ class="px-2 py-1 rounded-xs"
+ disabled={props.isAccepting || props.isDeclining}
+ onClick={props.onDecline}
+ >
+ <Show when={props.isDeclining} fallback="Decline">
+ <SpinnerIcon class="size-4 animate-spin" />
+ </Show>
+ </Button>
+ <Button
+ variant="accent"
+ class="px-2 py-1 rounded-xs"
+ disabled={props.isAccepting || props.isDeclining}
+ onClick={props.onAccept}
+ >
+ <Show when={props.isAccepting} fallback="Join">
+ <SpinnerIcon class="size-4 animate-spin" />
+ </Show>
+ </Button>
+ </div>
+ </div>
+ );
+}
+
+function TeamInvites() {
+ const userInvitesQuery = useUserInvitesQuery();
+ const joinTeamMutation = useJoinTeamMutation();
+ const rejectMutation = useRejectInvitationMutation();
- const teamId = createMemo(() => team()?.id ?? '');
+ const invites = () => userInvitesQuery.data?.invites ?? [];
- const teamQuery = useTeamQuery(teamId);
- const invitesQuery = useTeamInvitesQuery(teamId);
+ const isAccepting = (inviteId: string) =>
+ joinTeamMutation.isPending && joinTeamMutation.variables?.teamInviteId === inviteId;
+ const isDeclining = (inviteId: string) =>
+ rejectMutation.isPending && rejectMutation.variables?.teamInviteId === inviteId;
+
+ return (
+ <Show when={invites().length > 0}>
+ <section class="mb-6">
+ <header class="mb-2">
+ <h3 class="text-sm font-medium">Pending Invitations</h3>
+ <p class="text-xs text-ink-muted">You've been invited to join a team.</p>
+ </header>
+ <div class="border border-edge rounded-sm px-3">
+ <For each={invites()}>
+ {(invite) => (
+ <UserInviteRow
+ invite={invite}
+ onAccept={() => joinTeamMutation.mutate({ teamInviteId: invite.id })}
+ onDecline={() => rejectMutation.mutate({ teamInviteId: invite.id })}
+ isAccepting={isAccepting(invite.id)}
+ isDeclining={isDeclining(invite.id)}
+ />
+ )}
+ </For>
+ </div>
+ </section>
+ </Show>
+ );
+}
+
+function EmptyTeamState() {
+ return (
+ <div class="flex flex-col items-center justify-center py-12 text-center">
+ <div class="w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center mb-4">
+ <PlusIcon class="size-6 text-accent" />
+ </div>
+ <h3 class="text-sm font-medium text-ink mb-1">No team yet</h3>
+ <p class="text-xs text-ink-muted max-w-xs">
+ You're not part of a team. When someone invites you to join their team, you'll see the invitation here.
+ </p>
+ </div>
+ );
+}
+
+function TeamManagement(props: { teamId: string; teamName: string; ownerId: string }) {
+ const userId = useUserId();
+
+ const teamQuery = useTeamQuery(() => props.teamId);
+ const invitesQuery = useTeamInvitesQuery(() => props.teamId);
const deleteInviteMutation = useDeleteTeamInviteMutation();
const removeUserMutation = useRemoveUserFromTeamMutation();
@@ -217,14 +317,13 @@ export function Team() {
const parsedEmails = () => parseEmails(inviteEmails());
const hasValidEmails = () => parsedEmails().length > 0;
- const deleteConfirmationPhrase = () => `Delete ${team()?.name ?? ''}`;
+ const deleteConfirmationPhrase = () => `Delete ${props.teamName}`;
const canDeleteTeam = () => deleteConfirmation() === deleteConfirmationPhrase();
- const originalTeamName = () => team()?.name ?? '';
- const teamNameValue = () => editingTeamName() ?? originalTeamName();
+ const teamNameValue = () => editingTeamName() ?? props.teamName;
const hasTeamNameChanged = () => {
const editing = editingTeamName();
- return editing !== undefined && editing.trim() !== originalTeamName();
+ return editing !== undefined && editing.trim() !== props.teamName;
};
const members = createMemo(() => {
@@ -239,18 +338,16 @@ export function Team() {
const isOwner = createMemo(() => {
const currentUserId = userId();
- const teamData = team();
- if (!currentUserId || !teamData) return false;
- return teamData.owner_id === currentUserId;
+ if (!currentUserId) return false;
+ return props.ownerId === currentUserId;
});
const handleSaveTeamName = () => {
const newName = editingTeamName()?.trim();
- const currentTeamId = teamId();
- if (!currentTeamId || !newName) return;
+ if (!props.teamId || !newName) return;
patchTeamMutation.mutate(
- { teamId: currentTeamId, request: { name: newName } },
+ { teamId: props.teamId, request: { name: newName } },
{ onSuccess: () => setEditingTeamName(undefined) }
);
};
@@ -261,21 +358,19 @@ export function Team() {
const handleLeaveTeam = () => {
const currentUserId = userId();
- const currentTeamId = teamId();
- if (!currentUserId || !currentTeamId) return;
+ if (!currentUserId || !props.teamId) return;
removeUserMutation.mutate(
- { teamId: currentTeamId, userId: currentUserId },
+ { teamId: props.teamId, userId: currentUserId },
{ onSuccess: () => setShowLeaveModal(false) }
);
};
const handleDeleteTeam = () => {
- const currentTeamId = teamId();
- if (!currentTeamId) return;
+ if (!props.teamId) return;
deleteTeamMutation.mutate(
- { teamId: currentTeamId },
+ { teamId: props.teamId },
{
onSuccess: () => {
setDeleteConfirmation('');
@@ -294,33 +389,30 @@ export function Team() {
const handleRemoveMember = () => {
const member = showRemoveModal();
- const currentTeamId = teamId();
- if (!currentTeamId || !member) return;
+ if (!props.teamId || !member) return;
removeUserMutation.mutate(
- { teamId: currentTeamId, userId: member.user_id },
+ { teamId: props.teamId, userId: member.user_id },
{ onSuccess: () => setShowRemoveModal(null) }
);
};
const handleCancelInvite = () => {
const invite = showCancelInviteModal();
- const currentTeamId = teamId();
- if (!currentTeamId || !invite) return;
+ if (!props.teamId || !invite) return;
deleteInviteMutation.mutate(
- { teamId: currentTeamId, teamInviteId: invite.id },
+ { teamId: props.teamId, teamInviteId: invite.id },
{ onSuccess: () => setShowCancelInviteModal(null) }
);
};
const handleInvite = () => {
const emails = parsedEmails();
- const currentTeamId = teamId();
- if (emails.length === 0 || !currentTeamId) return;
+ if (emails.length === 0 || !props.teamId) return;
inviteToTeamMutation.mutate(
- { teamId: currentTeamId, request: { emails } },
+ { teamId: props.teamId, request: { emails } },
{
onSuccess: () => {
setInviteEmails('');
@@ -338,160 +430,141 @@ export function Team() {
};
return (
- <div class="max-w-2xl mx-auto">
- <div class="p-6">
- <Show
- when={!userTeamsQuery.isLoading && team()}
- fallback={
- <Show
- when={userTeamsQuery.isLoading}
- fallback={
- <div class="text-sm text-ink-muted">
- You are not part of a team.
- </div>
- }
- >
- <div class="animate-pulse bg-ink-extra-muted rounded h-4 w-32" />
- </Show>
- }
- >
- <header class="mb-6">
- <h2 class="text-xl font-semibold text-ink">{originalTeamName()}</h2>
- </header>
-
- <section class="mb-6">
- <header class="flex items-center justify-between mb-2">
- <div>
- <h3 class="text-sm font-medium">Details</h3>
- <p class="text-xs text-ink-muted">Team information and settings.</p>
- </div>
- <Show
- when={isOwner()}
- fallback={
- <Show when={currentMember()}>
- <Button variant="destructive" size="sm" class="rounded-xs" onClick={() => setShowLeaveModal(true)}>
- <LeaveIcon class="size-4" />
- Leave
- </Button>
- </Show>
- }
- >
- <Button variant="destructive" size="sm" class="rounded-xs" onClick={() => setShowDeleteTeamModal(true)}>
- <TrashIcon class="size-4" />
- Delete Team
- </Button>
- </Show>
- </header>
- <div class="border border-edge rounded-sm px-3">
- <div class="flex items-center justify-between py-2">
- <span class="text-sm font-medium text-ink-muted">Name</span>
- <Show
- when={isOwner()}
- fallback={<span class="text-sm text-ink">{originalTeamName()}</span>}
- >
- <div class="flex items-center gap-2">
- <input
- type="text"
- value={teamNameValue()}
- onInput={(e) => setEditingTeamName(e.currentTarget.value)}
- placeholder="Enter team name"
- class="text-sm bg-transparent border border-edge-muted rounded-xs px-2 py-1 hover:border-edge focus:border-accent outline-none text-ink w-48"
- />
- <Show when={hasTeamNameChanged()}>
- <div class="flex items-center gap-1 shrink-0">
- <Tooltip tooltip="Save">
- <Button
- variant="accent"
- size="icon-sm"
- class="rounded-xs"
- disabled={patchTeamMutation.isPending || !editingTeamName()?.trim()}
- onClick={handleSaveTeamName}
- >
- <Show when={patchTeamMutation.isPending} fallback={<CheckIcon class="size-4" />}>
- <SpinnerIcon class="size-4 animate-spin" />
- </Show>
- </Button>
- </Tooltip>
- <Tooltip tooltip="Cancel">
- <Button
- variant="ghost"
- size="icon-sm"
- class="rounded-xs"
- disabled={patchTeamMutation.isPending}
- onClick={handleCancelTeamNameEdit}
- >
- <XIcon class="size-4" />
- </Button>
- </Tooltip>
- </div>
- </Show>
- </div>
- </Show>
- </div>
- </div>
- </section>
-
- <section class="mb-6">
- <header class="flex items-center justify-between mb-2">
- <div>
- <h3 class="text-sm font-medium">Members ({members().length})</h3>
- <p class="text-xs text-ink-muted">People who have access to this team.</p>
- </div>
- <Show when={isOwner()}>
- <Button variant="secondary" size="sm" class="rounded-xs" onClick={() => setShowInviteModal(true)}>
- <PlusIcon class="size-4" />
- Invite Member
+ <>
+ <header class="mb-6">
+ <h2 class="text-xl font-semibold text-ink">{props.teamName}</h2>
+ </header>
+
+ <section class="mb-6">
+ <header class="flex items-center justify-between mb-2">
+ <div>
+ <h3 class="text-sm font-medium">Details</h3>
+ <p class="text-xs text-ink-muted">Team information and settings.</p>
+ </div>
+ <Show
+ when={isOwner()}
+ fallback={
+ <Show when={currentMember()}>
+ <Button variant="destructive" size="sm" class="rounded-xs" onClick={() => setShowLeaveModal(true)}>
+ <LeaveIcon class="size-4" />
+ Leave
</Button>
</Show>
- </header>
+ }
+ >
+ <Button variant="destructive" size="sm" class="rounded-xs" onClick={() => setShowDeleteTeamModal(true)}>
+ <TrashIcon class="size-4" />
+ Delete Team
+ </Button>
+ </Show>
+ </header>
+ <div class="border border-edge rounded-sm px-3">
+ <div class="flex items-center justify-between py-2">
+ <span class="text-sm font-medium text-ink-muted">Name</span>
<Show
- when={!teamQuery.isLoading}
- fallback={<div class="animate-pulse bg-ink-extra-muted rounded h-16" />}
+ when={isOwner()}
+ fallback={<span class="text-sm text-ink">{props.teamName}</span>}
>
- <div class="border border-edge rounded-sm px-3">
- <For each={members()}>
- {(member) => (
- <MemberRow
- member={member}
- isOwner={isOwner()}
- isCurrentUser={member.user_id === userId()}
- onRemove={() => setShowRemoveModal(member)}
- onTierChange={(newTier) => {
- const currentTeamId = teamId();
- if (!currentTeamId) return;
- patchTierMutation.mutate({
- teamId: currentTeamId,
- request: {
- team_user_id: member.user_id,
- new_tier: newTier,
- },
- });
- }}
- />
- )}
- </For>
+ <div class="flex items-center gap-2">
+ <input
+ type="text"
+ value={teamNameValue()}
+ onInput={(e) => setEditingTeamName(e.currentTarget.value)}
+ placeholder="Enter team name"
+ class="text-sm bg-transparent border border-edge-muted rounded-xs px-2 py-1 hover:border-edge focus:border-accent outline-none text-ink w-48"
+ />
+ <Show when={hasTeamNameChanged()}>
+ <div class="flex items-center gap-1 shrink-0">
+ <Tooltip tooltip="Save">
+ <Button
+ variant="accent"
+ size="icon-sm"
+ class="rounded-xs"
+ disabled={patchTeamMutation.isPending || !editingTeamName()?.trim()}
+ onClick={handleSaveTeamName}
+ >
+ <Show when={patchTeamMutation.isPending} fallback={<CheckIcon class="size-4" />}>
+ <SpinnerIcon class="size-4 animate-spin" />
+ </Show>
+ </Button>
+ </Tooltip>
+ <Tooltip tooltip="Cancel">
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ class="rounded-xs"
+ disabled={patchTeamMutation.isPending}
+ onClick={handleCancelTeamNameEdit}
+ >
+ <XIcon class="size-4" />
+ </Button>
+ </Tooltip>
+ </div>
+ </Show>
</div>
</Show>
- </section>
-
- <Show when={isOwner() && (invitesQuery.data?.invites?.length ?? 0) > 0}>
- <section class="mb-6">
- <h3 class="text-sm font-medium mb-2">Pending Invites</h3>
- <div class="border border-edge rounded-md px-3">
- <For each={invitesQuery.data?.invites ?? []}>
- {(invite) => (
- <InviteRow
- invite={invite}
- isOwner={isOwner()}
- onCancel={() => setShowCancelInviteModal(invite)}
- />
- )}
- </For>
- </div>
- </section>
+ </div>
+ </div>
+ </section>
+
+ <section class="mb-6">
+ <header class="flex items-center justify-between mb-2">
+ <div>
+ <h3 class="text-sm font-medium">Members ({members().length})</h3>
+ <p class="text-xs text-ink-muted">People who have access to this team.</p>
+ </div>
+ <Show when={isOwner()}>
+ <Button variant="secondary" size="sm" class="rounded-xs" onClick={() => setShowInviteModal(true)}>
+ <PlusIcon class="size-4" />
+ Invite Member
+ </Button>
</Show>
+ </header>
+ <Show
+ when={!teamQuery.isLoading}
+ fallback={<div class="animate-pulse bg-ink-extra-muted rounded h-16" />}
+ >
+ <div class="border border-edge rounded-sm px-3">
+ <For each={members()}>
+ {(member) => (
+ <MemberRow
+ member={member}
+ isOwner={isOwner()}
+ isCurrentUser={member.user_id === userId()}
+ onRemove={() => setShowRemoveModal(member)}
+ onTierChange={(newTier) => {
+ if (!props.teamId) return;
+ patchTierMutation.mutate({
+ teamId: props.teamId,
+ request: {
+ team_user_id: member.user_id,
+ new_tier: newTier,
+ },
+ });
+ }}
+ />
+ )}
+ </For>
+ </div>
</Show>
- </div>
+ </section>
+
+ <Show when={isOwner() && (invitesQuery.data?.invites?.length ?? 0) > 0}>
+ <section class="mb-6">
+ <h3 class="text-sm font-medium mb-2">Pending Invites</h3>
+ <div class="border border-edge rounded-md px-3">
+ <For each={invitesQuery.data?.invites ?? []}>
+ {(invite) => (
+ <InviteRow
+ invite={invite}
+ isOwner={isOwner()}
+ onCancel={() => setShowCancelInviteModal(invite)}
+ />
+ )}
+ </For>
+ </div>
+ </section>
+ </Show>
<Dialog open={showLeaveModal()} onOpenChange={setShowLeaveModal}>
<Dialog.Portal>
@@ -506,7 +579,7 @@ export function Team() {
</Dialog.Title>
</div>
<div class="p-3 flex flex-col gap-3">
- <p>Are you sure you want to leave {team()?.name}? You will lose access to team resources.</p>
+ <p>Are you sure you want to leave {props.teamName}? You will lose access to team resources.</p>
<div class="flex justify-end gap-1 pt-2">
<Button
variant="ghost"
@@ -547,7 +620,7 @@ export function Team() {
</div>
<div class="p-3 flex flex-col gap-3">
<p>
- Are you sure you want to delete <span class="font-medium">{team()?.name}</span>?
+ Are you sure you want to delete <span class="font-medium">{props.teamName}</span>?
This action cannot be undone and all team members will lose access.
</p>
<p class="text-sm text-ink-muted">
@@ -731,6 +804,45 @@ export function Team() {
</DialogWrapper>
</Dialog.Portal>
</Dialog>
+ </>
+ );
+}
+
+function TeamContent() {
+ const userTeamsQuery = useUserTeamsQuery();
+ const userInvitesQuery = useUserInvitesQuery();
+
+ const team = createMemo(() => {
+ const teams = userTeamsQuery.data;
+ if (!teams || teams.length === 0) return null;
+ return teams[0];
+ });
+
+ const hasInvites = () => (userInvitesQuery.data?.invites?.length ?? 0) > 0;
+
+ return (
+ <Switch>
+ <Match when={team()} keyed>
+ {(t) => <TeamManagement teamId={t.id} teamName={t.name} ownerId={t.owner_id} />}
+ </Match>
+ <Match when={hasInvites()}>
+ <TeamInvites />
+ </Match>
+ <Match when={true}>
+ <EmptyTeamState />
+ </Match>
+ </Switch>
+ );
+}
+
+export function Team() {
+ return (
+ <div class="max-w-2xl mx-auto">
+ <div class="p-6">
+ <Suspense fallback={<div class="animate-pulse bg-ink-extra-muted rounded h-4 w-32" />}>
+ <TeamContent />
+ </Suspense>
+ </div>
</div>
);
}