From 070825d2b779b114a1c345fbca210d324bf34d53 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 29 Mar 2025 22:19:55 -0400 Subject: Quote submit stats + input validation for author/year; API changes; Use toString for some stuff --- web/src/app/quotes/page.js | 67 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) (limited to 'web/src/app') diff --git a/web/src/app/quotes/page.js b/web/src/app/quotes/page.js index 0dde1ec..3ba4ea3 100644 --- a/web/src/app/quotes/page.js +++ b/web/src/app/quotes/page.js @@ -9,6 +9,8 @@ export default function Quotes() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [message, setMessage] = useState(null); + const [rejectReason, setRejectReason] = useState(''); + const [quoteToReject, setQuoteToReject] = useState(null); const [formData, setFormData] = useState({ author: '', authorImage: '', @@ -16,6 +18,7 @@ export default function Quotes() { year: '', submitterID: '' }); + const [silentReject, setSilentReject] = useState(false); useEffect(() => { fetchPendingQuotes(); @@ -114,14 +117,28 @@ export default function Quotes() { } }; - const handleRejectQuote = async (id) => { + const openRejectModal = (id) => { + setQuoteToReject(id); + setRejectReason(''); + }; + + const closeRejectModal = () => { + setQuoteToReject(null); + setRejectReason(''); + }; + + const handleRejectQuote = async () => { try { const response = await fetchWithAuth('/api/quotes/reject', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id }) + body: JSON.stringify({ + id: quoteToReject, + reason: rejectReason, + silent: silentReject + }) }); if (!response.ok) { @@ -133,6 +150,9 @@ export default function Quotes() { text: 'Quote rejected successfully' }); + // Close modal + closeRejectModal(); + // Refresh quotes fetchPendingQuotes(); } catch (err) { @@ -202,7 +222,6 @@ export default function Quotes() { )} -

Pending Quotes

{loading &&

Loading quotes...

} @@ -228,7 +247,7 @@ export default function Quotes() { Approve