: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 clsx from 'clsx'
import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
export type SlaState = 'breached' | 'at-risk' | 'on-track'
export function getSlaState(slaDueAt: string): SlaState {
const diffMs = dayjs(slaDueAt).diff(dayjs())
if (diffMs < 0) {
return 'breached'
}
if (diffMs < 60 * 60 * 1000) {
return 'at-risk'
}
return 'on-track'
}
export function SlaDisplay({
slaDueAt,
className,
showPopover = true,
}: {
slaDueAt?: string | null
className?: string
showPopover?: boolean
}): JSX.Element | null {
if (!slaDueAt) {
return null
}
const due = dayjs(slaDueAt)
const slaState = getSlaState(slaDueAt)
return (
<TZLabel
time={due}
showPopover={showPopover}
className={clsx(
'font-medium',
{
'text-danger': slaState === 'breached',
'text-warning': slaState === 'at-risk',
'text-success': slaState === 'on-track',
},
className
)}
/>
)
}