mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
## Thinking Path > - Teams use Paperclip to manage agents and their work. > - Hosted teams can have a private Slack channel with the Paperclip team. > - A workspace member needs to know whether they can open the channel or still need the owner's invitation. > - Cloud supplies that information for the selected organization. > - This change puts a Slack button in the sidebar footer. It opens a dialog with the next action. ## Linked Issues or Issue Description **Subsystem affected** Workspace sidebar and the Cloud onboarding browser journey. **Problem or motivation** After setup, a user can lose track of the invitation to their organization's private feedback channel. **Proposed solution** Show the invitation status in a dialog. Offer a channel link when Cloud confirms the connection. **Roadmap alignment** This extends the existing hosted workspace navigation. The roadmap has no separate item for this shortcut. ## What Changed - Both sidebar variants use the existing portfolio request to show the Slack shortcut when Cloud supplies invitation details. - The icon uses grayscale at rest and brand colors on hover or keyboard focus. The button has an accessible name and a tooltip. - The Cloud onboarding journey selects Codex and confirms feedback intent when the first-account welcome appears. - Storybook covers pending and connected channels. ## Verification - The sidebar suite passed 36 tests. The Cloud onboarding journey suite passed 10 tests covering both the current and previous gateway layouts. - The Storybook catalog regenerated successfully. - In a local browser run, a fresh user completed signup, connected a test model, hired an agent, opened its chat, and opened and dismissed the Slack invitation. The test used a local Slack fixture. - The incremental verifier selected broad CI coverage for the runner journey change. All applicable checks passed on `ea9779abda`. A GitHub runner shut down during a server test shard. The shard and final verification gate passed on retry. [CI run](https://github.com/paperclipai/paperclip/actions/runs/45276376121/attempts/2) · [Greptile review (5/5)](https://github.com/paperclipai/paperclip/pull/22702#issuecomment-7115303606) ## Risks An older Cloud service can omit the optional feedback field. In that case, the sidebar keeps the existing layout. Cloud controls the channel destination and the invitation state. ## Model Used OpenAI GPT-6 in Codex, with repository tools and browser verification. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Scott Tong <1504818+scotttong@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
300 lines
12 KiB
TypeScript
300 lines
12 KiB
TypeScript
import { useState, type CSSProperties } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import {
|
|
BookOpen,
|
|
Flag,
|
|
LogOut,
|
|
Settings,
|
|
type LucideIcon,
|
|
UserPlus,
|
|
} from "lucide-react";
|
|
import { hidesCompanyPage, type DeploymentMode } from "@paperclipai/shared";
|
|
import { Link } from "@/lib/router";
|
|
import { authApi } from "@/api/auth";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
import { useCloudInstance } from "@/hooks/useCloudInstance";
|
|
import { useCloudSidebarLinks } from "@/hooks/useCloudSidebarLinks";
|
|
import { SidebarSlackFeedback } from "./SidebarSlackFeedback";
|
|
import { useCanInviteCompanyMembers } from "@/hooks/useCompanyInviteAccess";
|
|
import { useHiddenSettings } from "@/hooks/useHiddenSettings";
|
|
import { useSignOut } from "@/hooks/useSignOut";
|
|
import { useStagingCommit } from "@/hooks/useStagingCommit";
|
|
import { userProfilePath } from "@/lib/userProfileLinks";
|
|
import { useSidebar } from "../context/SidebarContext";
|
|
import { Popover, PopoverTrigger } from "@/components/ui/popover";
|
|
import { FlyoutContent, FlyoutHeader, FlyoutOptions } from "@/components/ui/flyout";
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
import { cn } from "../lib/utils";
|
|
import { ThemeToggle } from "./ThemeToggle";
|
|
import { SidebarServerInfo } from "./SidebarServerInfo";
|
|
import { TruncatedText } from "./TruncatedText";
|
|
|
|
const INVITES_PATH = "/company/settings/members?tab=invites";
|
|
const DOCS_URL = "https://docs.paperclip.ing/";
|
|
const FEEDBACK_URL = "https://paperclip.ing/feedback";
|
|
|
|
interface SidebarAccountMenuProps {
|
|
deploymentMode?: DeploymentMode;
|
|
open?: boolean;
|
|
onOpenChange?: (open: boolean) => void;
|
|
shadow?: CSSProperties["boxShadow"];
|
|
}
|
|
|
|
interface MenuActionProps {
|
|
label: string;
|
|
icon: LucideIcon;
|
|
onClick?: () => void;
|
|
href?: string;
|
|
/** Opens `href` in a new tab (docs and other off-product links). */
|
|
external?: boolean;
|
|
/**
|
|
* Leaves the app in the current tab with a full navigation. Cloud links
|
|
* must use this: the cloud harness shadows those paths on tenant hosts, so
|
|
* the in-app router can never reach them.
|
|
*/
|
|
topLevel?: boolean;
|
|
}
|
|
|
|
function deriveInitials(name: string) {
|
|
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
if (parts.length >= 2) {
|
|
return `${parts[0]?.[0] ?? ""}${parts[parts.length - 1]?.[0] ?? ""}`.toUpperCase();
|
|
}
|
|
return name.slice(0, 2).toUpperCase();
|
|
}
|
|
|
|
function MenuAction({
|
|
label,
|
|
icon: Icon,
|
|
onClick,
|
|
href,
|
|
external = false,
|
|
topLevel = false,
|
|
}: MenuActionProps) {
|
|
const className =
|
|
"flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-accent";
|
|
|
|
const content = (
|
|
<>
|
|
<span className="flex size-5 shrink-0 items-center justify-center text-muted-foreground">
|
|
<Icon className="size-4" />
|
|
</span>
|
|
<TruncatedText className="min-w-0 flex-1 truncate">{label}</TruncatedText>
|
|
</>
|
|
);
|
|
|
|
if (href) {
|
|
if (external) {
|
|
return (
|
|
<a href={href} target="_blank" rel="noreferrer" className={className} onClick={onClick}>
|
|
{content}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
if (topLevel) {
|
|
return (
|
|
<a href={href} className={className} onClick={onClick}>
|
|
{content}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Link to={href} className={className} onClick={onClick}>
|
|
{content}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<button type="button" className={className} onClick={onClick}>
|
|
{content}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
export function SidebarAccountMenu({
|
|
deploymentMode,
|
|
open: controlledOpen,
|
|
onOpenChange,
|
|
shadow,
|
|
}: SidebarAccountMenuProps) {
|
|
const cloud = useCloudInstance();
|
|
const isCloud = Boolean(cloud);
|
|
// Invites live on the Members page (or in Cloud's People settings). Hide the
|
|
// shortcut when the hosting operator hides either surface, and until the
|
|
// health response resolves so a hidden surface never flashes.
|
|
const { hidden: hiddenSettings, loaded: hiddenSettingsLoaded } = useHiddenSettings();
|
|
// On Cloud the shortcut exists only for the current stack's owner/admin and
|
|
// only once the stack metadata is known; the in-app Invites tab is never a
|
|
// fallback there because it drives a different invitation flow.
|
|
const { inviteUrl: cloudInviteUrl, slackFeedback } = useCloudSidebarLinks(cloud);
|
|
// Self-hosted invites need the `users:invite` grant. Offer the shortcut only
|
|
// to boards with role-default access (company owner/admin/operator,
|
|
// instance admins, local boards). The server checks the actual grants.
|
|
const canInviteMembers = useCanInviteCompanyMembers(!isCloud);
|
|
const inviteHref = isCloud ? cloudInviteUrl : canInviteMembers ? INVITES_PATH : null;
|
|
const showInvite =
|
|
hiddenSettingsLoaded &&
|
|
inviteHref !== null &&
|
|
!hidesCompanyPage(hiddenSettings, "company.members") &&
|
|
!hidesCompanyPage(hiddenSettings, "company.invites");
|
|
const [internalOpen, setInternalOpen] = useState(false);
|
|
const { isMobile, setSidebarOpen } = useSidebar();
|
|
const open = controlledOpen ?? internalOpen;
|
|
const stagingCommit = useStagingCommit(open);
|
|
const setOpen = onOpenChange ?? setInternalOpen;
|
|
const { data: session } = useQuery({
|
|
queryKey: queryKeys.auth.session,
|
|
queryFn: () => authApi.getSession(),
|
|
});
|
|
|
|
const signOutMutation = useSignOut({ onSignedOut: closeNavigationChrome });
|
|
|
|
const displayName = session?.user.name?.trim() || "Board";
|
|
const secondaryLabel =
|
|
session?.user.email?.trim() || (deploymentMode === "authenticated" ? "Signed in" : "Local workspace board");
|
|
const initials = deriveInitials(displayName);
|
|
const profileHref = userProfilePath(session?.user);
|
|
|
|
function closeNavigationChrome() {
|
|
setOpen(false);
|
|
if (isMobile) setSidebarOpen(false);
|
|
}
|
|
|
|
function handleSignOut() {
|
|
signOutMutation.mutate();
|
|
}
|
|
|
|
return (
|
|
<div data-sidebar-account="" className="bg-border/50 px-3 py-2 dark:bg-muted">
|
|
<div className="flex items-center gap-0.5 px-2">
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
"flex min-w-0 items-center gap-2.5 rounded-lg text-left text-(length:--text-compact) font-medium text-foreground/80 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
"flex-1 px-2 py-1.5",
|
|
)}
|
|
aria-label="Open account menu"
|
|
>
|
|
<Avatar size="sm">
|
|
{session?.user.image ? <AvatarImage src={session.user.image} alt={displayName} /> : null}
|
|
<AvatarFallback>{initials}</AvatarFallback>
|
|
</Avatar>
|
|
<TruncatedText className="min-w-0 flex-1 truncate">{displayName}</TruncatedText>
|
|
</button>
|
|
</PopoverTrigger>
|
|
<FlyoutContent
|
|
shadow={shadow}
|
|
aria-label="Account"
|
|
side="top"
|
|
align="start"
|
|
sideOffset={10}
|
|
className="w-(--profile-popover-width) max-w-(--sz-calc-24) overflow-hidden rounded-xl border-border bg-popover p-0 shadow-(--shadow-profile-popover)"
|
|
>
|
|
{/* The profile link is a stretched overlay so the staging SHA anchor can sit beside the email without nesting anchors. */}
|
|
<FlyoutHeader data-flyout-profile data-marquee-surface className="relative flex h-(--profile-popover-header-height) shrink-0 items-center gap-2.5 px-3.5">
|
|
<Link
|
|
to={profileHref}
|
|
aria-label="View profile"
|
|
onClick={closeNavigationChrome}
|
|
className="absolute inset-0 transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
|
/>
|
|
<Avatar className="pointer-events-none relative size-9">
|
|
{session?.user.image ? <AvatarImage src={session.user.image} alt={displayName} /> : null}
|
|
<AvatarFallback className="text-xs text-foreground">{initials}</AvatarFallback>
|
|
</Avatar>
|
|
<div className="pointer-events-none relative min-w-0 flex-1">
|
|
<TruncatedText as="h2" className="truncate text-sm font-semibold leading-(--profile-popover-label-line-height) text-foreground">
|
|
{displayName}
|
|
</TruncatedText>
|
|
<TruncatedText as="p" className="truncate text-(length:--text-micro) leading-(--profile-popover-meta-line-height) text-muted-foreground">
|
|
{secondaryLabel}
|
|
</TruncatedText>
|
|
{stagingCommit ? (
|
|
<a
|
|
className="pointer-events-auto block truncate font-mono text-(length:--text-micro) leading-(--profile-popover-meta-line-height) text-muted-foreground hover:underline focus-visible:underline"
|
|
href={`https://github.com/paperclipai/paperclip/commit/${stagingCommit}`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
aria-label={`View commit ${stagingCommit} on GitHub`}
|
|
title={stagingCommit}
|
|
>
|
|
SHA {stagingCommit.slice(0, 7)}
|
|
</a>
|
|
) : null}
|
|
</div>
|
|
</FlyoutHeader>
|
|
|
|
<FlyoutOptions className="flex flex-col gap-0.5 border-t border-border p-2.5">
|
|
<MenuAction
|
|
label="Settings"
|
|
icon={Settings}
|
|
href="/company/settings"
|
|
onClick={closeNavigationChrome}
|
|
/>
|
|
{showInvite && inviteHref ? (
|
|
<MenuAction
|
|
label="Invite"
|
|
icon={UserPlus}
|
|
href={inviteHref}
|
|
topLevel={isCloud}
|
|
onClick={closeNavigationChrome}
|
|
/>
|
|
) : null}
|
|
<MenuAction
|
|
label="Documentation"
|
|
icon={BookOpen}
|
|
href={DOCS_URL}
|
|
external
|
|
onClick={() => setOpen(false)}
|
|
/>
|
|
<ThemeToggle variant="compact-menu-action" onAfterToggle={() => setOpen(false)} />
|
|
{deploymentMode === "authenticated" ? (
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
"flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-destructive/10",
|
|
signOutMutation.isPending && "cursor-not-allowed opacity-60",
|
|
)}
|
|
onClick={handleSignOut}
|
|
disabled={signOutMutation.isPending}
|
|
>
|
|
<span className="flex size-5 shrink-0 items-center justify-center text-muted-foreground">
|
|
<LogOut className="size-4" />
|
|
</span>
|
|
<TruncatedText className="min-w-0 flex-1 truncate">
|
|
{signOutMutation.isPending ? "Signing out..." : "Sign out"}
|
|
</TruncatedText>
|
|
</button>
|
|
) : null}
|
|
<SidebarServerInfo />
|
|
</FlyoutOptions>
|
|
</FlyoutContent>
|
|
</Popover>
|
|
{slackFeedback && <SidebarSlackFeedback feedback={slackFeedback} className="hover:bg-sidebar-accent" />}
|
|
{!isCloud ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<a
|
|
href={FEEDBACK_URL}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
aria-label="Share feedback"
|
|
className="flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground/50 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
>
|
|
<Flag className="h-4 w-4" aria-hidden="true" />
|
|
</a>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">Share feedback</TooltipContent>
|
|
</Tooltip>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|