From 7551720f857f9bd22ee75afda5ad537c5d878ce5 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Mon, 25 Mar 2024 18:10:03 +0100 Subject: [PATCH] improve typing using generics --- ...ttingsAccountsCalendarAccountsListCard.tsx | 4 +- ...ttingsAccountsConnectedAccountsSection.tsx | 2 +- ...SettingsAccountsEmailsAccountsListCard.tsx | 4 +- .../components/SettingsAccountsListCard.tsx | 46 ++++++++----------- .../SettingsAccountsRowDropdownMenu.tsx | 4 +- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsCalendarAccountsListCard.tsx b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsCalendarAccountsListCard.tsx index 448cab5961ef..fc5bdbac0825 100644 --- a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsCalendarAccountsListCard.tsx +++ b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsCalendarAccountsListCard.tsx @@ -45,13 +45,13 @@ export const SettingsAccountsCalendarAccountsListCard = () => { return ( navigate(`/settings/accounts/calendars/${calendarChannel.id}`) } RowIcon={IconGoogleCalendar} - RowRightComponent={({ accountOrChannel: calendarChannel }) => ( + RowRightComponent={({ item: calendarChannel }) => ( { return ( navigate(`/settings/accounts/emails/${messageChannel.id}`) } RowIcon={IconGmail} - RowRightComponent={({ accountOrChannel: messageChannel }) => ( + RowRightComponent={({ item: messageChannel }) => ( , -> = { - accountsOrChannels: AccountOrChannel[]; +type ItemType = { + handle: string; + id: string; +}; + +type SettingsAccountsListCardProps = { + items: T[]; hasFooter?: boolean; isLoading?: boolean; - onRowClick?: (accountOrChannel: AccountOrChannel) => void; + onRowClick?: (item: T) => void; RowIcon?: IconComponent; - RowRightComponent: ComponentType<{ accountOrChannel: AccountOrChannel }>; + RowRightComponent: ComponentType<{ item: T }>; }; -export const SettingsAccountsListCard = < - Account extends Pick< - ConnectedAccount | CalendarChannel | MessageChannel, - 'handle' | 'id' - >, ->({ - accountsOrChannels, +export const SettingsAccountsListCard = ({ + items, hasFooter, isLoading, onRowClick, RowIcon = IconGoogle, RowRightComponent, -}: SettingsAccountsListCardProps) => { +}: SettingsAccountsListCardProps) => { const theme = useTheme(); const navigate = useNavigate(); if (isLoading === true) return ; - if (!accountsOrChannels.length) return ; + if (!items.length) return ; return ( - {accountsOrChannels.map((account, index) => ( + {items.map((item, index) => ( } - divider={index < accountsOrChannels.length - 1} - onClick={() => onRowClick?.(account)} + account={item} + rightComponent={} + divider={index < items.length - 1} + onClick={() => onRowClick?.(item)} /> ))} {hasFooter && ( diff --git a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRowDropdownMenu.tsx b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRowDropdownMenu.tsx index 07520d07a3e3..d68ec50c0f61 100644 --- a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRowDropdownMenu.tsx +++ b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRowDropdownMenu.tsx @@ -12,12 +12,12 @@ import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown'; import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem'; type SettingsAccountsRowDropdownMenuProps = { - accountOrChannel: Pick; + item: Pick; className?: string; }; export const SettingsAccountsRowDropdownMenu = ({ - accountOrChannel: account, + item: account, className, }: SettingsAccountsRowDropdownMenuProps) => { const dropdownId = `settings-account-row-${account.id}`;