forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4810 display participants in the right drawer of the calendar event (t…
…wentyhq#4896) Closes twentyhq#4810 - Introduces a new component `ExpandableList` which uses intersection observers to display the maximum number of elements possible
- Loading branch information
1 parent
432d041
commit c0b3a87
Showing
18 changed files
with
468 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...nt/src/modules/activities/calendar/components/CalendarEventParticipantsResponseStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import groupBy from 'lodash.groupby'; | ||
|
||
import { CalendarEventParticipantsResponseStatusField } from '@/activities/calendar/components/CalendarEventParticipantsResponseStatusField'; | ||
import { CalendarEventParticipant } from '@/activities/calendar/types/CalendarEventParticipant'; | ||
|
||
export const CalendarEventParticipantsResponseStatus = ({ | ||
participants, | ||
}: { | ||
participants: CalendarEventParticipant[]; | ||
}) => { | ||
const groupedParticipants = groupBy(participants, (participant) => { | ||
switch (participant.responseStatus) { | ||
case 'ACCEPTED': | ||
return 'Yes'; | ||
case 'DECLINED': | ||
return 'No'; | ||
case 'NEEDS_ACTION': | ||
case 'TENTATIVE': | ||
return 'Maybe'; | ||
default: | ||
return ''; | ||
} | ||
}); | ||
|
||
const responseStatusOrder: ('Yes' | 'Maybe' | 'No')[] = [ | ||
'Yes', | ||
'Maybe', | ||
'No', | ||
]; | ||
|
||
return ( | ||
<> | ||
{responseStatusOrder.map((responseStatus) => ( | ||
<CalendarEventParticipantsResponseStatusField | ||
key={responseStatus} | ||
responseStatus={responseStatus} | ||
participants={groupedParticipants[responseStatus] || []} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
108 changes: 108 additions & 0 deletions
108
...c/modules/activities/calendar/components/CalendarEventParticipantsResponseStatusField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useRef } from 'react'; | ||
import { useTheme } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
import { IconCheck, IconQuestionMark, IconX } from 'twenty-ui'; | ||
import { v4 } from 'uuid'; | ||
|
||
import { CalendarEventParticipant } from '@/activities/calendar/types/CalendarEventParticipant'; | ||
import { ParticipantChip } from '@/activities/components/ParticipantChip'; | ||
import { PropertyBox } from '@/object-record/record-inline-cell/property-box/components/PropertyBox'; | ||
import { ExpandableList } from '@/ui/display/expandable-list/ExpandableList'; | ||
import { EllipsisDisplay } from '@/ui/field/display/components/EllipsisDisplay'; | ||
|
||
const StyledInlineCellBaseContainer = styled.div` | ||
align-items: center; | ||
box-sizing: border-box; | ||
width: 100%; | ||
display: flex; | ||
gap: ${({ theme }) => theme.spacing(1)}; | ||
position: relative; | ||
user-select: none; | ||
`; | ||
|
||
const StyledPropertyBox = styled(PropertyBox)` | ||
height: ${({ theme }) => theme.spacing(6)}; | ||
padding: 0; | ||
width: 100%; | ||
`; | ||
|
||
const StyledIconContainer = styled.div` | ||
align-items: center; | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
display: flex; | ||
width: 16px; | ||
svg { | ||
align-items: center; | ||
display: flex; | ||
height: 16px; | ||
justify-content: center; | ||
width: 16px; | ||
} | ||
`; | ||
|
||
const StyledLabelAndIconContainer = styled.div` | ||
align-items: center; | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
display: flex; | ||
gap: ${({ theme }) => theme.spacing(1)}; | ||
`; | ||
|
||
const StyledLabelContainer = styled.div<{ width?: number }>` | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
font-size: ${({ theme }) => theme.font.size.sm}; | ||
width: ${({ width }) => width}px; | ||
`; | ||
|
||
export const CalendarEventParticipantsResponseStatusField = ({ | ||
responseStatus, | ||
participants, | ||
}: { | ||
responseStatus: 'Yes' | 'Maybe' | 'No'; | ||
participants: CalendarEventParticipant[]; | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const Icon = { | ||
Yes: <IconCheck stroke={theme.icon.stroke.sm} />, | ||
Maybe: <IconQuestionMark stroke={theme.icon.stroke.sm} />, | ||
No: <IconX stroke={theme.icon.stroke.sm} />, | ||
}[responseStatus]; | ||
|
||
// We want to display external participants first | ||
const orderedParticipants = [ | ||
...participants.filter((participant) => participant.person), | ||
...participants.filter( | ||
(participant) => !participant.person && !participant.workspaceMember, | ||
), | ||
...participants.filter((participant) => participant.workspaceMember), | ||
]; | ||
|
||
const participantsContainerRef = useRef<HTMLDivElement>(null); | ||
|
||
const StyledChips = orderedParticipants.map((participant) => ( | ||
<ParticipantChip participant={participant} /> | ||
)); | ||
|
||
return ( | ||
<StyledPropertyBox> | ||
<StyledInlineCellBaseContainer> | ||
<StyledLabelAndIconContainer> | ||
<StyledIconContainer>{Icon}</StyledIconContainer> | ||
|
||
<StyledLabelContainer width={72}> | ||
<EllipsisDisplay>{responseStatus}</EllipsisDisplay> | ||
</StyledLabelContainer> | ||
</StyledLabelAndIconContainer> | ||
|
||
<ExpandableList | ||
listItems={StyledChips} | ||
id={v4()} | ||
rootRef={participantsContainerRef} | ||
/> | ||
</StyledInlineCellBaseContainer> | ||
</StyledPropertyBox> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/twenty-front/src/modules/activities/calendar/types/CalendarEventParticipant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Person } from '@/people/types/Person'; | ||
import { WorkspaceMember } from '~/generated-metadata/graphql'; | ||
|
||
export type CalendarEventParticipant = { | ||
id: string; | ||
handle: string; | ||
isOrganizer: boolean; | ||
displayName: string; | ||
person?: Person; | ||
workspaceMember?: WorkspaceMember; | ||
responseStatus: 'ACCEPTED' | 'DECLINED' | 'NEEDS_ACTION' | 'TENTATIVE'; | ||
}; |
80 changes: 80 additions & 0 deletions
80
packages/twenty-front/src/modules/activities/components/ParticipantChip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { getDisplayNameFromParticipant } from '@/activities/emails/utils/getDisplayNameFromParticipant'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { RecordChip } from '@/object-record/components/RecordChip'; | ||
import { Avatar } from '@/users/components/Avatar'; | ||
|
||
const StyledAvatar = styled(Avatar)` | ||
margin-right: ${({ theme }) => theme.spacing(1)}; | ||
`; | ||
|
||
const StyledSenderName = styled.span<{ variant?: 'default' | 'bold' }>` | ||
color: ${({ theme }) => theme.font.color.primary}; | ||
font-size: ${({ theme }) => theme.font.size.md}; | ||
font-weight: ${({ theme, variant }) => | ||
variant === 'bold' ? theme.font.weight.medium : theme.font.weight.regular}; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
`; | ||
|
||
const StyledContainer = styled.div` | ||
align-items: flex-start; | ||
display: flex; | ||
`; | ||
|
||
const StyledRecordChip = styled(RecordChip)<{ variant: 'default' | 'bold' }>` | ||
font-weight: ${({ theme, variant }) => | ||
variant === 'bold' ? theme.font.weight.medium : theme.font.weight.regular}; | ||
`; | ||
|
||
const StyledChip = styled.div` | ||
align-items: center; | ||
display: flex; | ||
padding: ${({ theme }) => theme.spacing(1)}; | ||
height: 20px; | ||
box-sizing: border-box; | ||
`; | ||
|
||
type ParticipantChipVariant = 'default' | 'bold'; | ||
|
||
export const ParticipantChip = ({ | ||
participant, | ||
variant = 'default', | ||
className, | ||
}: { | ||
participant: any; | ||
variant?: ParticipantChipVariant; | ||
className?: string; | ||
}) => { | ||
const { person, workspaceMember } = participant; | ||
|
||
const displayName = getDisplayNameFromParticipant({ | ||
participant, | ||
shouldUseFullName: true, | ||
}); | ||
|
||
const avatarUrl = person?.avatarUrl ?? workspaceMember?.avatarUrl ?? ''; | ||
|
||
return ( | ||
<StyledContainer className={className}> | ||
{person ? ( | ||
<StyledRecordChip | ||
objectNameSingular={CoreObjectNameSingular.Person} | ||
record={person} | ||
variant={variant} | ||
/> | ||
) : ( | ||
<StyledChip> | ||
<StyledAvatar | ||
avatarUrl={avatarUrl} | ||
type="rounded" | ||
placeholder={displayName} | ||
size="sm" | ||
/> | ||
<StyledSenderName variant={variant}>{displayName}</StyledSenderName> | ||
</StyledChip> | ||
)} | ||
</StyledContainer> | ||
); | ||
}; |
Oops, something went wrong.