diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 352cbff9002c..f13050b7fcf9 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -8749,6 +8749,12 @@ const CONST = { MFA_OVERLAY: { BACKDROP: 'MfaOverlay-Backdrop', }, + AGENTS: { + TABLE_ROW: 'Agents-TableRow', + CHAT: 'Agents-Chat', + COPILOT: 'Agents-Copilot', + EDIT: 'Agents-Edit', + }, DOMAIN: { ADMINS: { ROW: 'DomainAdmins-Row', diff --git a/src/components/Tables/AgentsTable/AgentsTableRow.tsx b/src/components/Tables/AgentsTable/AgentsTableRow.tsx new file mode 100644 index 000000000000..78b1a3e1d236 --- /dev/null +++ b/src/components/Tables/AgentsTable/AgentsTableRow.tsx @@ -0,0 +1,133 @@ +import Button from '@components/ButtonComposed'; +import Icon from '@components/Icon'; +import ReportActionAvatars from '@components/ReportActionAvatars'; +import Table from '@components/Table'; +import TextWithTooltip from '@components/TextWithTooltip'; + +import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; +import useLocalize from '@hooks/useLocalize'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; + +import variables from '@styles/variables'; + +import CONST from '@src/CONST'; + +import React from 'react'; +import {View} from 'react-native'; + +import type {AgentRowData} from '.'; + +type AgentsTableRowProps = { + /** Data about the agent */ + item: AgentRowData; + + /** The index of the row relative to all other rows */ + rowIndex: number; + + /** Whether to use narrow table row layout */ + shouldUseNarrowTableLayout: boolean; +}; + +export default function AgentsTableRow({item, rowIndex, shouldUseNarrowTableLayout}: AgentsTableRowProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const styleUtils = useStyleUtils(); + const {translate} = useLocalize(); + const icons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'ChatBubble']); + + const avatarSize = shouldUseNarrowTableLayout ? CONST.AVATAR_SIZE.DEFAULT : CONST.AVATAR_SIZE.SMALL; + const isPendingDeletion = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + const isPendingAddOrDelete = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || isPendingDeletion; + const areActionsDisabled = isPendingAddOrDelete || item.accountID <= 0 || !item.login; + const accessibilityLabel = [item.displayName, item.login].filter(Boolean).join(', '); + + const getSecondaryAvatarContainerStyle = (hovered: boolean) => [ + styleUtils.getBackgroundAndBorderStyle(theme.sidebar), + hovered ? styleUtils.getBackgroundAndBorderStyle(styles.sidebarLinkHover?.backgroundColor ?? theme.sidebar) : undefined, + ]; + + return ( + + {({hovered}) => ( + <> + + + + + + + + + + {!shouldUseNarrowTableLayout && ( + + + + + + )} + + + + )} + + ); +} diff --git a/src/components/Tables/AgentsTable/index.tsx b/src/components/Tables/AgentsTable/index.tsx new file mode 100644 index 000000000000..e6fb2e389742 --- /dev/null +++ b/src/components/Tables/AgentsTable/index.tsx @@ -0,0 +1,93 @@ +import type {CompareItemsCallback, IsItemInSearchCallback, TableColumn, TableData} from '@components/Table'; +import Table from '@components/Table'; + +import useLocalize from '@hooks/useLocalize'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; + +import tokenizedSearch from '@libs/tokenizedSearch'; + +import variables from '@styles/variables'; + +import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; + +import type {ListRenderItemInfo} from '@shopify/flash-list'; + +import React from 'react'; + +import AgentsTableRow from './AgentsTableRow'; + +type AgentsTableColumnKey = 'agent' | 'actions'; + +type AgentRowData = TableData & { + accountID: number; + displayName: string; + login: string; + errors?: OnyxCommon.Errors; + pendingAction?: OnyxCommon.PendingAction; + action: () => void; + onChatPress: () => void; + onCopilotPress: () => void; + dismissError: () => void; +}; + +type AgentsTableProps = { + agents: AgentRowData[]; +}; + +export default function AgentsTable({agents}: AgentsTableProps) { + const {translate, localeCompare} = useLocalize(); + const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout(); + + const shouldUseNarrowTableLayout = shouldUseNarrowLayout || isMediumScreenWidth; + + const agentsTableColumns: Array> = [ + { + key: 'agent', + label: translate('agentsPage.title'), + sortable: true, + }, + { + key: 'actions', + label: '', + sortable: false, + width: shouldUseNarrowTableLayout ? variables.tableCaretColumnWidth : variables.agentsTableActionColumnWidth, + }, + ]; + + const compareTableItems: CompareItemsCallback = (item1, item2, activeSorting) => { + const orderMultiplier = activeSorting.order === 'asc' ? 1 : -1; + return localeCompare(item1.displayName, item2.displayName) * orderMultiplier; + }; + + const isTableItemInSearch: IsItemInSearchCallback = (item, searchValue) => { + const results = tokenizedSearch([item], searchValue, (option) => [option.displayName, option.login]); + return results.length > 0; + }; + + const renderTableItem = ({item, index}: ListRenderItemInfo) => ( + + ); + + return ( + item.keyForList} + > + + + +
+ ); +} + +export type {AgentRowData, AgentsTableColumnKey}; diff --git a/src/languages/de.ts b/src/languages/de.ts index 975d5ec6bf8f..b82fa4411ed5 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -2877,6 +2877,7 @@ ${amount} für ${merchant} – ${date}`, agentsPage: { title: 'Agenten', subtitle: `Agents übernehmen Ihre Workflows für Sie, sodass Sie täglich Stunden zurückgewinnen. Mehr erfahren.`, + findAgent: 'Agent suchen', newAgent: 'Neue:r Agent:in', emptyAgents: { title: 'Keine Agenten erstellt', diff --git a/src/languages/en.ts b/src/languages/en.ts index 331389ba9e0f..2cad4f433561 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2947,6 +2947,7 @@ const translations = { agentsPage: { title: 'Agents', subtitle: `Agents handle your workflows for you, so you get hours back in your day. Learn more.`, + findAgent: 'Find agent', newAgent: 'New agent', emptyAgents: { title: 'No agents created', diff --git a/src/languages/es.ts b/src/languages/es.ts index 96c84173b331..b3e8ece2d11f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2739,6 +2739,7 @@ ${amount} para ${merchant} - ${date}`, agentsPage: { title: 'Agentes', subtitle: `Los agentes gestionan tus flujos de trabajo por ti, para que recuperes horas en tu día. Más información.`, + findAgent: 'Buscar agente', newAgent: 'Nuevo agente', emptyAgents: { title: 'No se han creado agentes.', diff --git a/src/languages/fr.ts b/src/languages/fr.ts index 6470ef2fdd08..73b6c1cfc253 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -2884,6 +2884,7 @@ ${amount} pour ${merchant} - ${date}`, agentsPage: { title: 'Agents', subtitle: `Les agents gèrent vos workflows pour vous, afin que vous gagniez des heures dans votre journée. En savoir plus.`, + findAgent: 'Trouver un agent', newAgent: 'Nouvel agent', emptyAgents: { title: 'Aucun agent créé', diff --git a/src/languages/it.ts b/src/languages/it.ts index e79f68bd609f..35a7e1614e9e 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -2872,6 +2872,7 @@ ${amount} per ${merchant} - ${date}`, agentsPage: { title: 'Agenti', subtitle: `Gli agenti gestiscono i tuoi flussi di lavoro al posto tuo, così ti ritrovi ore in più nella tua giornata. Scopri di più.`, + findAgent: 'Trova agente', newAgent: 'Nuovo agente', emptyAgents: { title: 'Nessun agente creato', diff --git a/src/languages/ja.ts b/src/languages/ja.ts index 5cccad520a33..162cd8f77d73 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -2841,6 +2841,7 @@ ${date} の ${merchant} への ${amount}`, agentsPage: { title: '担当者', subtitle: `エージェントがワークフローを代わりに処理するので、毎日の時間を数時間取り戻せます。詳しく見る。`, + findAgent: '担当者を探す', newAgent: '新しいエージェント', emptyAgents: { title: 'エージェントは作成されていません', diff --git a/src/languages/nl.ts b/src/languages/nl.ts index 357903be3873..cc2614f50b66 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -2870,6 +2870,7 @@ ${amount} voor ${merchant} - ${date}`, agentsPage: { title: 'Agenten', subtitle: `Agents verwerken je workflows voor je, zodat je uren per dag terugkrijgt. Meer informatie.`, + findAgent: 'Agent zoeken', newAgent: 'Nieuwe medewerker', emptyAgents: { title: 'Geen agents aangemaakt', diff --git a/src/languages/pl.ts b/src/languages/pl.ts index 8868677f7579..5047157b793b 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -2857,6 +2857,7 @@ ${amount} dla ${merchant} - ${date}`, agentsPage: { title: 'Agenci', subtitle: `Agenci obsługują za ciebie twoje procesy, dzięki czemu odzyskujesz godziny w ciągu dnia. Dowiedz się więcej.`, + findAgent: 'Znajdź agenta', newAgent: 'Nowy agent', emptyAgents: { title: 'Nie utworzono agentów', diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index 95ac54b199e6..4bdb07b5c4b7 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -2860,6 +2860,7 @@ ${amount} para ${merchant} - ${date}`, agentsPage: { title: 'Agentes', subtitle: `Agentes cuidam dos seus fluxos de trabalho para você, para que você ganhe horas de volta no seu dia. Saiba mais.`, + findAgent: 'Encontrar agente', newAgent: 'Novo agente', emptyAgents: { title: 'Nenhum agente criado', diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 382087377f50..21988f13d97d 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -2773,6 +2773,7 @@ ${amount},商户:${merchant} - 日期:${date}`, agentsPage: { title: '代理人', subtitle: `智能代理为你处理工作流程,让你每天多出数小时。了解详情。`, + findAgent: '查找代理', newAgent: '新代理人', emptyAgents: { title: '尚未创建代理', diff --git a/src/pages/settings/Agents/AgentInfoRow.tsx b/src/pages/settings/Agents/AgentInfoRow.tsx deleted file mode 100644 index 1aa718fac224..000000000000 --- a/src/pages/settings/Agents/AgentInfoRow.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import ReportActionAvatars from '@components/ReportActionAvatars'; -import Text from '@components/Text'; - -import useStyleUtils from '@hooks/useStyleUtils'; -import useThemeStyles from '@hooks/useThemeStyles'; - -import variables from '@styles/variables'; - -import CONST from '@src/CONST'; - -import React from 'react'; -import {View} from 'react-native'; - -type AgentInfoRowProps = { - /** Account ID of the agent */ - accountID: number; - - /** Display name of the agent */ - displayName: string; - - /** Login (email) of the agent */ - login: string; - - /** Whether the agent is pending deletion */ - isPendingDeletion?: boolean; -}; - -function AgentInfoRow({accountID, displayName, login, isPendingDeletion = false}: AgentInfoRowProps) { - const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - - return ( - <> - - - - {displayName} - - - {login} - - - - ); -} - -export default AgentInfoRow; diff --git a/src/pages/settings/Agents/AgentsListRow.tsx b/src/pages/settings/Agents/AgentsListRow.tsx deleted file mode 100644 index 9777c601fbde..000000000000 --- a/src/pages/settings/Agents/AgentsListRow.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import Button from '@components/Button'; -import Icon from '@components/Icon'; -import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; - -import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; -import useLocalize from '@hooks/useLocalize'; -import useResponsiveLayout from '@hooks/useResponsiveLayout'; -import useTheme from '@hooks/useTheme'; -import useThemeStyles from '@hooks/useThemeStyles'; - -import Navigation from '@libs/Navigation/Navigation'; - -import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; -import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon'; - -import React from 'react'; -import {View} from 'react-native'; - -import AgentInfoRow from './AgentInfoRow'; - -type AgentsListRowProps = { - /** Account ID of the agent */ - accountID: number; - - /** Display name of the agent */ - displayName: string; - - /** Login email of the agent */ - login: string; - - /** Pending action for offline feedback */ - pendingAction?: PendingAction | null; - - /** Errors to display on the row */ - errors?: Errors | null; - - /** Called when the user dismisses the error */ - onErrorClose?: () => void; - - /** Whether to show the red error dot indicator */ - brickRoadIndicator?: typeof CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR | null; - - /** Called when the Chat button is pressed */ - onChatPress?: (accountID: number) => void; - - /** Called when the Copilot button is pressed */ - onCopilotPress?: (login: string) => void; -}; - -function AgentsListRow({accountID, displayName, login, pendingAction, errors, onErrorClose, brickRoadIndicator, onChatPress, onCopilotPress}: AgentsListRowProps) { - const styles = useThemeStyles(); - const theme = useTheme(); - const {translate} = useLocalize(); - const {shouldUseNarrowLayout} = useResponsiveLayout(); - const icons = useMemoizedLazyExpensifyIcons(['DotIndicator', 'ChatBubble']); - - const isPendingDeletion = pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - const isPendingAddOrDelete = pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || isPendingDeletion; - const areActionsDisabled = isPendingAddOrDelete || accountID <= 0 || !login; - const navigateToEdit = () => Navigation.navigate(ROUTES.SETTINGS_AGENTS_EDIT.getRoute(accountID)); - const handleChatPress = () => { - onChatPress?.(accountID); - }; - const handleCopilotPress = () => { - onCopilotPress?.(login); - }; - - return ( - - {shouldUseNarrowLayout ? ( - - - {!!brickRoadIndicator && ( - - )} - - ) : ( - - - {!!brickRoadIndicator && ( - - )} -