'use client'; import * as React from 'react'; import { Alert, AlertTitle, Collapse, Typography } from '@mui/material'; import { Box } from '@mui/system'; import { Warning as WarningIcon } from '@phosphor-icons/react/dist/ssr/Warning'; interface PropsError { message: string; code?: string | number; details?: string; severity?: 'error' | 'warning' | 'info' | 'success'; } // RULES: Sample of function function formatErrorMessage(message: string, code?: string | number): string { return code ? `[${code}] ${message}` : message; } // RULES: sample of inner component function ErrorDetails({ details }: { details: string }): React.JSX.Element { const [expanded, setExpanded] = React.useState(false); return ( { setExpanded(!expanded); }} > {expanded ? 'Hide Details' : 'Show Details'} {details} ); } // RULES: naming should be in Pascal case // RULES: sample of main component function ErrorDisplay({ message, code, details, severity = 'error' }: PropsError): React.JSX.Element { const [formattedMessage, setFormattedMessage] = React.useState(''); React.useEffect(() => { setFormattedMessage(formatErrorMessage(message, code)); }, [message, code]); return ( } sx={{ '& .MuiAlert-message': { width: '100%', }, }} > {code ? `Error ${code}` : 'Error'} {formattedMessage} {details && } ); } // RULES: component should be exported export default ErrorDisplay;