Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add alert components (#2413)
Leendert de Borst1523b82fbce5
diff --git a/apps/web/src/components/alerts/AlertMessageError.tsx b/apps/web/src/components/alerts/AlertMessageError.tsxnew file mode 100644index 000000000..77c87a0ee--- /dev/null+++ b/apps/web/src/components/alerts/AlertMessageError.tsx@@ -0,0 +1,17 @@+import React from 'react';++/**+ * Red alert box.+ */+const AlertMessageError: React.FC<{ message: string; hasTopMargin?: boolean }> = ({ message, hasTopMargin = true }) => {+ if (!message) {+ return null;+ }+ return (+ <div className={`p-4 ${hasTopMargin ? 'mt-4' : ''} text-sm text-red-800 rounded-lg bg-red-50 border-2 dark:bg-red-800 dark:text-white dark:border-red-500 dark:border`} role="alert">+ {message}+ </div>+ );+};++export default AlertMessageError;diff --git a/apps/web/src/components/alerts/AlertMessageSuccess.tsx b/apps/web/src/components/alerts/AlertMessageSuccess.tsxnew file mode 100644index 000000000..3230498b9--- /dev/null+++ b/apps/web/src/components/alerts/AlertMessageSuccess.tsx@@ -0,0 +1,17 @@+import React from 'react';++/**+ * Green alert box.+ */+const AlertMessageSuccess: React.FC<{ message: string }> = ({ message }) => {+ if (!message) {+ return null;+ }+ return (+ <div className="p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-50 border-2 dark:bg-green-800 dark:text-white dark:border-green-500 dark:border" role="alert">+ {message}+ </div>+ );+};++export default AlertMessageSuccess;diff --git a/apps/web/src/components/alerts/GlobalNotificationDisplay.tsx b/apps/web/src/components/alerts/GlobalNotificationDisplay.tsxnew file mode 100644index 000000000..badfbd883--- /dev/null+++ b/apps/web/src/components/alerts/GlobalNotificationDisplay.tsx@@ -0,0 +1,43 @@+import React, { useEffect, useState } from 'react';+import { useLocation } from 'react-router-dom';++import AlertMessageError from '@/components/alerts/AlertMessageError';+import AlertMessageSuccess from '@/components/alerts/AlertMessageSuccess';+import { type Notification, useNotifications } from '@/context/NotificationContext';++type GlobalNotificationDisplayProps = {+ marginTop?: boolean;+ marginBottom?: boolean;+ paddingX?: boolean;+};++/**+ * Renders the queued global notifications inline. Messages are refreshed on navigation and whenever a message is+ * queued with notify.+ */+const GlobalNotificationDisplay: React.FC<GlobalNotificationDisplayProps> = ({ marginTop = true, marginBottom = false, paddingX = true }) => {+ const { takeMessages, version } = useNotifications();+ const location = useLocation();+ const [messages, setMessages] = useState<Notification[]>([]);++ useEffect(() => {+ setMessages(takeMessages());+ }, [takeMessages, version, location.pathname]);++ if (messages.length === 0) {+ return null;+ }++ return (+ <div className={`messages-container grid ${paddingX ? 'px-4' : ''} ${marginTop ? 'pt-6' : ''} lg:gap-4 ${marginBottom ? 'pb-6' : ''}`}>+ {messages.filter(m => m.type === 'success').map((message, index) => (+ <AlertMessageSuccess key={`success-${index}`} message={message.message} />+ ))}+ {messages.filter(m => m.type === 'error').map((message, index) => (+ <AlertMessageError key={`error-${index}`} message={message.message} />+ ))}+ </div>+ );+};++export default GlobalNotificationDisplay;diff --git a/apps/web/src/components/alerts/MessageInfo.tsx b/apps/web/src/components/alerts/MessageInfo.tsxnew file mode 100644index 000000000..56a3dbbed--- /dev/null+++ b/apps/web/src/components/alerts/MessageInfo.tsx@@ -0,0 +1,22 @@+import React from 'react';++/**+ * Orange info box with a title.+ */+const MessageInfo: React.FC<{ title?: string; children: React.ReactNode }> = ({ title, children }) => (+ <div className="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 mb-6" role="alert">+ <div className="flex">+ <div className="py-1">+ <svg className="fill-current h-6 w-6 text-orange-500 mr-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">+ <path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM9 11V9h2v6H9v-4zm0-6h2v2H9V5z" />+ </svg>+ </div>+ <div>+ {title && <p className="font-bold">{title}</p>}+ <div className="text-sm">{children}</div>+ </div>+ </div>+ </div>+);++export default MessageInfo;diff --git a/apps/web/src/components/alerts/MessageWarning.tsx b/apps/web/src/components/alerts/MessageWarning.tsxnew file mode 100644index 000000000..eff48961d--- /dev/null+++ b/apps/web/src/components/alerts/MessageWarning.tsx@@ -0,0 +1,13 @@+import React from 'react';++/**+ * Red warning box.+ */+const MessageWarning: React.FC<{ message: string }> = ({ message }) => {+ if (!message) {+ return null;+ }+ return <div className="p-4 mb-4 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg">{message}</div>;+};++export default MessageWarning;diff --git a/apps/web/src/components/alerts/ServerValidationErrors.tsx b/apps/web/src/components/alerts/ServerValidationErrors.tsxnew file mode 100644index 000000000..94ab0e2d2--- /dev/null+++ b/apps/web/src/components/alerts/ServerValidationErrors.tsx@@ -0,0 +1,21 @@+import React from 'react';++import AlertMessageError from '@/components/alerts/AlertMessageError';++/**+ * List of form-level errors.+ */+const ServerValidationErrors: React.FC<{ errors: string[] }> = ({ errors }) => {+ if (errors.length === 0) {+ return null;+ }+ return (+ <div className="messages-container">+ {errors.map((error, index) => (+ <AlertMessageError key={index} message={error} />+ ))}+ </div>+ );+};++export default ServerValidationErrors;