fix(dashboard): guard nested fields (resolution, firstResponse, awaitingAction) to prevent undefined access and runtime crash; add safe fallbacks in UI
This commit is contained in:
parent
68b897c30c
commit
2cdc856009
1 changed files with 13 additions and 10 deletions
|
|
@ -83,17 +83,18 @@ export function SectionCards() {
|
|||
rateLabel: "Taxa indisponível",
|
||||
}
|
||||
}
|
||||
const current = dashboard.resolution.resolvedLast7d ?? 0
|
||||
const previous = dashboard.resolution.previousResolved ?? 0
|
||||
const deltaPercentage = dashboard.resolution.deltaPercentage ?? null
|
||||
const current = dashboard?.resolution?.resolvedLast7d ?? 0
|
||||
const previous = dashboard?.resolution?.previousResolved ?? 0
|
||||
const deltaPercentage = dashboard?.resolution?.deltaPercentage ?? null
|
||||
const positive = deltaPercentage !== null ? deltaPercentage >= 0 : current >= previous
|
||||
const badgeLabel = deltaPercentage !== null
|
||||
? `${deltaPercentage >= 0 ? "+" : ""}${deltaPercentage.toFixed(1)}%`
|
||||
: previous > 0
|
||||
? `${current - previous >= 0 ? "+" : ""}${current - previous}`
|
||||
: "Sem histórico"
|
||||
const rateLabel = dashboard.resolution.rate !== null
|
||||
? `${dashboard.resolution.rate.toFixed(1)}% dos tickets foram resolvidos`
|
||||
const rate = dashboard?.resolution?.rate ?? null
|
||||
const rateLabel = rate !== null
|
||||
? `${rate.toFixed(1)}% dos tickets foram resolvidos`
|
||||
: "Taxa indisponível"
|
||||
return { positive, badgeLabel, rateLabel }
|
||||
}, [dashboard])
|
||||
|
|
@ -137,7 +138,9 @@ export function SectionCards() {
|
|||
<span className="block">1ª resposta</span>
|
||||
</CardDescription>
|
||||
<CardTitle className="text-3xl font-semibold tabular-nums">
|
||||
{dashboard ? formatMinutes(dashboard.firstResponse.averageMinutes) : <Skeleton className="h-8 w-24" />}
|
||||
{dashboard?.firstResponse
|
||||
? formatMinutes(dashboard.firstResponse.averageMinutes)
|
||||
: <Skeleton className="h-8 w-24" />}
|
||||
</CardTitle>
|
||||
<CardAction>
|
||||
<Badge
|
||||
|
|
@ -157,7 +160,7 @@ export function SectionCards() {
|
|||
</CardHeader>
|
||||
<CardFooter className="flex-col items-start gap-1 text-sm text-muted-foreground">
|
||||
<span className="text-foreground">
|
||||
{dashboard
|
||||
{dashboard?.firstResponse
|
||||
? `${dashboard.firstResponse.responsesCount} tickets com primeira resposta`
|
||||
: "Carregando amostra"}
|
||||
</span>
|
||||
|
|
@ -169,12 +172,12 @@ export function SectionCards() {
|
|||
<CardHeader className="gap-3">
|
||||
<CardDescription>Tickets aguardando ação</CardDescription>
|
||||
<CardTitle className="text-3xl font-semibold tabular-nums">
|
||||
{dashboard ? dashboard.awaitingAction.total : <Skeleton className="h-8 w-16" />}
|
||||
{dashboard?.awaitingAction ? dashboard.awaitingAction.total : <Skeleton className="h-8 w-16" />}
|
||||
</CardTitle>
|
||||
<CardAction>
|
||||
<Badge variant="outline" className="rounded-full gap-1 px-2 py-1 text-xs">
|
||||
<IconClockHour4 className="size-3.5" />
|
||||
{dashboard ? `${dashboard.awaitingAction.atRisk} em risco` : "—"}
|
||||
{dashboard?.awaitingAction ? `${dashboard.awaitingAction.atRisk} em risco` : "—"}
|
||||
</Badge>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
|
|
@ -191,7 +194,7 @@ export function SectionCards() {
|
|||
<span className="block">(7 dias)</span>
|
||||
</CardDescription>
|
||||
<CardTitle className="text-3xl font-semibold tabular-nums">
|
||||
{dashboard ? dashboard.resolution.resolvedLast7d : <Skeleton className="h-8 w-12" />}
|
||||
{dashboard?.resolution ? dashboard.resolution.resolvedLast7d : <Skeleton className="h-8 w-12" />}
|
||||
</CardTitle>
|
||||
<CardAction>
|
||||
<Badge
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue