From 10c0bd953b9f2f0a8400670396d1adbe489d034d Mon Sep 17 00:00:00 2001 From: Don Strawsburg Date: Mon, 15 Dec 2025 22:04:48 -0500 Subject: [PATCH] emailing html now for formatted messages --- app/admin/email/page.tsx | 4 +- app/admin/email/send/page-sendText.tsx | 116 ++++++++++++ app/admin/email/send/page.tsx | 123 +------------ components/SendEmail-oriig.tsx | 117 ++++++++++++ components/SendEmail.tsx | 118 ++++++------ components/ui/RichTextEditor.tsx | 46 +++++ components/ui/send_email_form.tsx | 125 +++++++++++++ lib/api/dateFormattingUtility.ts | 5 + package-lock.json | 244 ++++++++++++++++++++++--- package.json | 4 +- 10 files changed, 702 insertions(+), 200 deletions(-) create mode 100644 app/admin/email/send/page-sendText.tsx create mode 100644 components/SendEmail-oriig.tsx create mode 100644 components/ui/RichTextEditor.tsx create mode 100644 components/ui/send_email_form.tsx create mode 100644 lib/api/dateFormattingUtility.ts diff --git a/app/admin/email/page.tsx b/app/admin/email/page.tsx index e090742..c1f19fa 100644 --- a/app/admin/email/page.tsx +++ b/app/admin/email/page.tsx @@ -12,7 +12,7 @@ import { type UpdateEmailRequestDto, } from "@/lib/api/emailRequests"; import { Pencil, Trash2, Plus, X } from "lucide-react"; - +import { formatDate } from "@/lib/api/dateFormattingUtility"; export default function AdminEmailPage() { const { token } = useAuth(); const [emails, setEmails] = useState([]); @@ -165,7 +165,7 @@ export default function AdminEmailPage() { {new Date(email.createdAt).toLocaleString()} - {new Date(email.updatedAt).toLocaleString()} + {formatDate(email.updatedAt)}
diff --git a/app/admin/email/send/page-sendText.tsx b/app/admin/email/send/page-sendText.tsx new file mode 100644 index 0000000..2151763 --- /dev/null +++ b/app/admin/email/send/page-sendText.tsx @@ -0,0 +1,116 @@ +"use client"; + +import { useEffect, useRef, useState } from "react"; +import { sendEmailAction, type ApiResponse, type EmailRequest } from "/app/actions/sendEmail"; +import { Button, Field, Input, Textarea } from "@/components/ui/form"; + +export default function SendEmailForm(): JSX.Element { + const [result, setResult] = useState< + ApiResponse | { error: string } | null + >(null); + const [submitting, setSubmitting] = useState(false); + + const [showSuccess, setShowSuccess] = useState(false); + const successTimerRef = useRef | null>(null); + + useEffect(() => { + return () => { + if (successTimerRef.current) clearTimeout(successTimerRef.current); + }; + }, []); + + async function onSubmit(e: React.FormEvent): Promise { + e.preventDefault(); + setResult(null); + + setShowSuccess(false); + if (successTimerRef.current) clearTimeout(successTimerRef.current); + + const form = new FormData(e.currentTarget); + + const recipient = String(form.get("recipient") ?? ""); + const subject = String(form.get("subject") ?? ""); + const body = String(form.get("body") ?? ""); + + try { + setSubmitting(true); + const data = await sendEmailAction({ recipient, subject, body }); + setResult(data); + + if (data?.success === true) { + setShowSuccess(true); + + successTimerRef.current = setTimeout(() => { + setShowSuccess(false); + }, 2000); + } + } catch (err) { + const message = err instanceof Error ? err.message : "Unknown error"; + setResult({ error: message }); + } finally { + setSubmitting(false); + } + } + + return ( +
+

+ Send Email +

+

+ Compose a message and send it from the admin panel. +

+ +
+ {result && "error" in result && ( +
+ {result.error} +
+ )} + + + + + + + + + + +