Skip to content

The open alternative to Salesforce, designed for AI.

[Onboarding 8/8] Stabilize avatar colors (#26785)

Thomas des Francsb6b3ca76971a
diff --git a/packages/twenty-front/src/modules/auth/components/Logo.tsx b/packages/twenty-front/src/modules/auth/components/Logo.tsx
index 8d55e565f5f..984706ea5cf 100644
--- a/packages/twenty-front/src/modules/auth/components/Logo.tsx
+++ b/packages/twenty-front/src/modules/auth/components/Logo.tsx
@@ -1,4 +1,5 @@
import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink/UndecoratedLink';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { styled } from '@linaria/react';
import { isNonEmptyString } from '@sniptt/guards';
import { AppPath } from 'twenty-shared/types';
@@ -99,7 +100,7 @@ export const Logo = ({
size="lg"
name={placeholder}
shape="square"
- colorSeed={placeholder}
+ colorSeed={getWorkspaceAvatarColorSeed(placeholder)}
/>
</StyledSecondaryLogoContainer>
)
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx
index 80f8ab6aa82..c9a14cd8e96 100644
--- a/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx
@@ -25,6 +25,7 @@ import { OnboardingStepAnimatedItem } from '@/onboarding/components/OnboardingSt
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { isNonEmptyString } from '@sniptt/guards';
import { IconChevronRight, IconPlus } from 'twenty-ui/icon';
import { Avatar } from 'twenty-ui/primitives/data-display';
@@ -179,6 +180,9 @@ export const SignInUpGlobalScopeForm = () => {
<StyledWorkspaceContent>
<Avatar
name={availableWorkspace.displayName || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ availableWorkspace.displayName,
+ )}
src={getAbsoluteImageUrl(
availableWorkspace.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpWorkspaceCreationForm.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpWorkspaceCreationForm.tsx
index abc7d9a5bfd..0e73a61db8f 100644
--- a/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpWorkspaceCreationForm.tsx
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpWorkspaceCreationForm.tsx
@@ -9,6 +9,7 @@ import { ONBOARDING_CONTENT_BLOCK_WIDTH } from '@/onboarding/constants/Onboardin
import { TextInput } from '@/ui/input/components/TextInput';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { isNonEmptyString } from '@sniptt/guards';
@@ -253,7 +254,7 @@ export const SignInUpWorkspaceCreationForm = () => {
<StyledLogoAvatar
src={logoPreviewUrl}
name={isNonEmptyString(workspaceName) ? workspaceName : '?'}
- colorSeed={workspaceName}
+ colorSeed={getWorkspaceAvatarColorSeed(workspaceName)}
shape="square"
size="xl"
onClick={openFilePicker}
diff --git a/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemWorkspaceSectionContext.tsx b/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemWorkspaceSectionContext.tsx
index c73571cb7f5..7c47fb14110 100644
--- a/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemWorkspaceSectionContext.tsx
+++ b/packages/twenty-front/src/modules/command-menu-item/display/hooks/useCommandMenuItemWorkspaceSectionContext.tsx
@@ -5,6 +5,7 @@ import { type CommandMenuItemSectionContext } from '@/command-menu-item/types/Co
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
export const useCommandMenuItemWorkspaceSectionContext =
(): CommandMenuItemSectionContext => {
@@ -15,6 +16,7 @@ export const useCommandMenuItemWorkspaceSectionContext =
<Avatar
size="md"
name={currentWorkspace?.displayName ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(currentWorkspace?.displayName)}
src={getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
index ad426d8c109..cdb85ebae31 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
@@ -8,6 +8,7 @@ import { type UsageLimitRow } from '@/settings/billing/types/UsageLimitRow';
import { isKeyOfRecord } from '@/settings/billing/utils/isKeyOfRecord';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
const StyledContainer = styled.div`
@@ -54,6 +55,7 @@ export const SettingsBillingLimitSpenderCell = ({
return (
<Avatar
name={name}
+ colorSeed={getWorkspaceAvatarColorSeed(name)}
src={getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
index 9de84ab340d..4cd18d2b8e1 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
@@ -11,6 +11,7 @@ import { getUsageLimitSpenderGroups } from '@/settings/billing/utils/getUsageLim
import { SelectOptionIcon } from '@/ui/input/components/SelectOptionIcon';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useLingui } from '@lingui/react/macro';
import { isDefined } from 'twenty-shared/utils';
import { Dropdown } from 'twenty-ui/components';
@@ -56,6 +57,7 @@ export const SettingsBillingLimitSpenderSelect = ({
const workspaceAvatarUrl = getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
);
+ const workspaceAvatarColorSeed = getWorkspaceAvatarColorSeed(workspaceName);
const handleSelect = (
nextSpenderType: UsageLimitSpenderType,
@@ -88,6 +90,7 @@ export const SettingsBillingLimitSpenderSelect = ({
return (
<Avatar
name={workspaceName}
+ colorSeed={workspaceAvatarColorSeed}
src={workspaceAvatarUrl}
shape="square"
size="md"
@@ -146,6 +149,7 @@ export const SettingsBillingLimitSpenderSelect = ({
startIcon={
<Avatar
name={workspaceName}
+ colorSeed={workspaceAvatarColorSeed}
src={workspaceAvatarUrl}
shape="square"
size="md"
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownClickableComponent.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownClickableComponent.tsx
index bb86d6c017a..24e1ba0c841 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownClickableComponent.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownClickableComponent.tsx
@@ -9,6 +9,7 @@ import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigat
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useIsNavigationDrawerContentExpanded } from '@/navigation/hooks/useIsNavigationDrawerContentExpanded';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
import { Avatar } from 'twenty-ui/primitives/data-display';
import { useTheme } from 'twenty-ui/theme';
@@ -34,6 +35,7 @@ export const MultiWorkspaceDropdownClickableComponent = ({
>
<Avatar
name={currentWorkspace?.displayName || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(currentWorkspace?.displayName)}
src={getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownDefaultComponents.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownDefaultComponents.tsx
index 8a7d40616c9..c9575c14a53 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownDefaultComponents.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownDefaultComponents.tsx
@@ -24,6 +24,7 @@ import { multiWorkspaceDropdownState } from '@/ui/navigation/navigation-drawer/s
import { useColorScheme } from '@/ui/theme/hooks/useColorScheme';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useLingui } from '@lingui/react/macro';
import { isNonEmptyString } from '@sniptt/guards';
import { AppPath, SettingsPath } from 'twenty-shared/types';
@@ -107,6 +108,9 @@ export const MultiWorkspaceDropdownDefaultComponents = () => {
Avatar={
<Avatar
name={currentWorkspace?.displayName || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ currentWorkspace?.displayName,
+ )}
src={getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
@@ -175,6 +179,9 @@ export const MultiWorkspaceDropdownDefaultComponents = () => {
startIcon={
<Avatar
name={availableWorkspace.displayName || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ availableWorkspace.displayName,
+ )}
src={getAbsoluteImageUrl(
availableWorkspace.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/components/AvailableWorkspaceItem.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/components/AvailableWorkspaceItem.tsx
index ac0db3aea98..17274662057 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/components/AvailableWorkspaceItem.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/components/AvailableWorkspaceItem.tsx
@@ -3,6 +3,7 @@ import { useBuildWorkspaceUrl } from '@/domain-manager/hooks/useBuildWorkspaceUr
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink/UndecoratedLink';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { t } from '@lingui/core/macro';
import { Avatar } from 'twenty-ui/primitives/data-display';
import { ListItem } from 'twenty-ui/primitives/navigation';
@@ -53,6 +54,9 @@ export const AvailableWorkspaceItem = ({
startIcon={
<Avatar
name={availableWorkspace.displayName || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ availableWorkspace.displayName,
+ )}
src={getAbsoluteImageUrl(
availableWorkspace.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts b/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts
new file mode 100644
index 00000000000..1b89d1fce95
--- /dev/null
+++ b/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts
@@ -0,0 +1,15 @@
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
+
+describe('getWorkspaceAvatarColorSeed', () => {
+ it('should keep the same seed while the name is being typed', () => {
+ expect(getWorkspaceAvatarColorSeed('w')).toBe('W');
+ expect(getWorkspaceAvatarColorSeed('worksp')).toBe('W');
+ expect(getWorkspaceAvatarColorSeed(' Workspace')).toBe('W');
+ });
+
+ it('should return an empty seed when there is no name', () => {
+ expect(getWorkspaceAvatarColorSeed('')).toBe('');
+ expect(getWorkspaceAvatarColorSeed(null)).toBe('');
+ expect(getWorkspaceAvatarColorSeed(undefined)).toBe('');
+ });
+});
diff --git a/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts b/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts
new file mode 100644
index 00000000000..f81f770110a
--- /dev/null
+++ b/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts
@@ -0,0 +1,5 @@
+export const getWorkspaceAvatarColorSeed = (
+ workspaceDisplayName: string | null | undefined,
+): string => {
+ return (workspaceDisplayName ?? '').trim().charAt(0).toUpperCase();
+};