Skip to content

The open alternative to Salesforce, designed for AI.

Add batch approval review components (#28684)

Raphaël Bosi36e47a4b5d2e
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/search-input.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/search-input.mdx
index d9fb8989dff..bb42a080dc8 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/search-input.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/search-input.mdx
@@ -79,6 +79,10 @@
returns a style object based on the component's state.
</ParamField>
+<ParamField body="textAlign" type="&quot;end&quot; | &quot;start&quot;">
+ Aligns text to the logical start or end of the input. Follows the text direction.
+</ParamField>
+
<ParamField body="value" type="string | number | readonly string[]">
Current search text.
</ParamField>
diff --git a/packages/twenty-docs/snippets/ui/generated/components/navigation/dropdown.mdx b/packages/twenty-docs/snippets/ui/generated/components/navigation/dropdown.mdx
index fe8cfd519d7..2000c2f6997 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/navigation/dropdown.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/navigation/dropdown.mdx
@@ -389,6 +389,10 @@
returns a style object based on the component's state.
</ParamField>
+<ParamField body="Search.textAlign" type="&quot;end&quot; | &quot;start&quot;">
+ Aligns text to the logical start or end of the input. Follows the text direction.
+</ParamField>
+
<ParamField body="Search.value" type="string | number | readonly string[]">
The value of the input. Use when controlled.
</ParamField>
diff --git a/packages/twenty-docs/snippets/ui/generated/input/input.mdx b/packages/twenty-docs/snippets/ui/generated/input/input.mdx
index f2b260a459e..bcc496f861f 100644
--- a/packages/twenty-docs/snippets/ui/generated/input/input.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/input/input.mdx
@@ -45,6 +45,10 @@
returns a style object based on the component's state.
</ParamField>
+<ParamField body="textAlign" type="&quot;end&quot; | &quot;start&quot;">
+ Aligns text to the logical start or end of the input. Follows the text direction.
+</ParamField>
+
<ParamField body="value" type="string | number | readonly string[]">
The value of the input. Use when controlled.
</ParamField>
diff --git a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
index f4b0a6e993a..1e9d1e71363 100644
--- a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
@@ -41,6 +41,10 @@
Native styles applied to the rendered part.
</ParamField>
+<ParamField body="Root.variant" type="&quot;compact&quot; | &quot;default&quot;" default="default">
+ default keeps the standard section appearance. compact uses secondary section backgrounds, 8px header and footer padding, 8px horizontal content padding without vertical padding, and no header divider.
+</ParamField>
+
### Card.Action
<ParamField body="Action.children" type="ReactNode">
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApprovalConfirmation.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApprovalConfirmation.tsx
new file mode 100644
index 00000000000..93b194c7d07
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApprovalConfirmation.tsx
@@ -0,0 +1,109 @@
+import { styled } from '@linaria/react';
+import { Plural, useLingui } from '@lingui/react/macro';
+import { Button } from 'twenty-ui/primitives/input';
+import { AlertDialog } from 'twenty-ui/primitives/surfaces';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { type AiChatApprovalReviewSummary } from '@/ai/types/AiChatApprovalReviewSummary';
+
+const StyledList = styled.ul`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[2]};
+ list-style: none;
+ margin: 0;
+ padding: 0;
+`;
+
+const StyledItem = styled.li`
+ display: flex;
+ flex-wrap: wrap;
+ gap: ${themeCssVariables.spacing[2]};
+ justify-content: space-between;
+ overflow-wrap: anywhere;
+`;
+
+type AiChatApprovalConfirmationProps = {
+ cards: readonly AiChatApprovalReviewSummary[];
+ onConfirm: () => void;
+ onCancel: () => void;
+ disabled?: boolean;
+};
+
+export const AiChatApprovalConfirmation = ({
+ cards,
+ onConfirm,
+ onCancel,
+ disabled = false,
+}: AiChatApprovalConfirmationProps) => {
+ const { t } = useLingui();
+ const cardCount = cards.length;
+ const selectedCount = cards.reduce(
+ (count, card) => count + card.selectedCount,
+ 0,
+ );
+ const skippedCount = cards.reduce(
+ (count, card) => count + card.skippedCount,
+ 0,
+ );
+
+ return (
+ <AlertDialog.Root
+ open
+ onOpenChange={(open) => {
+ if (!open && !disabled) {
+ onCancel();
+ }
+ }}
+ >
+ <AlertDialog.Portal>
+ <AlertDialog.Backdrop />
+ <AlertDialog.Viewport>
+ <AlertDialog.Popup>
+ <AlertDialog.Header>
+ <AlertDialog.Title>
+ <Plural
+ value={cardCount}
+ one="Approve # action?"
+ other="Approve # actions?"
+ />
+ </AlertDialog.Title>
+ <AlertDialog.Description>
+ {t`${selectedCount} records selected · ${skippedCount} records skipped`}
+ </AlertDialog.Description>
+ </AlertDialog.Header>
+ <AlertDialog.Body>
+ <StyledList>
+ {cards.map((card) => (
+ <StyledItem key={card.id}>
+ <span>{card.title}</span>
+ <span>{t`${card.selectedCount} selected · ${card.skippedCount} skipped`}</span>
+ </StyledItem>
+ ))}
+ </StyledList>
+ </AlertDialog.Body>
+ <AlertDialog.Footer>
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={disabled}
+ onClick={onCancel}
+ >
+ {t`Cancel`}
+ </Button>
+ <Button
+ size="sm"
+ color="accent"
+ variant="solid"
+ disabled={disabled || selectedCount === 0 || cardCount === 0}
+ onClick={onConfirm}
+ >
+ {t`Confirm approval`}
+ </Button>
+ </AlertDialog.Footer>
+ </AlertDialog.Popup>
+ </AlertDialog.Viewport>
+ </AlertDialog.Portal>
+ </AlertDialog.Root>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApprovalOutcome.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApprovalOutcome.tsx
new file mode 100644
index 00000000000..a9313f1879f
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApprovalOutcome.tsx
@@ -0,0 +1,78 @@
+import { styled } from '@linaria/react';
+import { msg } from '@lingui/core/macro';
+import { useLingui } from '@lingui/react/macro';
+import { isDefined } from 'twenty-shared/utils';
+import { Tag } from 'twenty-ui/primitives/data-display';
+import { ProgressBar } from 'twenty-ui/primitives/feedback';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { type AiChatApprovalReviewStatus } from '@/ai/types/AiChatApprovalReviewStatus';
+
+const STATUS_LABELS = {
+ pending: msg`Pending`,
+ running: msg`Running`,
+ success: msg`Succeeded`,
+ failed: msg`Failed`,
+ blocked: msg`Blocked`,
+ uncertain: msg`Outcome unknown`,
+ skipped: msg`Skipped`,
+};
+
+const STATUS_COLORS = {
+ pending: 'gray',
+ running: 'blue',
+ success: 'green',
+ failed: 'red',
+ blocked: 'orange',
+ uncertain: 'orange',
+ skipped: 'gray',
+} as const;
+
+const StyledOutcome = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[2]};
+ min-width: 0;
+`;
+
+const StyledDescription = styled.div`
+ align-items: center;
+ display: flex;
+ flex-wrap: wrap;
+ font-size: ${themeCssVariables.font.size.sm};
+ gap: ${themeCssVariables.spacing[2]};
+ overflow-wrap: anywhere;
+`;
+
+type AiChatApprovalOutcomeProps = {
+ status: AiChatApprovalReviewStatus;
+ message?: string;
+ progress?: { completed: number; total: number };
+};
+
+export const AiChatApprovalOutcome = ({
+ status,
+ message,
+ progress,
+}: AiChatApprovalOutcomeProps) => {
+ const { t } = useLingui();
+
+ return (
+ <StyledOutcome>
+ <StyledDescription>
+ <Tag color={STATUS_COLORS[status]} variant="soft">
+ {t(STATUS_LABELS[status])}
+ </Tag>
+ {isDefined(message) && <span>{message}</span>}
+ </StyledDescription>
+ {status === 'running' && isDefined(progress) && progress.total > 0 && (
+ <ProgressBar
+ aria-label={t`Action progress`}
+ value={progress.completed}
+ max={progress.total}
+ size="sm"
+ />
+ )}
+ </StyledOutcome>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApprovalRecordReview.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApprovalRecordReview.tsx
new file mode 100644
index 00000000000..68b45454068
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApprovalRecordReview.tsx
@@ -0,0 +1,302 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+import { IconArrowRight } from 'twenty-ui/icon';
+import { VisuallyHidden } from 'twenty-ui/primitives/accessibility';
+import { Checkbox } from 'twenty-ui/primitives/input';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { AiChatApprovalOutcome } from '@/ai/components/AiChatApprovalOutcome';
+import { type AiChatApprovalReviewCell } from '@/ai/types/AiChatApprovalReviewCell';
+import { type AiChatApprovalReviewColumn } from '@/ai/types/AiChatApprovalReviewColumn';
+import { type AiChatApprovalReviewRecord } from '@/ai/types/AiChatApprovalReviewRecord';
+
+const APPROVAL_REVIEW_ROW_HEIGHT = 32;
+const APPROVAL_REVIEW_STATUS_COLUMN_WIDTH = 140;
+const APPROVAL_REVIEW_CHANGE_ICON_SIZE = 14;
+const APPROVAL_REVIEW_SELECTION_WIDTH = 16;
+
+const StyledTableViewport = styled.div`
+ background: ${themeCssVariables.background.secondary};
+ border: 1px solid ${themeCssVariables.border.color.light};
+ border-radius: ${themeCssVariables.border.radius.sm};
+ min-width: 0;
+ overflow-x: auto;
+`;
+
+const StyledTable = styled.table<{ minimumWidth: number }>`
+ border-collapse: collapse;
+ color: ${themeCssVariables.font.color.primary};
+ font-family: ${themeCssVariables.font.family};
+ font-size: ${themeCssVariables.font.size.md};
+ min-width: ${({ minimumWidth }) => minimumWidth}px;
+ table-layout: fixed;
+ width: 100%;
+`;
+
+const StyledColumn = styled.col<{ columnWidth: number }>`
+ width: ${({ columnWidth }) => columnWidth}px;
+`;
+
+const StyledHeaderCell = styled.th`
+ border-bottom: 1px solid ${themeCssVariables.border.color.light};
+ color: ${themeCssVariables.font.color.tertiary};
+ font-weight: ${themeCssVariables.font.weight.regular};
+ padding: 0;
+ text-align: left;
+
+ &:not(:last-child) {
+ border-right: 1px solid ${themeCssVariables.border.color.light};
+ }
+`;
+
+const StyledRecordRow = styled.tr`
+ &:not(:last-child) {
+ border-bottom: 1px solid ${themeCssVariables.border.color.light};
+ }
+`;
+
+const StyledCell = styled.td<{ isChanged?: boolean }>`
+ background: ${({ isChanged }) =>
+ isChanged ? themeCssVariables.background.transparent.blue : 'transparent'};
+ padding: 0;
+
+ &:not(:last-child) {
+ border-right: 1px solid ${themeCssVariables.border.color.light};
+ }
+`;
+
+const StyledCellContent = styled.div<{ alignment?: 'left' | 'right' }>`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[3]};
+ justify-content: ${({ alignment }) =>
+ alignment === 'right' ? 'flex-end' : 'flex-start'};
+ min-height: ${APPROVAL_REVIEW_ROW_HEIGHT}px;
+ min-width: 0;
+ padding: 0 ${themeCssVariables.spacing[2]};
+ white-space: nowrap;
+`;
+
+const StyledHeaderLabel = styled.span`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[1]};
+ min-width: 0;
+`;
+
+const StyledSelectionControl = styled.span`
+ align-items: center;
+ display: inline-flex;
+ flex: 0 0 ${APPROVAL_REVIEW_SELECTION_WIDTH}px;
+ justify-content: center;
+`;
+
+const StyledValue = styled.div`
+ align-items: center;
+ display: flex;
+ flex: 1;
+ gap: ${themeCssVariables.spacing[1]};
+ justify-content: inherit;
+ min-width: 0;
+`;
+
+const StyledPreviousValue = styled.del`
+ color: ${themeCssVariables.font.color.tertiary};
+ flex-shrink: 0;
+`;
+
+const StyledChangeIcon = styled.span`
+ color: ${themeCssVariables.font.color.tertiary};
+ display: inline-flex;
+ flex-shrink: 0;
+`;
+
+const StyledEmptyCell = styled.td`
+ color: ${themeCssVariables.font.color.tertiary};
+ padding: ${themeCssVariables.spacing[3]};
+ text-align: center;
+`;
+
+type AiChatApprovalRecordReviewProps = {
+ label: string;
+ columns: readonly AiChatApprovalReviewColumn[];
+ records: readonly AiChatApprovalReviewRecord[];
+ selectedRecordIds: readonly string[];
+ onSelectedRecordIdsChange: (recordIds: string[]) => void;
+ operation: 'create' | 'update' | 'delete';
+ disabled?: boolean;
+ renderCell: (cell: {
+ recordId: string;
+ columnId: string;
+ isReadOnly: boolean;
+ }) => AiChatApprovalReviewCell;
+};
+
+export const AiChatApprovalRecordReview = ({
+ label,
+ columns,
+ records,
+ selectedRecordIds,
+ onSelectedRecordIdsChange,
+ operation,
+ disabled = false,
+ renderCell,
+}: AiChatApprovalRecordReviewProps) => {
+ const { t } = useLingui();
+ const selectedRecordIdSet = new Set(selectedRecordIds);
+ const visibleSelectedRecordIds = records
+ .filter(({ id }) => selectedRecordIdSet.has(id))
+ .map(({ id }) => id);
+ const hasRecords = isNonEmptyArray(records);
+ const areAllRecordsSelected =
+ hasRecords && visibleSelectedRecordIds.length === records.length;
+ const areSomeRecordsSelected =
+ isNonEmptyArray(visibleSelectedRecordIds) && !areAllRecordsSelected;
+ const hasRecordStatuses = records.some(({ status }) => isDefined(status));
+ const minimumWidth =
+ columns.reduce((width, column) => width + column.width, 0) +
+ (hasRecordStatuses ? APPROVAL_REVIEW_STATUS_COLUMN_WIDTH : 0);
+ const isReadOnly = disabled || operation === 'delete';
+
+ const handleRecordSelectionChange = ({
+ recordId,
+ isSelected,
+ }: {
+ recordId: string;
+ isSelected: boolean;
+ }) => {
+ onSelectedRecordIdsChange(
+ records
+ .filter(({ id }) =>
+ id === recordId ? isSelected : selectedRecordIdSet.has(id),
+ )
+ .map(({ id }) => id),
+ );
+ };
+
+ return (
+ <StyledTableViewport
+ role="region"
+ aria-label={t`Scrollable record review`}
+ tabIndex={0}
+ >
+ <StyledTable aria-label={label} minimumWidth={minimumWidth}>
+ <colgroup>
+ {columns.map((column) => (
+ <StyledColumn key={column.id} columnWidth={column.width} />
+ ))}
+ {hasRecordStatuses && (
+ <StyledColumn columnWidth={APPROVAL_REVIEW_STATUS_COLUMN_WIDTH} />
+ )}
+ </colgroup>
+ <thead>
+ <tr>
+ {columns.map((column, columnIndex) => (
+ <StyledHeaderCell key={column.id} scope="col">
+ <StyledCellContent>
+ {columnIndex === 0 && (
+ <StyledSelectionControl>
+ <Checkbox
+ aria-label={t`Select all records`}
+ checked={areAllRecordsSelected}
+ indeterminate={areSomeRecordsSelected}
+ disabled={disabled || !hasRecords}
+ onCheckedChange={(isSelected) =>
+ onSelectedRecordIdsChange(
+ isSelected ? records.map(({ id }) => id) : [],
+ )
+ }
+ />
+ </StyledSelectionControl>
+ )}
+ <StyledHeaderLabel>
+ {column.icon}
+ {column.label}
+ </StyledHeaderLabel>
+ </StyledCellContent>
+ </StyledHeaderCell>
+ ))}
+ {hasRecordStatuses && (
+ <StyledHeaderCell scope="col">
+ <StyledCellContent>{t`Status`}</StyledCellContent>
+ </StyledHeaderCell>
+ )}
+ </tr>
+ </thead>
+ <tbody>
+ {records.map((record) => (
+ <StyledRecordRow key={record.id}>
+ {columns.map((column, columnIndex) => {
+ const cell = renderCell({
+ recordId: record.id,
+ columnId: column.id,
+ isReadOnly,
+ });
+ const hasPreviousValue =
+ cell.isChanged && isDefined(cell.previousValue);
+
+ return (
+ <StyledCell key={column.id} isChanged={cell.isChanged}>
+ <StyledCellContent alignment={column.align}>
+ {columnIndex === 0 && (
+ <StyledSelectionControl>
+ <Checkbox
+ aria-label={t`Select ${record.label}`}
+ checked={selectedRecordIdSet.has(record.id)}
+ disabled={disabled}
+ onCheckedChange={(isSelected) =>
+ handleRecordSelectionChange({
+ recordId: record.id,
+ isSelected,
+ })
+ }
+ />
+ </StyledSelectionControl>
+ )}
+ <StyledValue>
+ {hasPreviousValue && (
+ <>
+ <VisuallyHidden>{t`Previous value:`}</VisuallyHidden>
+ <StyledPreviousValue>
+ {cell.previousValue}
+ </StyledPreviousValue>
+ <StyledChangeIcon aria-hidden="true">
+ <IconArrowRight
+ size={APPROVAL_REVIEW_CHANGE_ICON_SIZE}
+ />
+ </StyledChangeIcon>
+ <VisuallyHidden>{t`Proposed value:`}</VisuallyHidden>
+ </>
+ )}
+ {cell.value}
+ </StyledValue>
+ </StyledCellContent>
+ </StyledCell>
+ );
+ })}
+ {hasRecordStatuses && (
+ <StyledCell>
+ <StyledCellContent>
+ {isDefined(record.status) && (
+ <AiChatApprovalOutcome status={record.status} />
+ )}
+ </StyledCellContent>
+ </StyledCell>
+ )}
+ </StyledRecordRow>
+ ))}
+ {!hasRecords && (
+ <tr>
+ <StyledEmptyCell
+ colSpan={columns.length + Number(hasRecordStatuses)}
+ >
+ {t`No records to review`}
+ </StyledEmptyCell>
+ </tr>
+ )}
+ </tbody>
+ </StyledTable>
+ </StyledTableViewport>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApprovalReviewDeck.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApprovalReviewDeck.tsx
new file mode 100644
index 00000000000..83520d1f78a
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApprovalReviewDeck.tsx
@@ -0,0 +1,227 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined } from 'twenty-shared/utils';
+import { CountPager } from 'twenty-ui/components/navigation';
+import { Button } from 'twenty-ui/primitives/input';
+import { Card } from 'twenty-ui/primitives/surfaces';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { AiChatApprovalOutcome } from '@/ai/components/AiChatApprovalOutcome';
+import { type AiChatApprovalReviewCard } from '@/ai/types/AiChatApprovalReviewCard';
+
+const DECK_EDGE_HEIGHT_PX = 4;
+const DECK_BACK_EDGE_INSET_PX = 16;
+const DECK_MIDDLE_EDGE_INSET_PX = 8;
+const DECK_HEADER_HEIGHT_PX = 24;
+const DECK_HINT_MIN_WIDTH_PX = 160;
+
+const StyledDeck = styled.div`
+ min-width: 0;
+ width: 100%;
+`;
+
+const StyledStackEdge = styled.div<{ inset: number }>`
+ background: ${themeCssVariables.background.secondary};
+ border: 1px solid ${themeCssVariables.border.color.medium};
+ border-bottom: 0;
+ border-radius: ${themeCssVariables.border.radius.sm}
+ ${themeCssVariables.border.radius.sm} 0 0;
+ box-sizing: border-box;
+ height: ${DECK_EDGE_HEIGHT_PX}px;
+ margin: 0 ${({ inset }) => inset}px;
+`;
+
+const StyledHeader = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[2]};
+`;
+
+const StyledTitle = styled.div`
+ align-items: center;
+ color: ${themeCssVariables.font.color.primary};
+ display: flex;
+ flex: 1;
+ font-size: ${themeCssVariables.font.size.md};
+ font-weight: ${themeCssVariables.font.weight.medium};
+ gap: ${themeCssVariables.spacing[2]};
+ min-height: ${DECK_HEADER_HEIGHT_PX}px;
+ min-width: 0;
+ overflow-wrap: anywhere;
+ padding-left: ${themeCssVariables.spacing[1]};
+`;
+
+const StyledIcon = styled.span<{ isDestructive?: boolean }>`
+ color: ${({ isDestructive }) =>
+ isDestructive
+ ? themeCssVariables.font.color.danger
+ : themeCssVariables.font.color.secondary};
+ display: inline-flex;
+ flex-shrink: 0;
+`;
+
+const StyledFooter = styled.div`
+ align-items: center;
+ display: flex;
+ flex-wrap: wrap;
+ gap: ${themeCssVariables.spacing[2]};
+`;
+
+const StyledHint = styled.div`
+ color: ${themeCssVariables.font.color.tertiary};
+ flex: 1 1 ${DECK_HINT_MIN_WIDTH_PX}px;
+ font-size: ${themeCssVariables.font.size.sm};
+ min-width: 0;
+ overflow-wrap: anywhere;
+ padding-left: ${themeCssVariables.spacing[1]};
+`;
+
+const StyledActions = styled.div`
+ align-items: center;
+ display: flex;
+ flex-wrap: wrap;
+ gap: ${themeCssVariables.spacing[2]};
+ margin-left: auto;
+`;
+
+const StyledOutcome = styled.div`
+ padding: ${themeCssVariables.spacing[2]};
+`;
+
+const StyledEmpty = styled.div`
+ color: ${themeCssVariables.font.color.secondary};
+ padding: ${themeCssVariables.spacing[4]};
+`;
+
+type AiChatApprovalReviewDeckProps = {
+ cards: readonly AiChatApprovalReviewCard[];
+ activeIndex: number;
+ onActiveIndexChange: (index: number) => void;
+ onRequestApproval: (cardIds: string[]) => void;
+ onDeny: (cardId: string) => void;
+ disabled?: boolean;
+};
+
+export const AiChatApprovalReviewDeck = ({
+ cards,
+ activeIndex,
+ onActiveIndexChange,
+ onRequestApproval,
+ onDeny,
+ disabled = false,
+}: AiChatApprovalReviewDeckProps) => {
+ const { t } = useLingui();
+ const activeCard = cards[activeIndex];
+
+ if (!isDefined(activeCard)) {
+ return <StyledEmpty role="status">{t`No actions to review`}</StyledEmpty>;
+ }
+
+ const pendingCards = cards.filter((card) => card.status === 'pending');
+ const pendingCardIds = pendingCards.map((card) => card.id);
+ const hasSelectedItems = pendingCards.some((card) => card.selectedCount > 0);
+ const isActiveCardPending = activeCard.status === 'pending';
+ const canApproveActiveCard =
+ !disabled && isActiveCardPending && activeCard.selectedCount > 0;
+ const pendingCardCount = pendingCards.length;
+ const nextTitles = cards
+ .filter((card, index) => index > activeIndex && card.status === 'pending')
+ .map((card) => card.title)
+ .join(', ');
+ const selectionSummary = t`${activeCard.selectedCount} selected · ${activeCard.skippedCount} skipped`;
+ const nextActionHint = isNonEmptyString(nextTitles)
+ ? t`Next: ${nextTitles}`
+ : selectionSummary;
+ const hint =
+ activeCard.skippedCount > 0
+ ? selectionSummary
+ : (activeCard.hint ?? nextActionHint);
+
+ return (
+ <StyledDeck aria-label={t`Approval review`} role="region">
+ {cards.length > 2 && <StyledStackEdge inset={DECK_BACK_EDGE_INSET_PX} />}
+ {cards.length > 1 && (
+ <StyledStackEdge inset={DECK_MIDDLE_EDGE_INSET_PX} />
+ )}
+ <Card.Root
+ fullWidth
+ variant="compact"
+ role="group"
+ aria-label={activeCard.title}
+ >
+ <Card.Header>
+ <StyledHeader>
+ <StyledTitle>
+ <StyledIcon
+ aria-hidden="true"
+ isDestructive={activeCard.isDestructive}
+ >
+ {activeCard.icon}
+ </StyledIcon>
+ {activeCard.title}
+ </StyledTitle>
+ {cards.length > 1 && (
+ <CountPager
+ index={activeIndex}
+ count={cards.length}
+ disabled={disabled}
+ onIndexChange={onActiveIndexChange}
+ positionText={`${activeIndex + 1}/${cards.length}`}
+ previousLabel={t`Previous approval`}
+ nextLabel={t`Next approval`}
+ />
+ )}
+ </StyledHeader>
+ </Card.Header>
+ <Card.Content>{activeCard.content}</Card.Content>
+ <div role="status" aria-atomic="true">
+ {!isActiveCardPending && (
+ <StyledOutcome>
+ <AiChatApprovalOutcome
+ status={activeCard.status}
+ message={activeCard.outcomeMessage}
+ progress={activeCard.progress}
+ />
+ </StyledOutcome>
+ )}
+ </div>
+ <Card.Footer divider={false}>
+ <StyledFooter>
+ <StyledHint>{hint}</StyledHint>
+ <StyledActions>
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={disabled || !isActiveCardPending}
+ onClick={() => onDeny(activeCard.id)}
+ >
+ {t`Deny`}
+ </Button>
+ {pendingCardCount > 1 && (
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={disabled || !hasSelectedItems}
+ onClick={() => onRequestApproval(pendingCardIds)}
+ >
+ {t`Approve all ${pendingCardCount}`}
+ </Button>
+ )}
+ <Button
+ size="sm"
+ color={activeCard.isDestructive ? 'danger' : 'accent'}
+ variant="solid"
+ disabled={!canApproveActiveCard}
+ loading={activeCard.status === 'running'}
+ onClick={() => onRequestApproval([activeCard.id])}
+ >
+ {activeCard.approveLabel}
+ </Button>
+ </StyledActions>
+ </StyledFooter>
+ </Card.Footer>
+ </Card.Root>
+ </StyledDeck>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewDeck.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewDeck.stories.tsx
new file mode 100644
index 00000000000..f5243aec006
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewDeck.stories.tsx
@@ -0,0 +1,540 @@
+import { styled } from '@linaria/react';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+import { isDefined } from 'twenty-shared/utils';
+import { ComponentDecorator } from 'twenty-ui/testing';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { AiChatApprovalOutcome } from '@/ai/components/AiChatApprovalOutcome';
+import { AiChatApprovalReviewDeck } from '@/ai/components/AiChatApprovalReviewDeck';
+import { AiChatApprovalReviewExample } from '@/ai/components/__stories__/AiChatApprovalReviewExample';
+import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';
+import { RootDecorator } from '~/testing/decorators/RootDecorator';
+
+const StyledOutcomes = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[4]};
+`;
+
+const meta = {
+ title: 'Modules/AI/AiChatApprovalReviewDeck',
+ component: AiChatApprovalReviewExample,
+ decorators: [ComponentDecorator, MemoryRouterDecorator, RootDecorator],
+ parameters: { container: { width: 728 }, argos: { fitToContent: false } },
+ args: { onApprove: fn(), onDeny: fn() },
+} satisfies Meta<typeof AiChatApprovalReviewExample>;
+
+export default meta;
+
+type Story = StoryObj<typeof meta>;
+
+export const Create: Story = {};
+
+export const KeyboardFieldFocus: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select Sundar Pichai' }),
+ );
+ await userEvent.tab();
+
+ const name = canvas.getByRole('textbox', { name: 'Sundar Pichai People' });
+ const label = name.parentElement;
+
+ await expect(name).toHaveFocus();
+ await expect(getComputedStyle(name).outlineWidth).toBe('2px');
+
+ if (!isDefined(label)) {
+ throw new Error('Editable record label is missing');
+ }
+
+ await expect(getComputedStyle(label).overflowX).toBe('visible');
+ await expect(getComputedStyle(label).overflowY).toBe('visible');
+ },
+};
+
+export const Update: Story = {
+ args: { initialActiveIndex: 1 },
+};
+
+export const Delete: Story = {
+ args: { initialActiveIndex: 2 },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expect(
+ canvas.getByRole('table', { name: 'Delete 2 people review' }),
+ ).toBeVisible();
+ await expect(canvas.queryByRole('textbox')).not.toBeInTheDocument();
+ await expect(canvas.getByText('[email protected]')).toBeVisible();
+ await expect(
+ canvas.getByRole('button', { name: 'Delete 2' }),
+ ).toBeEnabled();
+ },
+};
+
+export const RetainedEditsAndSelection: Story = {
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const email = canvas.getByRole('textbox', { name: 'Sundar Pichai Email' });
+
+ await userEvent.clear(email);
+ await userEvent.type(email, '[email protected]');
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select Thomas Kurian' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Create 2' }),
+ ).toBeEnabled();
+ await expect(
+ canvas.getByText('2 selected · 1 skipped', { exact: false }),
+ ).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Next approval' }),
+ );
+
+ const employees = canvas.getByRole('textbox', { name: 'Stripe Employees' });
+
+ await userEvent.clear(employees);
+ await userEvent.type(employees, '9,250');
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select Airbnb' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Update 1' }),
+ ).toBeEnabled();
+ await expect(
+ canvas.getByText('1 selected · 1 skipped', { exact: false }),
+ ).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Next approval' }),
+ );
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select Reid Hoffman' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Delete 1' }),
+ ).toBeEnabled();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Previous approval' }),
+ );
+
+ await expect(
+ canvas.getByRole('textbox', { name: 'Stripe Employees' }),
+ ).toHaveValue('9,250');
+ await expect(
+ canvas.getByRole('checkbox', { name: 'Select Airbnb' }),
+ ).not.toBeChecked();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Previous approval' }),
+ );
+ await expect(
+ canvas.getByRole('textbox', { name: 'Sundar Pichai Email' }),
+ ).toHaveValue('[email protected]');
+ await expect(
+ canvas.getByRole('checkbox', { name: 'Select Thomas Kurian' }),
+ ).not.toBeChecked();
+
+ const editedEmail = canvas.getByRole('textbox', {
+ name: 'Sundar Pichai Email',
+ });
+ const deny = canvas.getByRole('button', { name: 'Deny' });
+ const nextApproval = canvas.getByRole('button', { name: 'Next approval' });
+
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Approve all 3' }),
+ );
+
+ const dialog = await body.findByRole('alertdialog');
+
+ await expect(
+ within(dialog).getByRole('heading', { name: 'Approve 3 actions?' }),
+ ).toBeVisible();
+ await waitFor(() => {
+ expect(dialog.contains(canvasElement.ownerDocument.activeElement)).toBe(
+ true,
+ );
+ });
+ await expect(editedEmail).toBeDisabled();
+ await expect(deny).toBeDisabled();
+ await expect(nextApproval).toBeDisabled();
+ await userEvent.click(
+ within(dialog).getByRole('button', { name: 'Cancel' }),
+ );
+ await expect(editedEmail).toHaveValue('[email protected]');
+ await expect(deny).toBeEnabled();
+ await expect(nextApproval).toBeEnabled();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Approve all 3' }),
+ );
+
+ const reopenedDialog = within(await body.findByRole('alertdialog'));
+
+ await userEvent.click(
+ reopenedDialog.getByRole('button', { name: 'Confirm approval' }),
+ );
+ await expect(args.onApprove).toHaveBeenCalledWith({
+ cards: [
+ expect.objectContaining({
+ id: 'create-people',
+ selectedRecordIds: ['sundar', 'roelof'],
+ skippedRecordIds: ['thomas'],
+ records: expect.arrayContaining([
+ expect.objectContaining({
+ id: 'sundar',
+ values: expect.objectContaining({
+ email: '[email protected]',
+ }),
+ }),
+ ]),
+ }),
+ expect.objectContaining({
+ id: 'update-companies',
+ selectedRecordIds: ['stripe'],
+ skippedRecordIds: ['airbnb'],
+ records: expect.arrayContaining([
+ expect.objectContaining({
+ id: 'stripe',
+ values: expect.objectContaining({ employees: '9,250' }),
+ }),
+ ]),
+ }),
+ expect.objectContaining({
+ id: 'delete-people',
+ selectedRecordIds: ['stewart'],
+ skippedRecordIds: ['reid'],
+ }),
+ ],
+ });
+ },
+};
+
+export const ApproveAllIncludesUnopenedCards: Story = {
+ args: {
+ initialSelectedRecordIds: {
+ 'create-people': ['sundar', 'roelof'],
+ 'update-companies': ['stripe'],
+ 'delete-people': ['reid'],
+ },
+ },
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await expect(
+ canvas.queryByRole('table', { name: 'Update 2 companies review' }),
+ ).not.toBeInTheDocument();
+ await expect(
+ canvas.getByRole('button', { name: 'Create 2' }),
+ ).toBeEnabled();
+ await expect(
+ canvas.getByText('2 selected · 1 skipped', { exact: false }),
+ ).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Approve all 3' }),
+ );
+
+ const confirmation = within(await body.findByRole('alertdialog'));
+
+ await expect(
+ confirmation.getByRole('heading', { name: 'Approve 3 actions?' }),
+ ).toBeVisible();
+ await expect(confirmation.getAllByRole('listitem')).toHaveLength(3);
+ await expect(confirmation.getByText('Create 3 people')).toBeVisible();
+ await expect(confirmation.getByText('Update 2 companies')).toBeVisible();
+ await expect(confirmation.getByText('Delete 2 people')).toBeVisible();
+ await expect(
+ confirmation.getByText('2 selected · 1 skipped'),
+ ).toBeVisible();
+ await expect(
+ confirmation.getAllByText('1 selected · 1 skipped'),
+ ).toHaveLength(2);
+ await expect(
+ confirmation.getByText('4 records selected · 3 records skipped'),
+ ).toBeVisible();
+ await expect(args.onApprove).not.toHaveBeenCalled();
+ await userEvent.click(
+ confirmation.getByRole('button', { name: 'Confirm approval' }),
+ );
+ await expect(args.onApprove).toHaveBeenCalledWith({
+ cards: [
+ expect.objectContaining({
+ id: 'create-people',
+ selectedRecordIds: ['sundar', 'roelof'],
+ skippedRecordIds: ['thomas'],
+ }),
+ expect.objectContaining({
+ id: 'update-companies',
+ selectedRecordIds: ['stripe'],
+ skippedRecordIds: ['airbnb'],
+ }),
+ expect.objectContaining({
+ id: 'delete-people',
+ selectedRecordIds: ['reid'],
+ skippedRecordIds: ['stewart'],
+ }),
+ ],
+ });
+ },
+};
+
+export const ApproveCurrentCard: Story = {
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const outcomeStatus = canvas.getByRole('status');
+
+ await expect(outcomeStatus).toBeEmptyDOMElement();
+
+ await userEvent.click(canvas.getByRole('button', { name: 'Create 3' }));
+
+ const confirmation = within(await body.findByRole('alertdialog'));
+
+ await expect(
+ confirmation.getByRole('heading', { name: 'Approve 1 action?' }),
+ ).toBeVisible();
+ await expect(confirmation.getAllByRole('listitem')).toHaveLength(1);
+ await expect(confirmation.getByText('Create 3 people')).toBeVisible();
+ await userEvent.click(
+ confirmation.getByRole('button', { name: 'Confirm approval' }),
+ );
+ await expect(args.onApprove).toHaveBeenCalledWith({
+ cards: [
+ expect.objectContaining({
+ id: 'create-people',
+ selectedRecordIds: ['sundar', 'thomas', 'roelof'],
+ skippedRecordIds: [],
+ }),
+ ],
+ });
+ await expect(canvas.getAllByText('Succeeded')).toHaveLength(4);
+ await expect(canvas.getByRole('status')).toBe(outcomeStatus);
+ await expect(outcomeStatus).toHaveTextContent('Succeeded');
+ await expect(
+ canvas.getByRole('button', { name: 'Create 3' }),
+ ).toBeDisabled();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Next approval' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Update 2' }),
+ ).toBeEnabled();
+ await expect(canvas.getByRole('status')).toBe(outcomeStatus);
+ await expect(outcomeStatus).toBeEmptyDOMElement();
+ await expect(
+ canvas.getByRole('button', { name: 'Approve all 2' }),
+ ).toBeEnabled();
+ await expect(
+ canvas.getByRole('textbox', { name: 'Stripe ARR' }),
+ ).toHaveValue('$2,100,000');
+ await expect(
+ canvas.getByRole('checkbox', { name: 'Select all records' }),
+ ).toBeChecked();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Next approval' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Delete 2' }),
+ ).toBeEnabled();
+ await expect(args.onDeny).not.toHaveBeenCalled();
+ },
+};
+
+export const DenyCurrentCard: Story = {
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(canvas.getByRole('button', { name: 'Deny' }));
+ await expect(args.onDeny).toHaveBeenCalledWith('create-people');
+ await expect(args.onApprove).not.toHaveBeenCalled();
+ await expect(canvas.getAllByText('Skipped')).toHaveLength(4);
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Next approval' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Update 2' }),
+ ).toBeEnabled();
+ },
+};
+
+export const Running: Story = {
+ args: { initialStatus: 'running' },
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ for (const input of canvas.getAllByRole('textbox')) {
+ await expect(input).toBeDisabled();
+ }
+
+ for (const checkbox of canvas.getAllByRole('checkbox')) {
+ await expect(checkbox).toHaveAttribute('aria-disabled', 'true');
+ }
+
+ await expect(canvas.getByRole('button', { name: 'Deny' })).toBeDisabled();
+ await expect(
+ canvas.getByRole('button', { name: 'Create 3' }),
+ ).toBeDisabled();
+ await expect(
+ canvas.getByRole('progressbar', { name: 'Action progress' }),
+ ).toHaveAttribute('aria-valuenow', '1');
+ await userEvent.click(canvas.getByRole('button', { name: 'Create 3' }));
+ await expect(args.onApprove).not.toHaveBeenCalled();
+ await expect(args.onDeny).not.toHaveBeenCalled();
+ },
+};
+
+export const NoSelectedRecords: Story = {
+ args: {
+ initialSelectedRecordIds: {
+ 'create-people': [],
+ 'update-companies': [],
+ 'delete-people': [],
+ },
+ },
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+ const approve = canvas.getByRole('button', { name: 'Create 0' });
+ const approveAll = canvas.getByRole('button', { name: 'Approve all 3' });
+
+ await expect(approve).toBeDisabled();
+ await expect(approveAll).toBeDisabled();
+ await expect(
+ canvas.getByText('0 selected · 3 skipped', { exact: false }),
+ ).toBeVisible();
+ await userEvent.click(approve);
+ await userEvent.click(approveAll);
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select all records' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Create 3' }),
+ ).toBeEnabled();
+ for (const checkbox of canvas.getAllByRole('checkbox')) {
+ await expect(checkbox).toBeChecked();
+ }
+ await userEvent.click(
+ canvas.getByRole('checkbox', { name: 'Select all records' }),
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Create 0' }),
+ ).toBeDisabled();
+ await expect(args.onApprove).not.toHaveBeenCalled();
+ await expect(args.onDeny).not.toHaveBeenCalled();
+ },
+};
+
+export const RecordOutcomes: Story = {
+ args: {
+ initialStatus: 'success',
+ initialSelectedRecordIds: { 'create-people': ['sundar'] },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const sundar = within(canvas.getByRole('row', { name: /Sundar Pichai/ }));
+ const thomas = within(canvas.getByRole('row', { name: /Thomas Kurian/ }));
+ const roelof = within(canvas.getByRole('row', { name: /Roelof Botha/ }));
+
+ await expect(sundar.getByText('Succeeded')).toBeVisible();
+ await expect(thomas.getByText('Skipped')).toBeVisible();
+ await expect(roelof.getByText('Skipped')).toBeVisible();
+
+ for (const input of canvas.getAllByRole('textbox')) {
+ await expect(input).toBeDisabled();
+ }
+
+ for (const checkbox of canvas.getAllByRole('checkbox')) {
+ await expect(checkbox).toHaveAttribute('aria-disabled', 'true');
+ }
+
+ await expect(canvas.getByRole('button', { name: 'Deny' })).toBeDisabled();
+ await expect(
+ canvas.getByRole('button', { name: 'Create 1' }),
+ ).toBeDisabled();
+ },
+};
+
+export const Empty: Story = {
+ render: () => (
+ <AiChatApprovalReviewDeck
+ cards={[]}
+ activeIndex={0}
+ onActiveIndexChange={fn()}
+ onRequestApproval={fn()}
+ onDeny={fn()}
+ />
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expect(canvas.getByRole('status')).toHaveTextContent(
+ 'No actions to review',
+ );
+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
+ },
+};
+
+export const OutcomeStates: Story = {
+ render: () => (
+ <StyledOutcomes>
+ <AiChatApprovalOutcome
+ status="pending"
+ message="Waiting for your review"
+ />
+ <AiChatApprovalOutcome
+ status="running"
+ message="Creating 3 people"
+ progress={{ completed: 1, total: 3 }}
+ />
+ <AiChatApprovalOutcome status="success" message="3 people created" />
+ <AiChatApprovalOutcome
+ status="failed"
+ message="The record was not saved"
+ />
+ <AiChatApprovalOutcome
+ status="blocked"
+ message="You need permission to delete these records"
+ />
+ <AiChatApprovalOutcome
+ status="uncertain"
+ message="Check the record before trying again"
+ />
+ <AiChatApprovalOutcome status="skipped" message="No records changed" />
+ </StyledOutcomes>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ for (const label of [
+ 'Pending',
+ 'Running',
+ 'Succeeded',
+ 'Failed',
+ 'Blocked',
+ 'Outcome unknown',
+ 'Skipped',
+ ]) {
+ await expect(canvas.getByText(label)).toBeVisible();
+ }
+ },
+};
+
+export const NarrowReview: Story = {
+ args: { initialActiveIndex: 1 },
+ parameters: { container: { width: 360 } },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const scrollRegion = canvas.getByRole('region', {
+ name: 'Scrollable record review',
+ });
+
+ await expect(scrollRegion.scrollWidth).toBeGreaterThan(
+ scrollRegion.clientWidth,
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Update 2' }),
+ ).toBeVisible();
+ },
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExample.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExample.tsx
new file mode 100644
index 00000000000..b8af5754617
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExample.tsx
@@ -0,0 +1,231 @@
+import { styled } from '@linaria/react';
+import { useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { IconBuildingSkyscraper, IconTrash, IconUser } from 'twenty-ui/icon';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { AiChatApprovalConfirmation } from '@/ai/components/AiChatApprovalConfirmation';
+import { AiChatApprovalRecordReview } from '@/ai/components/AiChatApprovalRecordReview';
+import { AiChatApprovalReviewDeck } from '@/ai/components/AiChatApprovalReviewDeck';
+import { AI_CHAT_APPROVAL_REVIEW_FIXTURES } from '@/ai/components/__stories__/aiChatApprovalReviewFixtures';
+import { AiChatApprovalReviewExampleCell } from '@/ai/components/__stories__/AiChatApprovalReviewExampleCell';
+import { type AiChatApprovalReviewSnapshot } from '@/ai/components/__stories__/AiChatApprovalReviewSnapshot';
+import { getAiChatApprovalReviewRecordStatus } from '@/ai/components/__stories__/getAiChatApprovalReviewRecordStatus';
+import { type AiChatApprovalReviewCard } from '@/ai/types/AiChatApprovalReviewCard';
+import { type AiChatApprovalReviewStatus } from '@/ai/types/AiChatApprovalReviewStatus';
+import { TextDisplay } from '@/ui/field/display/components/TextDisplay/TextDisplay';
+
+const APPROVAL_REVIEW_ICON_SIZE = 16;
+const APPROVAL_REVIEW_ICONS = {
+ create: IconUser,
+ update: IconBuildingSkyscraper,
+ delete: IconTrash,
+};
+
+const StyledExample = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[3]};
+ min-width: 0;
+`;
+
+type AiChatApprovalReviewExampleProps = {
+ initialStatus?: AiChatApprovalReviewStatus;
+ initialActiveIndex?: number;
+ initialSelectedRecordIds?: Record<string, string[]>;
+ onApprove: (snapshot: AiChatApprovalReviewSnapshot) => void;
+ onDeny: (cardId: string) => void;
+};
+
+export const AiChatApprovalReviewExample = ({
+ initialStatus = 'pending',
+ initialActiveIndex = 0,
+ initialSelectedRecordIds,
+ onApprove,
+ onDeny,
+}: AiChatApprovalReviewExampleProps) => {
+ const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
+ const [statuses, setStatuses] = useState<
+ Record<string, AiChatApprovalReviewStatus>
+ >(() =>
+ Object.fromEntries(
+ AI_CHAT_APPROVAL_REVIEW_FIXTURES.map(({ id }) => [id, initialStatus]),
+ ),
+ );
+ const [selectedRecordIds, setSelectedRecordIds] = useState<
+ Record<string, string[]>
+ >(() =>
+ Object.fromEntries(
+ AI_CHAT_APPROVAL_REVIEW_FIXTURES.map(({ id, records }) => [
+ id,
+ initialSelectedRecordIds?.[id] ?? records.map((record) => record.id),
+ ]),
+ ),
+ );
+ const [recordValues, setRecordValues] = useState<
+ Record<string, Record<string, string>>
+ >(() =>
+ Object.fromEntries(
+ AI_CHAT_APPROVAL_REVIEW_FIXTURES.flatMap(({ records }) =>
+ records.map(({ id, values }) => [id, { ...values }]),
+ ),
+ ),
+ );
+ const [confirmation, setConfirmation] =
+ useState<AiChatApprovalReviewSnapshot | null>(null);
+
+ const handleRequestApproval = (cardIds: string[]) => {
+ setConfirmation({
+ cards: AI_CHAT_APPROVAL_REVIEW_FIXTURES.filter(({ id }) =>
+ cardIds.includes(id),
+ ).map(({ id, title, records }) => {
+ const selectedIds = selectedRecordIds[id] ?? [];
+
+ return {
+ id,
+ title,
+ selectedRecordIds: [...selectedIds],
+ skippedRecordIds: records
+ .filter((record) => !selectedIds.includes(record.id))
+ .map((record) => record.id),
+ records: records.map((record) => ({
+ id: record.id,
+ values: { ...recordValues[record.id] },
+ })),
+ };
+ }),
+ });
+ };
+
+ const handleConfirm = () => {
+ if (!isDefined(confirmation)) {
+ return;
+ }
+
+ onApprove(confirmation);
+ setStatuses((currentStatuses) => ({
+ ...currentStatuses,
+ ...Object.fromEntries(
+ confirmation.cards.map(({ id, selectedRecordIds }) => [
+ id,
+ selectedRecordIds.length > 0 ? 'success' : 'skipped',
+ ]),
+ ),
+ }));
+ setConfirmation(null);
+ };
+
+ const handleDeny = (cardId: string) => {
+ setStatuses((currentStatuses) => ({
+ ...currentStatuses,
+ [cardId]: 'skipped',
+ }));
+ onDeny(cardId);
+ };
+
+ const cards: AiChatApprovalReviewCard[] =
+ AI_CHAT_APPROVAL_REVIEW_FIXTURES.map((fixture) => {
+ const selectedIds = selectedRecordIds[fixture.id] ?? [];
+ const status = statuses[fixture.id] ?? 'pending';
+ const isDisabled = status !== 'pending' || isDefined(confirmation);
+ const Icon = APPROVAL_REVIEW_ICONS[fixture.operation];
+
+ return {
+ id: fixture.id,
+ title: fixture.title,
+ approveLabel: `${fixture.approveVerb} ${selectedIds.length}`,
+ selectedCount: selectedIds.length,
+ skippedCount: fixture.records.length - selectedIds.length,
+ status,
+ icon: <Icon size={APPROVAL_REVIEW_ICON_SIZE} />,
+ isDestructive: fixture.operation === 'delete',
+ hint: fixture.hint,
+ progress:
+ status === 'running'
+ ? { completed: 1, total: fixture.records.length }
+ : undefined,
+ content: (
+ <AiChatApprovalRecordReview
+ label={`${fixture.title} review`}
+ columns={fixture.columns}
+ records={fixture.records.map((record) => ({
+ ...record,
+ status: getAiChatApprovalReviewRecordStatus({
+ status,
+ isSelected: selectedIds.includes(record.id),
+ }),
+ }))}
+ selectedRecordIds={selectedIds}
+ disabled={isDisabled}
+ operation={fixture.operation}
+ onSelectedRecordIdsChange={(recordIds) =>
+ setSelectedRecordIds((currentIds) => ({
+ ...currentIds,
+ [fixture.id]: recordIds,
+ }))
+ }
+ renderCell={({ recordId, columnId, isReadOnly }) => {
+ const record = fixture.records.find(
+ (candidate) => candidate.id === recordId,
+ );
+ const column = fixture.columns.find(
+ (candidate) => candidate.id === columnId,
+ );
+ const value = recordValues[recordId]?.[columnId] ?? '';
+ const previousValue = record?.previousValues?.[columnId];
+
+ return {
+ value: (
+ <AiChatApprovalReviewExampleCell
+ operation={fixture.operation}
+ column={column}
+ recordLabel={record?.label}
+ value={value}
+ isReadOnly={isReadOnly}
+ onValueChange={(nextValue) =>
+ setRecordValues((currentValues) => ({
+ ...currentValues,
+ [recordId]: {
+ ...currentValues[recordId],
+ [columnId]: nextValue,
+ },
+ }))
+ }
+ />
+ ),
+ previousValue: isDefined(previousValue) ? (
+ <TextDisplay text={previousValue} />
+ ) : undefined,
+ isChanged: isDefined(previousValue) && value !== previousValue,
+ };
+ }}
+ />
+ ),
+ };
+ });
+
+ return (
+ <StyledExample>
+ <AiChatApprovalReviewDeck
+ cards={cards}
+ activeIndex={activeIndex}
+ onActiveIndexChange={setActiveIndex}
+ onRequestApproval={handleRequestApproval}
+ onDeny={handleDeny}
+ disabled={isDefined(confirmation)}
+ />
+ {isDefined(confirmation) && (
+ <AiChatApprovalConfirmation
+ cards={confirmation.cards.map((card) => ({
+ id: card.id,
+ title: card.title,
+ selectedCount: card.selectedRecordIds.length,
+ skippedCount: card.skippedRecordIds.length,
+ }))}
+ onConfirm={handleConfirm}
+ onCancel={() => setConfirmation(null)}
+ />
+ )}
+ </StyledExample>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExampleCell.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExampleCell.tsx
new file mode 100644
index 00000000000..a102bd9ac1f
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewExampleCell.tsx
@@ -0,0 +1,83 @@
+import { styled } from '@linaria/react';
+import { Avatar, Chip } from 'twenty-ui/primitives/data-display';
+import { Input } from 'twenty-ui/primitives/input';
+
+import { type AiChatApprovalReviewFixture } from '@/ai/components/__stories__/AiChatApprovalReviewFixture';
+import { type AiChatApprovalReviewColumn } from '@/ai/types/AiChatApprovalReviewColumn';
+import { TextDisplay } from '@/ui/field/display/components/TextDisplay/TextDisplay';
+
+const StyledNumericEditor = styled.span<{ contentWidth: number }>`
+ display: inline-flex;
+ inline-size: ${({ contentWidth }) => contentWidth}ch;
+ min-width: 0;
+`;
+
+type AiChatApprovalReviewExampleCellProps = {
+ operation: AiChatApprovalReviewFixture['operation'];
+ column?: AiChatApprovalReviewColumn;
+ recordLabel?: string;
+ value: string;
+ isReadOnly: boolean;
+ onValueChange: (value: string) => void;
+};
+
+export const AiChatApprovalReviewExampleCell = ({
+ operation,
+ column,
+ recordLabel,
+ value,
+ isReadOnly,
+ onValueChange,
+}: AiChatApprovalReviewExampleCellProps) => {
+ const isEditable = operation !== 'delete';
+ const isRecordChip = column?.id === 'name' || column?.id === 'company';
+ const isAvatarSquare = column?.id === 'company' || operation === 'update';
+
+ const renderValue = () => {
+ if (!isEditable) {
+ return <TextDisplay text={value} />;
+ }
+
+ const input = (
+ <Input
+ aria-label={`${recordLabel} ${column?.label}`}
+ variant="plain"
+ size="sm"
+ value={value}
+ disabled={isReadOnly}
+ textAlign={column?.align === 'right' ? 'end' : 'start'}
+ onValueChange={onValueChange}
+ />
+ );
+
+ if (column?.align === 'right') {
+ return (
+ <StyledNumericEditor contentWidth={Math.max(value.length, 1)}>
+ {input}
+ </StyledNumericEditor>
+ );
+ }
+
+ return input;
+ };
+
+ if (!isRecordChip) {
+ return renderValue();
+ }
+
+ return (
+ <Chip
+ variant="soft"
+ truncate={!isEditable}
+ startElement={
+ <Avatar
+ name={value}
+ size="xs"
+ shape={isAvatarSquare ? 'square' : 'circle'}
+ />
+ }
+ >
+ {renderValue()}
+ </Chip>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewFixture.ts b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewFixture.ts
new file mode 100644
index 00000000000..2a72d03c986
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewFixture.ts
@@ -0,0 +1,16 @@
+import { type AiChatApprovalReviewColumn } from '@/ai/types/AiChatApprovalReviewColumn';
+
+export type AiChatApprovalReviewFixture = {
+ id: string;
+ title: string;
+ approveVerb: string;
+ operation: 'create' | 'update' | 'delete';
+ hint?: string;
+ columns: readonly AiChatApprovalReviewColumn[];
+ records: readonly {
+ id: string;
+ label: string;
+ values: Record<string, string>;
+ previousValues?: Record<string, string>;
+ }[];
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewSnapshot.ts b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewSnapshot.ts
new file mode 100644
index 00000000000..6a48abf9c7a
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatApprovalReviewSnapshot.ts
@@ -0,0 +1,9 @@
+export type AiChatApprovalReviewSnapshot = {
+ cards: {
+ id: string;
+ title: string;
+ selectedRecordIds: string[];
+ skippedRecordIds: string[];
+ records: { id: string; values: Record<string, string> }[];
+ }[];
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/aiChatApprovalReviewFixtures.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/aiChatApprovalReviewFixtures.tsx
new file mode 100644
index 00000000000..e616d5e8ee2
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/aiChatApprovalReviewFixtures.tsx
@@ -0,0 +1,177 @@
+import {
+ IconBriefcase,
+ IconBuildingSkyscraper,
+ IconCurrencyDollar,
+ IconMail,
+ IconNumbers,
+ IconPhone,
+ IconUser,
+} from 'twenty-ui/icon';
+
+import { type AiChatApprovalReviewFixture } from '@/ai/components/__stories__/AiChatApprovalReviewFixture';
+
+const APPROVAL_REVIEW_FIELD_ICON_SIZE = 12;
+
+const PEOPLE_COLUMNS = [
+ {
+ id: 'name',
+ label: 'People',
+ icon: <IconUser size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 180,
+ },
+ {
+ id: 'email',
+ label: 'Email',
+ icon: <IconMail size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 234,
+ },
+ {
+ id: 'company',
+ label: 'Company',
+ icon: <IconBuildingSkyscraper size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 234,
+ },
+ {
+ id: 'phone',
+ label: 'Phone',
+ icon: <IconPhone size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 234,
+ },
+ {
+ id: 'job',
+ label: 'Job',
+ icon: <IconBriefcase size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 234,
+ },
+];
+
+export const AI_CHAT_APPROVAL_REVIEW_FIXTURES: readonly AiChatApprovalReviewFixture[] =
+ [
+ {
+ id: 'create-people',
+ title: 'Create 3 people',
+ approveVerb: 'Create',
+ operation: 'create',
+ columns: PEOPLE_COLUMNS,
+ records: [
+ {
+ id: 'sundar',
+ label: 'Sundar Pichai',
+ values: {
+ name: 'Sundar Pichai',
+ email: '[email protected]',
+ company: 'Google',
+ phone: '(920) 948-1722',
+ job: 'CEO',
+ },
+ },
+ {
+ id: 'thomas',
+ label: 'Thomas Kurian',
+ values: {
+ name: 'Thomas Kurian',
+ email: '[email protected]',
+ company: 'Google',
+ phone: '(256) 289-9707',
+ job: 'Founder',
+ },
+ },
+ {
+ id: 'roelof',
+ label: 'Roelof Botha',
+ values: {
+ name: 'Roelof Botha',
+ email: '[email protected]',
+ company: 'Sequoia',
+ phone: '(347) 438-7215',
+ job: 'Partner',
+ },
+ },
+ ],
+ },
+ {
+ id: 'update-companies',
+ title: 'Update 2 companies',
+ approveVerb: 'Update',
+ operation: 'update',
+ hint: 'Only changed fields are shown',
+ columns: [
+ {
+ id: 'name',
+ label: 'Companies',
+ icon: (
+ <IconBuildingSkyscraper size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />
+ ),
+ width: 180,
+ },
+ {
+ id: 'arr',
+ label: 'ARR',
+ icon: <IconCurrencyDollar size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 243,
+ align: 'right',
+ },
+ {
+ id: 'employees',
+ label: 'Employees',
+ icon: <IconNumbers size={APPROVAL_REVIEW_FIELD_ICON_SIZE} />,
+ width: 243,
+ align: 'right',
+ },
+ ],
+ records: [
+ {
+ id: 'stripe',
+ label: 'Stripe',
+ values: {
+ name: 'Stripe',
+ arr: '$2,100,000',
+ employees: '9,000',
+ },
+ previousValues: { arr: '$1,800,000', employees: '8,500' },
+ },
+ {
+ id: 'airbnb',
+ label: 'Airbnb',
+ values: {
+ name: 'Airbnb',
+ arr: '$4,500,000',
+ employees: '8,200',
+ },
+ previousValues: { arr: '$4,200,000' },
+ },
+ ],
+ },
+ {
+ id: 'delete-people',
+ title: 'Delete 2 people',
+ approveVerb: 'Delete',
+ operation: 'delete',
+ hint: 'You can restore them from the Trash',
+ columns: PEOPLE_COLUMNS,
+ records: [
+ {
+ id: 'reid',
+ label: 'Reid Hoffman',
+ values: {
+ name: 'Reid Hoffman',
+ email: '[email protected]',
+ company: 'LinkedIn',
+ phone: '(907) 248-8330',
+ job: 'Partner',
+ },
+ },
+ {
+ id: 'stewart',
+ label: 'Stewart Butterfield',
+ values: {
+ name: 'Stewart Butterfield',
+ email: '[email protected]',
+ company: 'Slack',
+ phone: '(617) 623-2338',
+ job: 'CEO',
+ },
+ },
+ ],
+ },
+ ];
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/getAiChatApprovalReviewRecordStatus.ts b/packages/twenty-front/src/modules/ai/components/__stories__/getAiChatApprovalReviewRecordStatus.ts
new file mode 100644
index 00000000000..ff1f3653513
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/getAiChatApprovalReviewRecordStatus.ts
@@ -0,0 +1,19 @@
+import { type AiChatApprovalReviewStatus } from '@/ai/types/AiChatApprovalReviewStatus';
+
+export const getAiChatApprovalReviewRecordStatus = ({
+ status,
+ isSelected,
+}: {
+ status: AiChatApprovalReviewStatus;
+ isSelected: boolean;
+}): AiChatApprovalReviewStatus | undefined => {
+ if (status === 'pending') {
+ return undefined;
+ }
+
+ if (!isSelected) {
+ return 'skipped';
+ }
+
+ return status;
+};
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCard.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCard.ts
new file mode 100644
index 00000000000..99b1cb0c772
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCard.ts
@@ -0,0 +1,15 @@
+import { type ReactNode } from 'react';
+
+import { type AiChatApprovalReviewStatus } from '@/ai/types/AiChatApprovalReviewStatus';
+import { type AiChatApprovalReviewSummary } from '@/ai/types/AiChatApprovalReviewSummary';
+
+export type AiChatApprovalReviewCard = AiChatApprovalReviewSummary & {
+ icon: ReactNode;
+ content: ReactNode;
+ approveLabel: string;
+ status: AiChatApprovalReviewStatus;
+ isDestructive?: boolean;
+ hint?: string;
+ outcomeMessage?: string;
+ progress?: { completed: number; total: number };
+};
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCell.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCell.ts
new file mode 100644
index 00000000000..f254b7649c6
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewCell.ts
@@ -0,0 +1,7 @@
+import { type ReactNode } from 'react';
+
+export type AiChatApprovalReviewCell = {
+ value: ReactNode;
+ previousValue?: ReactNode;
+ isChanged?: boolean;
+};
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewColumn.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewColumn.ts
new file mode 100644
index 00000000000..87bcb67abb2
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewColumn.ts
@@ -0,0 +1,9 @@
+import { type ReactNode } from 'react';
+
+export type AiChatApprovalReviewColumn = {
+ id: string;
+ label: string;
+ icon?: ReactNode;
+ width: number;
+ align?: 'left' | 'right';
+};
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewRecord.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewRecord.ts
new file mode 100644
index 00000000000..3a645509144
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewRecord.ts
@@ -0,0 +1,7 @@
+import { type AiChatApprovalReviewStatus } from '@/ai/types/AiChatApprovalReviewStatus';
+
+export type AiChatApprovalReviewRecord = {
+ id: string;
+ label: string;
+ status?: AiChatApprovalReviewStatus;
+};
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewStatus.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewStatus.ts
new file mode 100644
index 00000000000..7d495167bfc
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewStatus.ts
@@ -0,0 +1,8 @@
+export type AiChatApprovalReviewStatus =
+ | 'pending'
+ | 'running'
+ | 'success'
+ | 'failed'
+ | 'blocked'
+ | 'uncertain'
+ | 'skipped';
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewSummary.ts b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewSummary.ts
new file mode 100644
index 00000000000..97d00a8d8e1
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/types/AiChatApprovalReviewSummary.ts
@@ -0,0 +1,6 @@
+export type AiChatApprovalReviewSummary = {
+ id: string;
+ title: string;
+ selectedCount: number;
+ skippedCount: number;
+};
diff --git a/packages/twenty-ui/docs/cardPropDescriptions.ts b/packages/twenty-ui/docs/cardPropDescriptions.ts
index d23ce71599c..e251667ad4a 100644
--- a/packages/twenty-ui/docs/cardPropDescriptions.ts
+++ b/packages/twenty-ui/docs/cardPropDescriptions.ts
@@ -3,6 +3,8 @@ import { type CardRootProps } from '../src/primitives/surfaces/Card/types/CardRo
export const CARD_PROP_DESCRIPTIONS = {
children: 'Card sections or other content.',
fullWidth: 'Sets the card width to 100% of its container.',
+ variant:
+ 'default keeps the standard section appearance. compact uses secondary section backgrounds, 8px header and footer padding, 8px horizontal content padding without vertical padding, and no header divider.',
backgroundColor:
'CSS background color of the outer card. Child sections have their own backgrounds.',
className: 'CSS class merged with the part class.',
diff --git a/packages/twenty-ui/docs/dropdownPartPropDescriptions.ts b/packages/twenty-ui/docs/dropdownPartPropDescriptions.ts
index 290cdcd1f8d..5619464489d 100644
--- a/packages/twenty-ui/docs/dropdownPartPropDescriptions.ts
+++ b/packages/twenty-ui/docs/dropdownPartPropDescriptions.ts
@@ -10,6 +10,7 @@ import { type DropdownSearchProps } from '../src/components/navigation/Dropdown/
import { type DropdownSelectionGroupProps } from '../src/components/navigation/Dropdown/types/DropdownSelectionGroupProps';
import { type DropdownSectionProps } from '../src/components/navigation/Dropdown/types/DropdownSectionProps';
import { type DropdownSubmenuTriggerProps } from '../src/components/navigation/Dropdown/types/DropdownSubmenuTriggerProps';
+import { INPUT_PROP_DESCRIPTIONS } from './inputPropDescriptions';
const DROPDOWN_ROOT_PROP_DESCRIPTIONS = {
type: 'Interaction model: `menu` for commands and links, `picker` for search and selectable options, or `panel` for forms. It sets the ARIA roles, initial focus, and keyboard navigation.',
@@ -93,6 +94,7 @@ export const DROPDOWN_PART_PROP_DESCRIPTIONS = {
'Element or function rendered as the group. Functions receive supplied props and `{ value, multiple }` state. Forward the props and ref.',
} satisfies Partial<Record<keyof DropdownSelectionGroupProps, string>>,
Search: {
+ textAlign: INPUT_PROP_DESCRIPTIONS.textAlign,
hasFocusRing:
'Shows the search input focus outline. Defaults to false for all dropdown searches. Set true to opt in. Error styling remains visible.',
onValueChange:
diff --git a/packages/twenty-ui/docs/inputPropDescriptions.ts b/packages/twenty-ui/docs/inputPropDescriptions.ts
index c25a4c737f8..8c8ab583a68 100644
--- a/packages/twenty-ui/docs/inputPropDescriptions.ts
+++ b/packages/twenty-ui/docs/inputPropDescriptions.ts
@@ -4,6 +4,8 @@ export const INPUT_PROP_DESCRIPTIONS = {
variant:
'default keeps the field frame. plain removes fill, border, radius and padding and uses natural height. Its outline follows native :focus-visible, including pointer focus or autofocus on text inputs; invalid state uses a danger outline. InputGroup always owns the grouped frame.',
size: 'Visual size. Explicit input size takes precedence over the InputGroup default, then md applies. Group layout still sets the surrounding height.',
+ textAlign:
+ 'Aligns text to the logical start or end of the input. Follows the text direction.',
hasFocusRing:
'Set false to hide the focus border or outline while keeping errors visible. Defaults to true. InputGroup controls grouped focus styling.',
ref: 'Ref to the native input element.',
diff --git a/packages/twenty-ui/docs/searchInputPropDescriptions.ts b/packages/twenty-ui/docs/searchInputPropDescriptions.ts
index c3ef977db86..25f16c386e3 100644
--- a/packages/twenty-ui/docs/searchInputPropDescriptions.ts
+++ b/packages/twenty-ui/docs/searchInputPropDescriptions.ts
@@ -1,6 +1,7 @@
import { type ComponentProps } from 'react';
import { type SearchInput } from '../src/components/input/SearchInput/SearchInput';
+import { INPUT_PROP_DESCRIPTIONS } from './inputPropDescriptions';
export const SEARCH_INPUT_PROP_DESCRIPTIONS = {
value: 'Current search text.',
@@ -8,6 +9,7 @@ export const SEARCH_INPUT_PROP_DESCRIPTIONS = {
onChange: 'Native input change event handler.',
ref: 'Ref to the native input element.',
size: 'Visual size of the input group.',
+ textAlign: INPUT_PROP_DESCRIPTIONS.textAlign,
hasFocusRing:
'Shows the group focus border. Defaults to false for all search inputs. Set true to opt in. Error styling remains visible.',
placeholder:
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 03350e10c44..3d0156d18d2 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -3917,6 +3917,13 @@
"defaultValue": null,
"description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
},
+ {
+ "name": "textAlign",
+ "type": "\"end\" | \"start\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Aligns text to the logical start or end of the input. Follows the text direction."
+ },
{
"name": "value",
"type": "string | number | readonly string[]",
@@ -8414,6 +8421,13 @@
"required": false,
"defaultValue": null,
"description": "Native styles applied to the rendered part."
+ },
+ {
+ "name": "variant",
+ "type": "\"compact\" | \"default\"",
+ "required": false,
+ "defaultValue": "default",
+ "description": "default keeps the standard section appearance. compact uses secondary section backgrounds, 8px header and footer padding, 8px horizontal content padding without vertical padding, and no header divider."
}
]
},
@@ -12851,6 +12865,13 @@
"defaultValue": null,
"description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
},
+ {
+ "name": "textAlign",
+ "type": "\"end\" | \"start\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Aligns text to the logical start or end of the input. Follows the text direction."
+ },
{
"name": "value",
"type": "string | number | readonly string[]",
@@ -15495,6 +15516,13 @@
"defaultValue": null,
"description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
},
+ {
+ "name": "textAlign",
+ "type": "\"end\" | \"start\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Aligns text to the logical start or end of the input. Follows the text direction."
+ },
{
"name": "value",
"type": "string | number | readonly string[]",
diff --git a/packages/twenty-ui/src/primitives/input/Input/Input.module.scss b/packages/twenty-ui/src/primitives/input/Input/Input.module.scss
index ebe9f05ef9b..cb153a867ce 100644
--- a/packages/twenty-ui/src/primitives/input/Input/Input.module.scss
+++ b/packages/twenty-ui/src/primitives/input/Input/Input.module.scss
@@ -42,6 +42,14 @@
cursor: not-allowed;
}
+ &[data-text-align='start'] {
+ text-align: start;
+ }
+
+ &[data-text-align='end'] {
+ text-align: end;
+ }
+
&[data-variant='plain'],
&[data-grouped] {
background-color: transparent;
diff --git a/packages/twenty-ui/src/primitives/input/Input/Input.tsx b/packages/twenty-ui/src/primitives/input/Input/Input.tsx
index 0b12751115d..34dbe7bf10e 100644
--- a/packages/twenty-ui/src/primitives/input/Input/Input.tsx
+++ b/packages/twenty-ui/src/primitives/input/Input/Input.tsx
@@ -13,6 +13,7 @@ export const Input = ({
size,
variant = 'default',
hasFocusRing = true,
+ textAlign,
className,
...props
}: InputProps) => {
@@ -31,6 +32,7 @@ export const Input = ({
data-variant={resolvedVariant}
data-focus-ring={hasFocusRing}
data-grouped={isGrouped || undefined}
+ data-text-align={textAlign}
/>
);
};
diff --git a/packages/twenty-ui/src/primitives/input/Input/__stories__/Input.stories.tsx b/packages/twenty-ui/src/primitives/input/Input/__stories__/Input.stories.tsx
index 1718faef618..3e83a9d11ec 100644
--- a/packages/twenty-ui/src/primitives/input/Input/__stories__/Input.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Input/__stories__/Input.stories.tsx
@@ -70,6 +70,12 @@ export const WithField: Story = {
},
};
+export const EndAligned: Story = {
+ args: { defaultValue: '2,100,000', textAlign: 'end' },
+ decorators: [ComponentDecorator],
+ parameters: { container: { width: 240 } },
+};
+
type InputCatalogState = 'default' | 'focus' | 'invalid' | 'disabled';
const getInputCatalogStateProps = (state: InputCatalogState) => {
diff --git a/packages/twenty-ui/src/primitives/input/Input/types/InputProps.ts b/packages/twenty-ui/src/primitives/input/Input/types/InputProps.ts
index d32ec041fd1..ac9fc311958 100644
--- a/packages/twenty-ui/src/primitives/input/Input/types/InputProps.ts
+++ b/packages/twenty-ui/src/primitives/input/Input/types/InputProps.ts
@@ -7,4 +7,5 @@ export type InputProps = Omit<InputPrimitive.Props, 'size'> & {
size?: InputSize;
variant?: InputVariant;
hasFocusRing?: boolean;
+ textAlign?: 'start' | 'end';
};
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss
index 7f2cf10b550..4481c37066e 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss
@@ -4,6 +4,11 @@
@include CardOwner.card-owner;
--card-section-background-color: initial;
+ --card-default-section-background-color: initial;
+ --card-header-padding: initial;
+ --card-header-border-width: initial;
+ --card-content-padding: initial;
+ --card-footer-padding: initial;
background-color: var(--card-background-color, transparent);
border: 1px solid var(--t-border-color-medium);
@@ -17,4 +22,12 @@
&[data-full-width] {
width: 100%;
}
+
+ &[data-variant='compact'] {
+ --card-default-section-background-color: var(--t-background-secondary);
+ --card-header-padding: var(--t-spacing-2);
+ --card-header-border-width: 0px;
+ --card-content-padding: 0 var(--t-spacing-2);
+ --card-footer-padding: var(--t-spacing-2);
+ }
}
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss
index a4894bd8eff..024759a9b1f 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss
@@ -5,12 +5,12 @@
background-color: var(
--card-section-background-color,
- var(--t-background-secondary)
+ var(--card-default-section-background-color, var(--t-background-secondary))
);
border: 0;
font-size: inherit;
font-weight: inherit;
- padding: var(--t-spacing-4);
+ padding: var(--card-content-padding, var(--t-spacing-4));
width: 100%;
&[data-divider] {
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss
index daa1288faf8..9ad69a84e17 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss
@@ -5,12 +5,12 @@
background-color: var(
--card-section-background-color,
- var(--t-background-primary)
+ var(--card-default-section-background-color, var(--t-background-primary))
);
border: 0;
border-top: 1px solid var(--t-border-color-medium);
font-size: var(--t-font-size-sm);
- padding: var(--t-spacing-2) var(--t-spacing-4);
+ padding: var(--card-footer-padding, var(--t-spacing-2) var(--t-spacing-4));
width: 100%;
// divider defaults to true; only an explicit false removes the border
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss
index 60b129ed7be..1f7068ac84f 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss
@@ -5,12 +5,13 @@
background-color: var(
--card-section-background-color,
- var(--t-background-primary)
+ var(--card-default-section-background-color, var(--t-background-primary))
);
border: 0;
- border-bottom: 1px solid var(--t-border-color-medium);
+ border-bottom: var(--card-header-border-width, 1px) solid
+ var(--t-border-color-medium);
font-size: var(--t-font-size-sm);
font-weight: var(--t-font-weight-medium);
- padding: var(--t-spacing-2) var(--t-spacing-4);
+ padding: var(--card-header-padding, var(--t-spacing-2) var(--t-spacing-4));
width: 100%;
}
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx
index 9cbc4c8e7a1..570b89d3fc1 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx
@@ -30,6 +30,11 @@ export const Display: Story = {
render: (args) => <CardDisplayExample {...args} />,
};
+export const Compact: Story = {
+ args: { variant: 'compact' },
+ parameters: { container: { width: 480 } },
+};
+
const CardDisplayExample = (props: ComponentProps<typeof Card.Root>) => {
const titleId = useId();
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx
index 99d02cc5a58..3cb256b5286 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx
@@ -12,6 +12,7 @@ export const CardRoot = ({
className,
fullWidth,
backgroundColor,
+ variant = 'default',
style,
render,
ref,
@@ -24,6 +25,7 @@ export const CardRoot = ({
...props,
className: clsx(styles.card, className),
'data-full-width': fullWidth || undefined,
+ 'data-variant': variant,
style: isDefined(backgroundColor)
? ({
...style,
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts
index 34858dde37e..6f44cf40338 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts
@@ -3,4 +3,5 @@ import { type useRender } from '@base-ui/react/use-render';
export type CardRootProps = useRender.ComponentProps<'div'> & {
fullWidth?: boolean;
backgroundColor?: string;
+ variant?: 'default' | 'compact';
};