-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(dashboard): Conversations page #10739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule .source
updated
from 698255 to 791db2
This file contains hidden or 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 hidden or 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,164 @@ | ||
| import { getDateRangeInMs, type IEnvironment } from '@novu/shared'; | ||
| import { get } from './api.client'; | ||
|
|
||
| export type ConversationFilters = { | ||
| dateRange?: string; | ||
| subscriberId?: string; | ||
| provider?: string[]; | ||
| conversationId?: string; | ||
| status?: string; | ||
| }; | ||
|
|
||
| export type ParticipantSubscriberData = { | ||
| firstName?: string; | ||
| lastName?: string; | ||
| avatar?: string; | ||
| subscriberId: string; | ||
| }; | ||
|
|
||
| export type ParticipantAgentData = { | ||
| name: string; | ||
| identifier: string; | ||
| }; | ||
|
|
||
| export type ConversationParticipantDto = { | ||
| type: string; | ||
| id: string; | ||
| subscriber?: ParticipantSubscriberData | null; | ||
| agent?: ParticipantAgentData | null; | ||
| }; | ||
|
|
||
| export type ConversationChannelDto = { | ||
| platform: string; | ||
| _integrationId: string; | ||
| platformThreadId: string; | ||
| }; | ||
|
|
||
| export type ConversationDto = { | ||
| _id: string; | ||
| identifier: string; | ||
| _agentId: string; | ||
| participants?: ConversationParticipantDto[]; | ||
| channels?: ConversationChannelDto[]; | ||
| status: string; | ||
| title: string; | ||
| metadata: Record<string, unknown>; | ||
| _environmentId: string; | ||
| _organizationId: string; | ||
| createdAt: string; | ||
| lastActivityAt: string; | ||
| }; | ||
|
|
||
| export type ConversationsListResponse = { | ||
| data: ConversationDto[]; | ||
| page: number; | ||
| totalCount: number; | ||
| pageSize: number; | ||
| hasMore: boolean; | ||
| }; | ||
|
|
||
| export function getConversationsList({ | ||
| environment, | ||
| page, | ||
| limit, | ||
| filters, | ||
| signal, | ||
| }: { | ||
| environment: IEnvironment; | ||
| page: number; | ||
| limit: number; | ||
| filters?: ConversationFilters; | ||
| signal?: AbortSignal; | ||
| }): Promise<ConversationsListResponse> { | ||
| const searchParams = new URLSearchParams(); | ||
| searchParams.append('page', page.toString()); | ||
| searchParams.append('limit', limit.toString()); | ||
|
|
||
| if (filters?.status) { | ||
| searchParams.append('status', filters.status); | ||
| } | ||
|
|
||
| if (filters?.subscriberId) { | ||
| searchParams.append('subscriberId', filters.subscriberId); | ||
| } | ||
|
|
||
| if (filters?.dateRange) { | ||
| const after = new Date(Date.now() - getDateRangeInMs(filters.dateRange)); | ||
| searchParams.append('after', after.toISOString()); | ||
| } | ||
|
|
||
| if (filters?.provider?.length) { | ||
| for (const p of filters.provider) { | ||
| searchParams.append('provider', p); | ||
| } | ||
| } | ||
|
|
||
| if (filters?.conversationId) { | ||
| searchParams.append('conversationId', filters.conversationId); | ||
| } | ||
|
|
||
| return get<ConversationsListResponse>(`/conversations?${searchParams.toString()}`, { | ||
| environment, | ||
| signal, | ||
| }); | ||
| } | ||
|
|
||
| export type ConversationActivityDto = { | ||
| _id: string; | ||
| identifier: string; | ||
| _conversationId: string; | ||
| type: 'message' | 'update' | 'signal'; | ||
| content: string; | ||
| platform: string; | ||
| _integrationId: string; | ||
| platformThreadId: string; | ||
| senderType: 'subscriber' | 'platform_user' | 'agent' | 'system'; | ||
| senderId: string; | ||
| senderName?: string; | ||
| platformMessageId?: string; | ||
| signalData?: { type: string; payload?: Record<string, unknown> }; | ||
| _environmentId: string; | ||
| _organizationId: string; | ||
| createdAt: string; | ||
| }; | ||
|
|
||
| export type ConversationActivitiesResponse = { | ||
| data: ConversationActivityDto[]; | ||
| page: number; | ||
| totalCount: number; | ||
| pageSize: number; | ||
| hasMore: boolean; | ||
| }; | ||
|
|
||
| /** `conversationIdentifier` is the public `identifier` field — the API resolves by identifier, not Mongo `_id`. */ | ||
| export function getConversation( | ||
| conversationIdentifier: string, | ||
| environment: IEnvironment | ||
| ): Promise<ConversationDto> { | ||
| return get<ConversationDto>(`/conversations/${encodeURIComponent(conversationIdentifier)}`, { | ||
| environment, | ||
| }); | ||
| } | ||
|
|
||
| export function getConversationActivities({ | ||
| conversationIdentifier, | ||
| environment, | ||
| page = 0, | ||
| limit = 50, | ||
| signal, | ||
| }: { | ||
| conversationIdentifier: string; | ||
| environment: IEnvironment; | ||
| page?: number; | ||
| limit?: number; | ||
| signal?: AbortSignal; | ||
| }): Promise<ConversationActivitiesResponse> { | ||
| const searchParams = new URLSearchParams(); | ||
| searchParams.append('page', page.toString()); | ||
| searchParams.append('limit', limit.toString()); | ||
|
|
||
| return get<ConversationActivitiesResponse>( | ||
| `/conversations/${encodeURIComponent(conversationIdentifier)}/activities?${searchParams.toString()}`, | ||
| { environment, signal } | ||
| ); | ||
| } |
This file contains hidden or 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,14 @@ | ||
| import { CONVERSATIONAL_PROVIDERS } from '@novu/shared'; | ||
| import { ConversationFiltersData } from '@/types/conversation'; | ||
|
|
||
| export const PROVIDER_OPTIONS = CONVERSATIONAL_PROVIDERS.filter((p) => !p.comingSoon).map((p) => ({ | ||
| label: p.displayName, | ||
| value: p.providerId, | ||
| })); | ||
|
|
||
| export const defaultConversationFilters: ConversationFiltersData = { | ||
| dateRange: '24h', | ||
| subscriberId: '', | ||
| provider: [], | ||
| conversationId: '', | ||
| } as const; |
99 changes: 99 additions & 0 deletions
99
apps/dashboard/src/components/conversations/conversation-detail.tsx
This file contains hidden or 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,99 @@ | ||
| import { RiArrowDownSLine, RiArrowUpSLine, RiCloseFill } from 'react-icons/ri'; | ||
| import { Separator } from '@/components/primitives/separator'; | ||
| import { Skeleton } from '@/components/primitives/skeleton'; | ||
| import { | ||
| useFetchConversation, | ||
| useFetchConversationActivities, | ||
| } from '@/hooks/use-fetch-conversation-activities'; | ||
| import { ConversationOverview } from './conversation-overview'; | ||
| import { ConversationTimeline } from './conversation-timeline'; | ||
|
|
||
| type ConversationDetailProps = { | ||
| conversationId: string; | ||
| onClose?: () => void; | ||
| onNavigate?: (direction: 'prev' | 'next') => void; | ||
| }; | ||
|
|
||
| export function ConversationDetail({ conversationId, onClose, onNavigate }: ConversationDetailProps) { | ||
| const { conversation, isLoading: isConversationLoading } = useFetchConversation(conversationId); | ||
| const { activities, totalCount, isLoading: isActivitiesLoading } = | ||
| useFetchConversationActivities(conversationId); | ||
|
|
||
| return ( | ||
| <div className="flex h-full flex-col"> | ||
| <div className="flex h-8 shrink-0 items-center justify-between px-2"> | ||
| <span className="text-text-strong text-label-sm font-medium">Conversation</span> | ||
| <div className="flex items-center gap-0.5"> | ||
| {onNavigate && ( | ||
| <> | ||
| <button | ||
| onClick={() => onNavigate('prev')} | ||
| className="text-text-soft hover:text-text-strong rounded p-0.5" | ||
| > | ||
| <RiArrowUpSLine className="size-4" /> | ||
| </button> | ||
| <button | ||
| onClick={() => onNavigate('next')} | ||
| className="text-text-soft hover:text-text-strong rounded p-0.5" | ||
| > | ||
| <RiArrowDownSLine className="size-4" /> | ||
| </button> | ||
| </> | ||
| )} | ||
| {onNavigate && onClose && <div className="bg-stroke-soft mx-0.5 h-4 w-px" />} | ||
| {onClose && ( | ||
| <button onClick={onClose} className="text-text-soft hover:text-text-strong rounded p-0.5"> | ||
| <RiCloseFill className="size-4" /> | ||
| </button> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex-1 overflow-y-auto"> | ||
| {isConversationLoading ? ( | ||
| <OverviewSkeleton /> | ||
| ) : conversation ? ( | ||
| <div className="px-3 pb-2"> | ||
| <ConversationOverview conversation={conversation} /> | ||
| </div> | ||
| ) : null} | ||
|
|
||
| <Separator /> | ||
|
|
||
| <ConversationTimeline | ||
| activities={activities} | ||
| isLoading={isActivitiesLoading} | ||
| totalCount={totalCount} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function OverviewSkeleton() { | ||
| return ( | ||
| <div className="flex flex-col gap-2 px-3 py-2"> | ||
| <div className="flex items-center justify-between"> | ||
| <Skeleton className="h-4 w-36" /> | ||
| <Skeleton className="h-4 w-32" /> | ||
| </div> | ||
| <div className="border-stroke-soft flex flex-col gap-1 rounded-lg border p-2"> | ||
| {Array.from({ length: 4 }).map((_, i) => ( | ||
| <div key={i} className="flex items-center justify-between py-1"> | ||
| <Skeleton className="h-3.5 w-24" /> | ||
| <Skeleton className="h-3.5 w-32" /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| <div className="border-stroke-soft rounded-lg border p-2"> | ||
| <div className="flex items-center gap-2"> | ||
| <Skeleton className="size-8 rounded-full" /> | ||
| <div className="flex flex-1 flex-col gap-1"> | ||
| <Skeleton className="h-3.5 w-24" /> | ||
| <Skeleton className="h-3 w-36" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.