diff --git a/.vscode/settings.json b/.vscode/settings.json index 10c26d5..9579b55 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -38,6 +38,7 @@ "fileupload", "Foxbiz", "gapis", + "googleplay", "hangingpiece", "hideloading", "hilightjs", diff --git a/client/jsconfig.json b/client/jsconfig.json index 7fb5d1e..1d97943 100644 --- a/client/jsconfig.json +++ b/client/jsconfig.json @@ -1,9 +1,8 @@ { "compilerOptions": { - "baseUrl": "./", "paths": { "*": [ - "*" + "./src/*" ], } } diff --git a/client/pages/admin/index.js b/client/pages/admin/index.js index 76398ec..533942d 100644 --- a/client/pages/admin/index.js +++ b/client/pages/admin/index.js @@ -19,6 +19,7 @@ export default async function Admin() {

Admin Panel

+ ); } @@ -194,3 +195,94 @@ async function deleteUser(id) { alert('Success', 'User deleted successfully'); } } + +function EmailUsers() { + const recipientCount = Reactive(0); + const sendBtn = Ref(); + let filter = 'all'; + let subject = ''; + let message = ''; + + const fetchCount = async (selectedFilter) => { + try { + const res = await fetch(`/api/admin/email-recipients-count?filter=${selectedFilter}`); + const json = await res.json(); + recipientCount.value = json.count; + } catch { + // silently ignore; count remains at last known value + } + }; + + fetchCount(filter); + + const onFilterChange = (e) => { + filter = e.target.value; + fetchCount(filter); + }; + + const onSend = async () => { + if (!subject.trim() || !message.trim()) { + alert('ERROR', 'Subject and message are required'); + return; + } + const confirmation = await confirm('Confirm', `Send email to ${recipientCount.value} recipient(s)?`); + if (!confirmation) return; + sendBtn.disabled = true; + sendBtn.textContent = 'Sending...'; + try { + const res = await fetch('/api/admin/send-email', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ filter, subject, message }), + }); + const json = await res.json(); + if (json.error) { + alert('ERROR', json.error); + } else { + alert('Success', `Email sent to ${json.sent} user(s)`); + } + } catch { + alert('ERROR', 'Failed to send emails'); + } finally { + sendBtn.disabled = false; + sendBtn.textContent = 'Send Email'; + } + }; + + return ( +
+

Email Users

+
+
+ + + {recipientCount} recipient(s) will receive this email +
+ { + subject = e.target.value; + }} + /> +
+ +