diff --git a/src/pages/moderation.jsx b/src/pages/moderation.jsx index 34abc996..cc7c5b20 100644 --- a/src/pages/moderation.jsx +++ b/src/pages/moderation.jsx @@ -46,6 +46,11 @@ export default function Competitions() { }); }; + const resetFields = () => { + document.getElementById('usernameInput').value = ""; + document.getElementById('reasonInput').value = ""; + }; + const fetchPendingChallenges = async () => { try { const response = await request(process.env.NEXT_PUBLIC_API_URL + '/pending', "GET"); @@ -67,13 +72,74 @@ export default function Competitions() { } }; + const handleDeleteChallenge = async () => { + const challengeId = document.getElementById('challengeIdInput').value; + const reason = document.getElementById('challengeReasonInput').value; + + try{ + const response = await request(`${process.env.NEXT_PUBLIC_API_URL}/admin/${challengeId}/deleteChallenge`, "POST", {reason}); + if(response.success){ + alert("Challenge deleted successfully!"); + }else { + alert("Failed to delete challenge."); + } + + document.getElementById('challengeIdInput').value = ""; + document.getElementById('challengeReasonInput').value = ""; + + + }catch(err){ + console.log(err); + alert("An error occurred while deleting the challenge."); + } + + }; + + const handleUnapproveChallenge = async () => { + const challengeId = document.getElementById('challengeIdInput').value; + const reason = document.getElementById('challengeReasonInput').value; + + try{ + const response = await request(`${process.env.NEXT_PUBLIC_API_URL}/admin/${challengeId}/unapproveChallenge`, "POST", {reason}); + if(response.success){ + alert("Challenge unapproved successfully!"); + }else { + alert("Failed to unapprove challenge."); + } + + document.getElementById('challengeIdInput').value = ""; + document.getElementById('challengeReasonInput').value = ""; + + + }catch(err){ + console.log(err); + alert("An error occurred while unapproving the challenge."); + } + + }; + + const handleResyncLeaderboard = async () => { + try{ + const response = await request(`${process.env.NEXT_PUBLIC_API_URL}/admin/syncLeaderboard`, "POST"); + if(response.success){ + alert("Leaderboard resynced successfully!"); + }else { + alert("Failed to resync leaderboard."); + } + }catch(err){ + console.log(err); + alert("An error occurred while resyncing the leaderboard."); + } + }; + useEffect(() => { fetchPendingChallenges(); }, []); const handleResetPFP = async () => { const username = document.getElementById('usernameInput').value; - const reason = ""; // Set reason as blank for now + const reason = document.getElementById('reasonInput').value; + console.log('REASON: ', reason); if (!username) { alert("Please enter a username."); @@ -87,6 +153,9 @@ export default function Competitions() { } else { alert("Failed to reset profile picture."); } + + resetFields(); + } catch (error) { console.error(error); alert("An error occurred while resetting the profile picture."); @@ -95,7 +164,7 @@ export default function Competitions() { const handleResetBanner = async () => { const username = document.getElementById('usernameInput').value; - const reason = ""; // Set reason as blank for now + const reason = document.getElementById('reasonInput').value; if(!username) { alert("Please enter a username."); @@ -108,6 +177,9 @@ export default function Competitions() { }else { alert("Failed to reset banner."); } + + resetFields(); + }catch(err){ console.log(err); alert("An error occurred while resetting the banner."); @@ -116,7 +188,7 @@ export default function Competitions() { const handleDisableAccount = async () => { const username = document.getElementById('usernameInput').value; - const reason = ""; + const reason = document.getElementById('reasonInput').value; if (!username) { alert("Please enter a username."); @@ -130,15 +202,41 @@ export default function Competitions() { } else { alert("Failed to disable account."); } + + resetFields(); + }catch(err){ console.log(err); alert("An error occurred while disabling the account."); } }; + const handleResetBio = async () => { + + const username = document.getElementById('usernameInput').value; + const reason = document.getElementById('reasonInput').value; + + if (!username) { + alert("Please enter a username."); + return; + } + try{ + const response = await request(`${process.env.NEXT_PUBLIC_API_URL}/admin/${username}/resetBio`, "POST", {reason}); + if(response.success){ + alert("Bio reset successfully!"); + }else{ + alert("Failed to reset bio."); + } + + resetFields(); + }catch(err){ + console.log(err); + alert("An error occurred while resetting the bio."); + } + }; const handleEnableAccount = async () => { const username = document.getElementById('usernameInput').value; - const reason = ""; + const reason = document.getElementById('reasonInput').value; if (!username) { alert("Please enter a username."); @@ -151,12 +249,37 @@ export default function Competitions() { }else { alert("Failed to enable account."); } + + resetFields(); }catch(err){ console.log(err); alert("An error occurred while enabling the account."); } }; + const handleWarnUser = async () => { + const username = document.getElementById('usernameInput').value; + const reason = document.getElementById('reasonInput').value; + + if (!username) { + alert("Please enter a username."); + return; + } + try{ + const response = await request(`${process.env.NEXT_PUBLIC_API_URL}/admin/${username}/warnUser`, "POST", {reason}); + if(response.success){ + alert("User warned successfully!"); + }else { + alert("Failed to warn user."); + } + + resetFields(); + }catch(err){ + console.log(err); + alert("An error occurred while warning the user."); + } + }; + return ( <>
@@ -192,19 +315,22 @@ export default function Competitions() { - + + +