Assistant

An assistant beside a record on a raised page: the deal on the left, and a conversation on the right that cites its sources and proposes a change to apply, which lands in the record and its activity.

Open full screen

Inset · Sidebar. <AppShell direction="inset">, the default: the navigation on the grey app frame, the page a raised white card inside it, scrolling within.

npx wideset add block-assistant

Import the default export from @/blocks/wideset/assistant. The files below are relative to your project's source directory.

Installed with this block
  • app-shell
  • avatar
  • block-styles
  • breadcrumbs
  • button
  • card
  • checkbox
  • chip
  • divider
  • dropdown-menu
  • icon-button
  • list-item
  • sidebar
  • text-input
  • utils
blocks/wideset/assistant/index.tsx
'use client';

import '@/styles/wideset-blocks.css';

import { RiSideBarLine } from '@remixicon/react';
import { AppShell } from '@/components/ui/wideset/app-shell/AppShell';
import { Breadcrumbs } from '@/components/ui/wideset/breadcrumbs/Breadcrumbs';
import { cn } from '@/lib/wideset/utils';
import { IconButton } from '@/components/ui/wideset/button/IconButton';
import { useId, useState } from 'react';

import { ActivityTimeline } from './activity-timeline';
import { AssistantPanel } from './assistant-panel';
import { deal, maya, NOW, proposedCloseDate, proposedStep } from './data';
import { FactsList } from './facts-list';
import { formatDay, formatUsd } from './format';
import { KeyValue } from './key-value';
import { NextSteps } from './next-steps';
import { PersonAvatar } from './person-avatar';
import { RecordHeader } from './record-header';
import { Section } from './section';
import { AssistantSidebar } from './sidebar';

/**
 * The record's column: the canonical one, but 60rem wide, not 80rem, since the 26rem assistant
 * card already takes the rest of the window and a wider record would only stretch its lines.
 */
const COLUMN = 'px-ws-14 mx-auto w-full max-w-[60rem]';

/**
 * Assistant (Inset direction): the Halcyon Freight renewal deal on the raised page beside the
 * workspace sidebar, with Orbit's assistant in a second raised card, 26rem, beside it on the same
 * grey frame. The record is the context, drawn plainly: its figures, key facts, next steps and
 * activity. The assistant is the subject: it answers with its sources and proposes changes, and
 * applying one writes it to the record on the left and logs it in the activity.
 */
export default function Assistant() {
  const sidebarId = useId();
  const [collapsed, setCollapsed] = useState(false);
  const [record, setRecord] = useState(deal);

  const apply = () =>
    setRecord((current) => ({
      ...current,
      closeDate: proposedCloseDate,
      nextSteps: [...current.nextSteps, proposedStep],
      activity: [
        {
          id: 'assistant-change',
          kind: 'change',
          actor: maya,
          action: 'changed the close date and added a next step, from the assistant',
          at: NOW,
        },
        ...current.activity,
      ],
    }));

  return (
    <AppShell className="ws-block-utility" direction="inset">
      <AssistantSidebar id={sidebarId} collapsed={collapsed} onCollapsedChange={setCollapsed} />
      <AppShell.Main>
        <div className="h-ws-18 border-ws-static-base flex shrink-0 items-center border-b">
          {/* The bar belongs to the surround: it runs edge to edge. The sidebar's toggle is pulled
              left so its glyph, not its box, sits 20px from the edge; the crumbs follow it. */}
          <div className="gap-ws-5 px-ws-11 flex w-full items-center">
            <IconButton
              icon={RiSideBarLine}
              variant="secondary"
              preset="ghost"
              size="sm"
              iconClassName="text-ws-static-subtle size-ws-9"
              aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
              aria-expanded={!collapsed}
              aria-controls={sidebarId}
              onClick={() => setCollapsed((collapsed) => !collapsed)}
              className="-ml-ws-5"
            />
            <Breadcrumbs separator="arrow">
              <Breadcrumbs.Item asChild>
                <a href="#deals">Deals</a>
              </Breadcrumbs.Item>
              <Breadcrumbs.Item>{record.name}</Breadcrumbs.Item>
            </Breadcrumbs>
          </div>
        </div>

        {/* The record scrolls inside its card; the assistant's card keeps its composer in reach. */}
        <div className="ws-scrollbar min-h-0 flex-1 overflow-y-auto">
          <div className={cn(COLUMN, 'gap-ws-14 pt-ws-14 pb-ws-16 flex flex-col')}>
            <RecordHeader />

            <dl className="gap-ws-9 grid grid-cols-4">
              <KeyValue label="Stage">{record.stage}</KeyValue>
              <KeyValue label="Amount">{formatUsd(record.amount)}</KeyValue>
              <KeyValue label="Close date">{formatDay(record.closeDate)}</KeyValue>
              <KeyValue label="Owner">
                <span className="gap-ws-5 flex items-center">
                  <PersonAvatar
                    size="xs"
                    name={record.owner.name}
                    initials={record.owner.initials}
                    color={record.owner.color}
                  />
                  {record.owner.name}
                </span>
              </KeyValue>
            </dl>

            <Section title="Key facts">
              <FactsList facts={record.facts} />
            </Section>

            <Section title="Next steps">
              <NextSteps steps={record.nextSteps} />
            </Section>

            <Section title="Activity">
              <ActivityTimeline items={record.activity} />
            </Section>
          </div>
        </div>
      </AppShell.Main>

      <AssistantPanel onApply={apply} />
    </AppShell>
  );
}