From f5078b814ef2a43fb18a965fb4c6c16ea565abc8 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 27 Feb 2024 18:39:21 -0500 Subject: [PATCH] improves alerts ui closes #49 --- components/Alert.tsx | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) 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; +}