The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat: colored avatar (#554)
Jérémy M3079747c83d9
diff --git a/front/src/modules/comments/components/comment-thread/CommentThreadRelationPicker.tsx b/front/src/modules/comments/components/comment-thread/CommentThreadRelationPicker.tsxindex 3c465d006bf..4eb6233014f 100644--- a/front/src/modules/comments/components/comment-thread/CommentThreadRelationPicker.tsx+++ b/front/src/modules/comments/components/comment-thread/CommentThreadRelationPicker.tsx@@ -10,7 +10,7 @@ import {import { useHandleCheckableCommentThreadTargetChange } from '@/comments/hooks/useHandleCheckableCommentThreadTargetChange';import { CommentableEntityForSelect } from '@/comments/types/CommentableEntityForSelect';-import CompanyChip from '@/companies/components/CompanyChip';+import { CompanyChip } from '@/companies/components/CompanyChip';import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';import { PersonChip } from '@/people/components/PersonChip';diff --git a/front/src/modules/comments/components/comment/CommentHeader.tsx b/front/src/modules/comments/components/comment/CommentHeader.tsxindex 3de95b834d3..c856f8126de 100644--- a/front/src/modules/comments/components/comment/CommentHeader.tsx+++ b/front/src/modules/comments/components/comment/CommentHeader.tsx@@ -8,7 +8,6 @@ import {beautifyExactDate,beautifyPastDateRelativeToNow,} from '@/utils/datetime/date-utils';-import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';type OwnProps = {comment: Pick<CommentForDrawer, 'id' | 'author' | 'createdAt'>;@@ -74,17 +73,14 @@ export function CommentHeader({ comment, actionBar }: OwnProps) {const avatarUrl = author.avatarUrl;const commentId = comment.id;- const capitalizedFirstUsernameLetter = isNonEmptyString(authorName)- ? authorName.toLocaleUpperCase()[0]- : '';-return (<StyledContainer><StyledLeftContainer><AvataravatarUrl={avatarUrl}size={theme.icon.size.md}- placeholder={capitalizedFirstUsernameLetter}+ colorId={author.id}+ placeholder={author.displayName}/><StyledName>{authorName}</StyledName>{showDate && (diff --git a/front/src/modules/companies/components/CompanyAccountOwnerCell.tsx b/front/src/modules/companies/components/CompanyAccountOwnerCell.tsxindex 2dbf0b1fff2..51a07641ad5 100644--- a/front/src/modules/companies/components/CompanyAccountOwnerCell.tsx+++ b/front/src/modules/companies/components/CompanyAccountOwnerCell.tsx@@ -16,7 +16,10 @@ export function CompanyAccountOwnerCell({ company }: OwnProps) {editModeContent={<CompanyAccountOwnerPicker company={company} />}nonEditModeContent={company.accountOwner?.displayName ? (- <PersonChip name={company.accountOwner?.displayName ?? ''} />+ <PersonChip+ id={company.accountOwner.id}+ name={company.accountOwner?.displayName ?? ''}+ />) : (<></>)diff --git a/front/src/modules/companies/components/CompanyChip.tsx b/front/src/modules/companies/components/CompanyChip.tsxindex 91e3cf94f88..73610d72610 100644--- a/front/src/modules/companies/components/CompanyChip.tsx+++ b/front/src/modules/companies/components/CompanyChip.tsx@@ -5,7 +5,7 @@ import styled from '@emotion/styled';import { Avatar } from '@/users/components/Avatar';export type CompanyChipPropsType = {- id?: string;+ id: string;name: string;picture?: string;};@@ -50,7 +50,7 @@ const StyledContainerNoLink = styled.div`${baseStyle}`;-function CompanyChip({ id, name, picture }: CompanyChipPropsType) {+export function CompanyChip({ id, name, picture }: CompanyChipPropsType) {const ContainerComponent = id ? StyledContainerLink : StyledContainerNoLink;return (@@ -58,6 +58,7 @@ function CompanyChip({ id, name, picture }: CompanyChipPropsType) {{picture && (<AvataravatarUrl={picture?.toString()}+ colorId={id}placeholder={name}type="squared"size={14}@@ -67,5 +68,3 @@ function CompanyChip({ id, name, picture }: CompanyChipPropsType) {</ContainerComponent>);}--export default CompanyChip;diff --git a/front/src/modules/companies/components/CompanyEditableNameCell.tsx b/front/src/modules/companies/components/CompanyEditableNameCell.tsxindex 12d888ba768..94047aa6ef1 100644--- a/front/src/modules/companies/components/CompanyEditableNameCell.tsx+++ b/front/src/modules/companies/components/CompanyEditableNameCell.tsx@@ -8,7 +8,7 @@ import {useUpdateCompanyMutation,} from '~/generated/graphql';-import CompanyChip from './CompanyChip';+import { CompanyChip } from './CompanyChip';type OwnProps = {company: Pick<diff --git a/front/src/modules/companies/components/__stories__/CompanyChip.stories.tsx b/front/src/modules/companies/components/__stories__/CompanyChip.stories.tsxindex 54c37f3dde6..119682e990c 100644--- a/front/src/modules/companies/components/__stories__/CompanyChip.stories.tsx+++ b/front/src/modules/companies/components/__stories__/CompanyChip.stories.tsx@@ -1,9 +1,10 @@+import { BrowserRouter } from 'react-router-dom';import styled from '@emotion/styled';import type { Meta, StoryObj } from '@storybook/react';import { getRenderWrapperForComponent } from '~/testing/renderWrappers';-import CompanyChip from '../CompanyChip';+import { CompanyChip } from '../CompanyChip';const meta: Meta<typeof CompanyChip> = {title: 'Modules/Companies/CompanyChip',@@ -32,10 +33,13 @@ const TestCellContainer = styled.div`export const SmallName: Story = {render: getRenderWrapperForComponent(<TestCellContainer>- <CompanyChip- name="Airbnb"- picture="https://api.faviconkit.com/airbnb.com/144"- />+ <BrowserRouter>+ <CompanyChip+ id="airbnb"+ name="Airbnb"+ picture="https://api.faviconkit.com/airbnb.com/144"+ />+ </BrowserRouter></TestCellContainer>,),};@@ -43,10 +47,13 @@ export const SmallName: Story = {export const BigName: Story = {render: getRenderWrapperForComponent(<TestCellContainer>- <CompanyChip- name="Google with a real big name to overflow the cell"- picture="https://api.faviconkit.com/google.com/144"- />+ <BrowserRouter>+ <CompanyChip+ id="google"+ name="Google with a real big name to overflow the cell"+ picture="https://api.faviconkit.com/google.com/144"+ />+ </BrowserRouter></TestCellContainer>,),};diff --git a/front/src/modules/people/components/PeopleCompanyCell.tsx b/front/src/modules/people/components/PeopleCompanyCell.tsxindex 4df2f160296..1b90c62edc1 100644--- a/front/src/modules/people/components/PeopleCompanyCell.tsx+++ b/front/src/modules/people/components/PeopleCompanyCell.tsx@@ -1,4 +1,4 @@-import CompanyChip from '@/companies/components/CompanyChip';+import { CompanyChip } from '@/companies/components/CompanyChip';import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';import { useRecoilScopedState } from '@/recoil-scope/hooks/useRecoilScopedState';import { EditableCell } from '@/ui/components/editable-cell/EditableCell';diff --git a/front/src/modules/people/components/PersonChip.tsx b/front/src/modules/people/components/PersonChip.tsxindex e7b656cebb1..012bb145a30 100644--- a/front/src/modules/people/components/PersonChip.tsx+++ b/front/src/modules/people/components/PersonChip.tsx@@ -3,10 +3,10 @@ import { Link } from 'react-router-dom';import { Theme } from '@emotion/react';import styled from '@emotion/styled';-import PersonPlaceholder from './person-placeholder.png';+import { Avatar } from '@/users/components/Avatar';export type PersonChipPropsType = {- id?: string;+ id: string;name: string;picture?: string;};@@ -52,10 +52,12 @@ export function PersonChip({ id, name, picture }: PersonChipPropsType) {const ContainerComponent = id ? StyledContainerLink : StyledContainerNoLink;return (<ContainerComponent data-testid="person-chip" to={`/person/${id}`}>- <img- data-testid="person-chip-image"- src={picture ? picture.toString() : PersonPlaceholder.toString()}- alt="person"+ <Avatar+ avatarUrl={picture}+ colorId={id}+ placeholder={name}+ size={14}+ type="rounded"/><StyledName>{name}</StyledName></ContainerComponent>diff --git a/front/src/modules/people/components/__stories__/PeopleChip.stories.tsx b/front/src/modules/people/components/__stories__/PeopleChip.stories.tsxnew file mode 100644index 00000000000..b3ca5a646d2--- /dev/null+++ b/front/src/modules/people/components/__stories__/PeopleChip.stories.tsx@@ -0,0 +1,47 @@+import { BrowserRouter } from 'react-router-dom';+import styled from '@emotion/styled';+import type { Meta, StoryObj } from '@storybook/react';++import { getRenderWrapperForComponent } from '~/testing/renderWrappers';++import { PersonChip } from '../PersonChip';++const meta: Meta<typeof PersonChip> = {+ title: 'Modules/Companies/PersonChip',+ component: PersonChip,+};++export default meta;+type Story = StoryObj<typeof PersonChip>;++const TestCellContainer = styled.div`+ align-items: center;+ background: ${({ theme }) => theme.background.primary};+ display: flex;+ height: fit-content;+ justify-content: space-between;+ max-width: 250px;+ min-width: 250px;+ overflow: hidden;+ text-wrap: nowrap;+`;++export const SmallName: Story = {+ render: getRenderWrapperForComponent(+ <TestCellContainer>+ <BrowserRouter>+ <PersonChip id="tim_fake_id" name="Tim C." />+ </BrowserRouter>+ </TestCellContainer>,+ ),+};++export const BigName: Story = {+ render: getRenderWrapperForComponent(+ <TestCellContainer>+ <BrowserRouter>+ <PersonChip id="steve_fake_id" name="Steve J." />+ </BrowserRouter>+ </TestCellContainer>,+ ),+};diff --git a/front/src/modules/people/components/person-placeholder.png b/front/src/modules/people/components/person-placeholder.pngdeleted file mode 100644index 8beb87a117f..00000000000Binary files a/front/src/modules/people/components/person-placeholder.png and /dev/null differdiff --git a/front/src/modules/relation-picker/components/MultipleEntitySelect.tsx b/front/src/modules/relation-picker/components/MultipleEntitySelect.tsxindex 53b47d4f94d..9d44f9d24c2 100644--- a/front/src/modules/relation-picker/components/MultipleEntitySelect.tsx+++ b/front/src/modules/relation-picker/components/MultipleEntitySelect.tsx@@ -71,6 +71,7 @@ export function MultipleEntitySelect<><AvataravatarUrl={entity.avatarUrl}+ colorId={entity.id}placeholder={entity.name}size={16}type={entity.avatarType ?? 'rounded'}diff --git a/front/src/modules/relation-picker/components/SingleEntitySelectBase.tsx b/front/src/modules/relation-picker/components/SingleEntitySelectBase.tsxindex 172017c3a32..193391a3d51 100644--- a/front/src/modules/relation-picker/components/SingleEntitySelectBase.tsx+++ b/front/src/modules/relation-picker/components/SingleEntitySelectBase.tsx@@ -69,6 +69,7 @@ export function SingleEntitySelectBase<><AvataravatarUrl={entity.avatarUrl}+ colorId={entity.id}placeholder={entity.name}size={16}type={entity.avatarType ?? 'rounded'}diff --git a/front/src/modules/ui/layout/show-page/ShowPageSummaryCard.tsx b/front/src/modules/ui/layout/show-page/ShowPageSummaryCard.tsxindex 8f1dd92bd73..ca43bb4875b 100644--- a/front/src/modules/ui/layout/show-page/ShowPageSummaryCard.tsx+++ b/front/src/modules/ui/layout/show-page/ShowPageSummaryCard.tsx@@ -9,6 +9,13 @@ import {beautifyPastDateRelativeToNow,} from '@/utils/datetime/date-utils';+type OwnProps = {+ id?: string;+ logoOrAvatar?: string;+ title: string;+ date: string;+};+const StyledShowPageSummaryCard = styled.div`align-items: center;display: flex;@@ -46,14 +53,11 @@ const StyledTooltip = styled(Tooltip)``;export function ShowPageSummaryCard({+ id,logoOrAvatar,title,date,-}: {- logoOrAvatar?: string;- title: string;- date: string;-}) {+}: OwnProps) {const beautifiedCreatedAt =date !== '' ? beautifyPastDateRelativeToNow(date) : '';const exactCreatedAt = date !== '' ? beautifyExactDate(date) : '';@@ -65,6 +69,7 @@ export function ShowPageSummaryCard({<AvataravatarUrl={logoOrAvatar}size={theme.icon.size.xl}+ colorId={id}placeholder={title}/><StyledInfoContainer>diff --git a/front/src/modules/users/components/Avatar.tsx b/front/src/modules/users/components/Avatar.tsxindex 9612d1f8038..99b17040492 100644--- a/front/src/modules/users/components/Avatar.tsx+++ b/front/src/modules/users/components/Avatar.tsx@@ -1,5 +1,6 @@import styled from '@emotion/styled';+import { stringToHslColor } from '@/utils/string-to-hsl';import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';export type AvatarType = 'squared' | 'rounded';@@ -8,26 +9,23 @@ type OwnProps = {avatarUrl: string | null | undefined;size: number;placeholder: string;+ colorId?: string;type?: AvatarType;};-export const StyledAvatar = styled.div<Omit<OwnProps, 'placeholder'>>`+export const StyledAvatar = styled.div<OwnProps & { colorId: string }>`align-items: center;- background-color: ${(props) =>- !isNonEmptyString(props.avatarUrl)- ? props.theme.background.tertiary- : 'none'};- ${(props) =>- isNonEmptyString(props.avatarUrl)- ? `background-image: url(${props.avatarUrl});`- : ''}+ background-color: ${({ avatarUrl, colorId }) =>+ !isNonEmptyString(avatarUrl) ? stringToHslColor(colorId, 75, 85) : 'none'};+ ${({ avatarUrl }) =>+ isNonEmptyString(avatarUrl) ? `background-image: url(${avatarUrl});` : ''}background-size: cover;border-radius: ${(props) => (props.type === 'rounded' ? '50%' : '2px')};- color: ${({ theme }) => theme.font.color.primary};+ color: ${({ colorId }) => stringToHslColor(colorId, 75, 25)};display: flex;flex-shrink: 0;- font-size: ${({ theme }) => theme.font.size.sm};+ font-size: ${({ theme }) => theme.font.size.xs};font-weight: ${({ theme }) => theme.font.weight.medium};height: ${(props) => props.size}px;@@ -39,12 +37,19 @@ export function Avatar({avatarUrl,size,placeholder,+ colorId = placeholder,type = 'squared',}: OwnProps) {const noAvatarUrl = !isNonEmptyString(avatarUrl);return (- <StyledAvatar avatarUrl={avatarUrl} size={size} type={type}>+ <StyledAvatar+ avatarUrl={avatarUrl}+ placeholder={placeholder}+ size={size}+ type={type}+ colorId={colorId}+ >{noAvatarUrl && placeholder[0]?.toLocaleUpperCase()}</StyledAvatar>);diff --git a/front/src/modules/utils/string-to-hsl.ts b/front/src/modules/utils/string-to-hsl.tsnew file mode 100644index 00000000000..87ab9328140--- /dev/null+++ b/front/src/modules/utils/string-to-hsl.ts@@ -0,0 +1,13 @@+export function stringToHslColor(+ str: string,+ saturation: number,+ lightness: number,+) {+ let hash = 0;+ for (let i = 0; i < str.length; i++) {+ hash = str.charCodeAt(i) + ((hash << 5) - hash);+ }++ const h = hash % 360;+ return 'hsl(' + h + ', ' + saturation + '%, ' + lightness + '%)';+}diff --git a/front/src/modules/workspace/components/WorkspaceMemberCard.tsx b/front/src/modules/workspace/components/WorkspaceMemberCard.tsxindex 74cc05f05ea..b5ca0a4ec90 100644--- a/front/src/modules/workspace/components/WorkspaceMemberCard.tsx+++ b/front/src/modules/workspace/components/WorkspaceMemberCard.tsx@@ -33,7 +33,7 @@ const EmailText = styled.span`type OwnProps = {workspaceMember: {- user: Pick<User, 'firstName' | 'lastName' | 'avatarUrl' | 'email'>;+ user: Pick<User, 'id' | 'firstName' | 'lastName' | 'avatarUrl' | 'email'>;};accessory?: React.ReactNode;};@@ -43,6 +43,7 @@ export function WorkspaceMemberCard({ workspaceMember, accessory }: OwnProps) {<StyledContainer><AvataravatarUrl={getImageAbsoluteURIOrBase64(workspaceMember.user.avatarUrl)}+ colorId={workspaceMember.user.id}placeholder={workspaceMember.user.firstName || ''}type="squared"size={40}diff --git a/front/src/pages/companies/CompanyShow.tsx b/front/src/pages/companies/CompanyShow.tsxindex 482a1ee074a..09ea094ef10 100644--- a/front/src/pages/companies/CompanyShow.tsx+++ b/front/src/pages/companies/CompanyShow.tsx@@ -37,6 +37,7 @@ export function CompanyShow() {<><ShowPageLeftContainer><ShowPageSummaryCard+ id={company?.id}logoOrAvatar={getLogoUrlFromDomainName(company?.domainName ?? '')}title={company?.name ?? 'No name'}date={company?.createdAt ?? ''}diff --git a/front/src/pages/people/PersonShow.tsx b/front/src/pages/people/PersonShow.tsxindex fa79edfde19..9e8a0e158ce 100644--- a/front/src/pages/people/PersonShow.tsx+++ b/front/src/pages/people/PersonShow.tsx@@ -28,6 +28,7 @@ export function PersonShow() {<><ShowPageLeftContainer><ShowPageSummaryCard+ id={person?.id}title={person?.displayName ?? 'No name'}date={person?.createdAt ?? ''}/>