|
1 | 1 | "use client"; |
2 | 2 | import { useState } from "react"; |
3 | 3 | import Link from "next/link"; |
| 4 | +import { actionSendProjectFeedback } from "@/src/util/actions/projectFeedback"; |
4 | 5 |
|
5 | 6 | export default function BroadcastPanel() { |
6 | 7 | const [message, setMessage] = useState<string>(""); |
7 | 8 | const [loading, setLoading] = useState<boolean>(false); |
8 | 9 | const [status, setStatus] = useState<string | null>(null); |
9 | 10 |
|
| 11 | + const [emailStatus, setEmailStatus] = useState< |
| 12 | + "idle" | "loading" | "success" | "error" |
| 13 | + >("idle"); |
| 14 | + |
10 | 15 | const sendBroadcast = async () => { |
11 | 16 | if (!message.trim()) { |
12 | 17 | setStatus("Message cannot be empty."); |
@@ -38,8 +43,23 @@ export default function BroadcastPanel() { |
38 | 43 | setLoading(false); |
39 | 44 | } |
40 | 45 | }; |
| 46 | + |
| 47 | + const sendFeedbackEmail = async () => { |
| 48 | + setEmailStatus("loading"); |
| 49 | + |
| 50 | + const result = await actionSendProjectFeedback(); |
| 51 | + |
| 52 | + if (result.success && result.failed && result.failed.length == 0) { |
| 53 | + setEmailStatus("success"); |
| 54 | + } else { |
| 55 | + console.error("Sending feedback emails failed:", result); |
| 56 | + setEmailStatus("error"); |
| 57 | + } |
| 58 | + }; |
| 59 | + |
41 | 60 | return ( |
42 | 61 | <div className="min-h-screen w-full flex flex-col items-center justify-center p-4"> |
| 62 | + {/* Broadcast using Discord */} |
43 | 63 | <div className="flex flex-col text-center w-full max-w-lg mx-auto bg-white border border-black rounded-2xl shadow-sm p-6 space-y-4"> |
44 | 64 | <div> |
45 | 65 | <h2 className="text-xl font-semibold text-black"> |
@@ -91,6 +111,43 @@ export default function BroadcastPanel() { |
91 | 111 | </div> |
92 | 112 | )} |
93 | 113 | </div> |
| 114 | + |
| 115 | + {/* Broadcast feedback emails */} |
| 116 | + <div className="flex flex-col text-center w-full max-w-lg mx-auto bg-white border border-black rounded-2xl shadow-sm p-6 mt-4 space-y-4"> |
| 117 | + <div> |
| 118 | + <h2 className="text-xl font-semibold text-black"> |
| 119 | + Send Feedback via Email |
| 120 | + </h2> |
| 121 | + <p className="text-sm text-black"> |
| 122 | + Send a message to all users via email. |
| 123 | + </p> |
| 124 | + <button |
| 125 | + onClick={sendFeedbackEmail} |
| 126 | + disabled={emailStatus === "loading"} |
| 127 | + className={`py-2 px-4 w-full rounded-md bg-green-600 hover:bg-green-500 text-white duration-200 border-black border disabled:opacity-50 ${ |
| 128 | + emailStatus === "loading" |
| 129 | + ? "bg-blue-300 cursor-not-allowed" |
| 130 | + : "bg-blue-600 hover:bg-blue-700 text-white" |
| 131 | + }`} |
| 132 | + > |
| 133 | + {emailStatus === "loading" |
| 134 | + ? "Sending..." |
| 135 | + : "Send Feedback via Email"} |
| 136 | + </button> |
| 137 | + |
| 138 | + {emailStatus === "success" && ( |
| 139 | + <div className="mt-3 text-sm px-3 py-2 rounded-lg bg-green-50 text-green-700 border border-green-200"> |
| 140 | + Feedback emails sent successfully. |
| 141 | + </div> |
| 142 | + )} |
| 143 | + {emailStatus === "error" && ( |
| 144 | + <div className="mt-3 text-sm px-3 py-2 rounded-lg bg-red-50 text-red-700 border border-red-200"> |
| 145 | + Failed to send feedback emails. |
| 146 | + </div> |
| 147 | + )} |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + |
94 | 151 | <Link |
95 | 152 | href="/dashboard" |
96 | 153 | className="m-10 py-2 px-4 w-full max-w-lg rounded-md bg-red-500 text-white text-center" |
|
0 commit comments