:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { IconWarning } from '@posthog/icons'
import { LemonCollapse, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
import { stripMarkdown } from 'lib/utils/markdown'
import { urls } from 'scenes/urls'
import { Ticket } from '../../types'
interface PreviousTicketsPanelProps {
previousTickets: Ticket[]
previousTicketsLoading?: boolean
// Merged distinct_ids of the current ticket's person. Tickets whose distinct_id
// is not in this set were matched by email alone, so they may be a different person.
personDistinctIds?: string[]
}
export function PreviousTicketsPanel({
previousTickets,
previousTicketsLoading,
personDistinctIds,
}: PreviousTicketsPanelProps): JSX.Element {
return (
<LemonCollapse
className="bg-surface-primary"
panels={[
{
key: 'previous-tickets',
header: (
<>
Previous tickets
{previousTickets.length > 0 && (
<span className="text-muted-alt font-normal ml-1">({previousTickets.length})</span>
)}
</>
),
content: (
<div className="space-y-2">
{previousTicketsLoading ? (
<div className="text-muted-alt text-xs">Loading previous tickets...</div>
) : previousTickets.length === 0 ? (
<div className="text-muted-alt text-xs">No previous tickets found</div>
) : (
<div className="space-y-2 max-h-96 overflow-auto">
{previousTickets.map((ticket) => {
const matchedByEmailOnly =
!!ticket.distinct_id &&
!!personDistinctIds?.length &&
!personDistinctIds.includes(ticket.distinct_id)
return (
<Link
key={ticket.id}
to={urls.supportTicketDetail(ticket.ticket_number)}
className="block p-2 mb-2 rounded border border-primary hover:bg-accent-3000 transition-colors hover:border-secondary"
>
<div className="flex items-center justify-between mb-1">
<div className="flex items-center gap-1">
<span className="font-mono text-xs text-muted-alt">
#{ticket.ticket_number}
</span>
{matchedByEmailOnly && (
<Tooltip title="Matched by email address, so this may not be the same person profile.">
<LemonTag type="warning" size="small" className="gap-1">
<IconWarning />
Email match
</LemonTag>
</Tooltip>
)}
</div>
<LemonTag
type={
ticket.status === 'resolved'
? 'success'
: ticket.status === 'new'
? 'primary'
: 'default'
}
>
{ticket.status === 'on_hold' ? 'On hold' : ticket.status}
</LemonTag>
</div>
{ticket.last_message_text && (
<div className="text-xs text-muted truncate mb-1">
{stripMarkdown(ticket.last_message_text)}
</div>
)}
<div className="text-xs text-muted-alt">
Created <TZLabel time={ticket.created_at} />
</div>
</Link>
)
})}
</div>
)}
</div>
),
},
]}
/>
)
}