The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Introduced Specific Icons image identifier for Notes and Tasks (#6997)
nitinfcaa9d9aed62
diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useGetStandardObjectIcon.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useGetStandardObjectIcon.tsnew file mode 100644index 00000000000..92b014d730a--- /dev/null+++ b/packages/twenty-front/src/modules/object-metadata/hooks/useGetStandardObjectIcon.ts@@ -0,0 +1,37 @@+import { useTheme } from '@emotion/react';+import { IconCheckbox, IconComponent, IconNotes } from 'twenty-ui';++export const useGetStandardObjectIcon = (objectNameSingular: string) => {+ const theme = useTheme();++ const getIconForObjectType = (+ objectType: string,+ ): IconComponent | undefined => {+ switch (objectType) {+ case 'note':+ return IconNotes;+ case 'task':+ return IconCheckbox;+ default:+ return undefined;+ }+ };++ const getIconColorForObjectType = (objectType: string): string => {+ switch (objectType) {+ case 'note':+ return theme.color.yellow;+ case 'task':+ return theme.color.blue;+ default:+ return 'currentColor';+ }+ };++ const { Icon, IconColor } = {+ Icon: getIconForObjectType(objectNameSingular),+ IconColor: getIconColorForObjectType(objectNameSingular),+ };++ return { Icon, IconColor };+};diff --git a/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexRecordChip.tsx b/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexRecordChip.tsxindex 959d09b8ca3..8e84fa83325 100644--- a/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexRecordChip.tsx+++ b/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexRecordChip.tsx@@ -1,9 +1,9 @@-import { AvatarChip, AvatarChipVariant } from 'twenty-ui';-+import { useGetStandardObjectIcon } from '@/object-metadata/hooks/useGetStandardObjectIcon';import { useRecordChipData } from '@/object-record/hooks/useRecordChipData';import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';import { ObjectRecord } from '@/object-record/types/ObjectRecord';import { useContext } from 'react';+import { AvatarChip, AvatarChipVariant } from 'twenty-ui';export type RecordIdentifierChipProps = {objectNameSingular: string;@@ -17,7 +17,6 @@ export const RecordIdentifierChip = ({variant,}: RecordIdentifierChipProps) => {const { onIndexIdentifierClick } = useContext(RecordIndexRootPropsContext);-const { recordChipData } = useRecordChipData({objectNameSingular,record,@@ -27,6 +26,8 @@ export const RecordIdentifierChip = ({onIndexIdentifierClick(record.id);};+ const { Icon: LeftIcon, IconColor: LeftIconColor } =+ useGetStandardObjectIcon(objectNameSingular);return (<AvatarChipplaceholderColorSeed={record.id}@@ -35,6 +36,8 @@ export const RecordIdentifierChip = ({avatarUrl={recordChipData.avatarUrl ?? ''}onClick={handleAvatarChipClick}variant={variant}+ LeftIcon={LeftIcon}+ LeftIconColor={LeftIconColor}/>);};diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsxindex 4829831086e..967825f3a5d 100644--- a/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx+++ b/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx@@ -5,6 +5,7 @@ import { ActivityTargetsInlineCell } from '@/activities/inline-cell/components/Aimport { Note } from '@/activities/types/Note';import { Task } from '@/activities/types/Task';import { InformationBannerDeletedRecord } from '@/information-banner/components/deleted-record/InformationBannerDeletedRecord';+import { useGetStandardObjectIcon } from '@/object-metadata/hooks/useGetStandardObjectIcon';import { useLabelIdentifierFieldMetadataItem } from '@/object-metadata/hooks/useLabelIdentifierFieldMetadataItem';import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';@@ -156,7 +157,7 @@ export const RecordShowContainer = ({objectNameSingular !== CoreObjectNameSingular.Task &&fieldMetadataItem.name !== 'taskTargets',);-+ const { Icon, IconColor } = useGetStandardObjectIcon(objectNameSingular);const isReadOnly = objectMetadataItem.isRemote;const isMobile = useIsMobile() || isInRightDrawer;const isPrefetchLoading = useIsPrefetchLoading();@@ -166,6 +167,8 @@ export const RecordShowContainer = ({isMobile={isMobile}id={objectRecordId}logoOrAvatar={recordIdentifier?.avatarUrl ?? ''}+ icon={Icon}+ iconColor={IconColor}avatarPlaceholder={recordIdentifier?.name ?? ''}date={recordFromStore.createdAt ?? ''}loading={isPrefetchLoading || loading || recordLoading}diff --git a/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSummaryCard.tsx b/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSummaryCard.tsxindex 3d228d5bd79..137bad6002c 100644--- a/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSummaryCard.tsx+++ b/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSummaryCard.tsx@@ -2,7 +2,7 @@ import { useTheme } from '@emotion/react';import styled from '@emotion/styled';import { ChangeEvent, ReactNode, useRef } from 'react';import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';-import { AppTooltip, Avatar, AvatarType } from 'twenty-ui';+import { AppTooltip, Avatar, AvatarType, IconComponent } from 'twenty-ui';import { v4 as uuidV4 } from 'uuid';import {@@ -17,6 +17,8 @@ type ShowPageSummaryCardProps = {date: string;id?: string;logoOrAvatar?: string;+ icon?: IconComponent;+ iconColor?: string;onUploadPicture?: (file: File) => void;title: ReactNode;loading: boolean;@@ -99,6 +101,8 @@ export const ShowPageSummaryCard = ({date,id,logoOrAvatar,+ icon,+ iconColor,onUploadPicture,title,loading,@@ -133,7 +137,9 @@ export const ShowPageSummaryCard = ({size="xl"placeholderColorSeed={id}placeholder={avatarPlaceholder}- type={avatarType}+ type={icon ? 'icon' : avatarType}+ Icon={icon}+ iconColor={iconColor}/><StyledFileInputref={inputFileRef}diff --git a/packages/twenty-ui/src/display/avatar/components/Avatar.tsx b/packages/twenty-ui/src/display/avatar/components/Avatar.tsxindex 81c3a80219a..5230e67ce07 100644--- a/packages/twenty-ui/src/display/avatar/components/Avatar.tsx+++ b/packages/twenty-ui/src/display/avatar/components/Avatar.tsx@@ -7,6 +7,7 @@ import { invalidAvatarUrlsState } from '@ui/display/avatar/components/states/isIimport { AVATAR_PROPERTIES_BY_SIZE } from '@ui/display/avatar/constants/AvatarPropertiesBySize';import { AvatarSize } from '@ui/display/avatar/types/AvatarSize';import { AvatarType } from '@ui/display/avatar/types/AvatarType';+import { IconComponent } from '@ui/display/icon/types/IconComponent';import { ThemeContext } from '@ui/theme';import { Nullable, getImageAbsoluteURI, stringToHslColor } from '@ui/utilities';@@ -17,13 +18,16 @@ const StyledAvatar = styled.div<{color: string;backgroundColor: string;backgroundTransparentLight: string;+ type?: Nullable<AvatarType>;}>`align-items: center;flex-shrink: 0;overflow: hidden;user-select: none;- border-radius: ${({ rounded }) => (rounded ? '50%' : '2px')};+ border-radius: ${({ rounded, type }) => {+ return rounded ? '50%' : type === 'icon' ? '4px' : '2px';+ }};display: flex;font-size: ${({ size }) => AVATAR_PROPERTIES_BY_SIZE[size].fontSize};height: ${({ size }) => AVATAR_PROPERTIES_BY_SIZE[size].width};@@ -51,6 +55,8 @@ export type AvatarProps = {size?: AvatarSize;placeholder: string | undefined;placeholderColorSeed?: string;+ Icon?: IconComponent;+ iconColor?: string;type?: Nullable<AvatarType>;color?: string;backgroundColor?: string;@@ -63,6 +69,8 @@ export const Avatar = ({size = 'md',placeholder,placeholderColorSeed = placeholder,+ Icon,+ iconColor,onClick,type = 'squared',color,@@ -101,14 +109,26 @@ export const Avatar = ({return (<StyledAvatarsize={size}- backgroundColor={showBackgroundColor ? fixedBackgroundColor : 'none'}+ backgroundColor={+ Icon+ ? theme.background.tertiary+ : showBackgroundColor+ ? fixedBackgroundColor+ : 'none'+ }color={fixedColor}clickable={!isUndefined(onClick)}rounded={type === 'rounded'}+ type={type}onClick={onClick}backgroundTransparentLight={theme.background.transparent.light}>- {showPlaceholder ? (+ {Icon ? (+ <Icon+ color={iconColor ? iconColor : 'currentColor'}+ size={theme.icon.size.xl}+ />+ ) : showPlaceholder ? (placeholderChar) : (<StyledImage src={avatarImageURI} onError={handleImageError} alt="" />diff --git a/packages/twenty-ui/src/display/avatar/types/AvatarType.ts b/packages/twenty-ui/src/display/avatar/types/AvatarType.tsindex 9e9b7dc9589..e267555111d 100644--- a/packages/twenty-ui/src/display/avatar/types/AvatarType.ts+++ b/packages/twenty-ui/src/display/avatar/types/AvatarType.ts@@ -1 +1 @@-export type AvatarType = 'squared' | 'rounded';+export type AvatarType = 'squared' | 'rounded' | 'icon';diff --git a/packages/twenty-ui/src/display/chip/components/AvatarChip.tsx b/packages/twenty-ui/src/display/chip/components/AvatarChip.tsxindex 2c993ba652d..72b0253eed8 100644--- a/packages/twenty-ui/src/display/chip/components/AvatarChip.tsx+++ b/packages/twenty-ui/src/display/chip/components/AvatarChip.tsx@@ -14,6 +14,7 @@ export type AvatarChipProps = {avatarType?: Nullable<AvatarType>;variant?: AvatarChipVariant;LeftIcon?: IconComponent;+ LeftIconColor?: string;isIconInverted?: boolean;className?: string;placeholderColorSeed?: string;@@ -41,6 +42,7 @@ export const AvatarChip = ({avatarType = 'rounded',variant = AvatarChipVariant.Regular,LeftIcon,+ LeftIconColor,isIconInverted,className,placeholderColorSeed,@@ -71,7 +73,11 @@ export const AvatarChip = ({/></StyledInvertedIconContainer>) : (- <LeftIcon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />+ <LeftIcon+ size={theme.icon.size.md}+ stroke={theme.icon.stroke.sm}+ color={LeftIconColor || 'currentColor'}+ />)) : (<Avatar