All files / src/components ReasonAlert.tsx

100% Statements 3/3
83.33% Branches 5/6
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                              29x 29x 29x                                        
// An error about the whole action (src/lib/reasons.ts, AlertReason), with
// its title, as on the Design canvas (SignInErrors). role="alert" makes
// screen readers announce it.
import Alert from '@mui/material/Alert'
import AlertTitle from '@mui/material/AlertTitle'
import Box from '@mui/material/Box'
import { reasonText, type Reason } from '#/lib/reasons'
import { errorReference } from '#/lib/trace'
import { m } from '#/paraglide/messages.js'
 
/**
 * `unexpected` also shows the error reference (spec: "Showing a reference
 * with an unexpected error"), which finds the failure in the logs.
 */
export function ReasonAlert({ reason }: { reason: Reason }) {
  const { title, text } = reasonText(reason)
  const reference = reason === 'unexpected' ? errorReference() : undefined
  return (
    <Alert severity="error">
      {title === undefined ? null : <AlertTitle>{title}</AlertTitle>}
      {text}
      {reference === undefined ? null : (
        <Box
          component="span"
          sx={{
            display: 'block',
            mt: 0.5,
            color: 'text.secondary',
            fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace",
          }}
        >
          {m.error_reference({ reference })}
        </Box>
      )}
    </Alert>
  )
}