diff --git a/components/Alert.tsx b/components/Alert.tsx index 1bafb49..a78fcac 100644 --- a/components/Alert.tsx +++ b/components/Alert.tsx @@ -1,6 +1,15 @@ -export default function Alert({ children }: { children: React.ReactNode }) { +import { ReactNode, useContext } from "react"; +import { ErrorContext } from "./App"; + +export default function Alert({ children }: { children: ReactNode }) { + const { setError } = useContext(ErrorContext); + + function onClick() { + setError(undefined); + } + return ( -
+
- {children} + {toSentence(children)} +
); } + +function toSentence(children: ReactNode) { + if (!children) { + return; + } + + let text = children.toString().trim(); + text = text.charAt(0).toUpperCase() + text.slice(1); + if (text.charAt(text.length - 1) !== ".") { + text += "."; + } + + return text; +}