-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from like-minded-nus/staging
merge staging into main
- Loading branch information
Showing
46 changed files
with
1,715 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AdminBase from '../../components/admin-base'; | ||
import UsersTable from './users-table'; | ||
|
||
const Reports = () => { | ||
const component = <UsersTable />; | ||
return <AdminBase content={component} />; | ||
}; | ||
|
||
export default Reports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client'; | ||
|
||
import { useAppDispatch, useAppSelector } from '@/redux/hooks'; | ||
import React, { useEffect } from 'react'; | ||
import { Ban } from '@/models/ban'; | ||
import { getBannedUsers } from '@/redux/features/banSlice'; | ||
|
||
const BanTable = () => { | ||
const dispatch = useAppDispatch(); | ||
const controller = new AbortController(); | ||
|
||
// Redux store | ||
const bans: Ban[] = useAppSelector((state) => state.banReducer.bans); | ||
|
||
useEffect(() => { | ||
dispatch(getBannedUsers({ controller })); | ||
|
||
return () => { | ||
controller.abort(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
console.log(bans); | ||
}, [bans]); | ||
|
||
return ( | ||
<> | ||
<div className='mt-4'> | ||
<table className='admin-table'> | ||
<thead> | ||
<tr> | ||
<th scope='col'>Ban ID</th> | ||
<th scope='col'>User ID</th> | ||
<th scope='col'>Username</th> | ||
<th scope='col'>Reason</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{bans.map((ban: Ban) => ( | ||
<tr key={ban.banId}> | ||
<th scope='row'>{ban.banId}</th> | ||
<td>{ban.userId}</td> | ||
<td>{ban.username}</td> | ||
<td>{ban.bannedReason}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default BanTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AdminBase from '../../../../components/admin-base'; | ||
import BanTable from './bans-table'; | ||
|
||
const Reports = () => { | ||
const component = <BanTable />; | ||
return <AdminBase content={component} />; | ||
}; | ||
|
||
export default Reports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AdminBase from '../../../components/admin-base'; | ||
import ReportTable from './report-table'; | ||
|
||
const Reports = () => { | ||
const component = <ReportTable />; | ||
return <AdminBase content={component} />; | ||
}; | ||
|
||
export default Reports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
'use client'; | ||
|
||
import { useAppDispatch, useAppSelector } from '@/redux/hooks'; | ||
import React, { useEffect } from 'react'; | ||
import { Report } from '@/models/report'; | ||
import { getReportedRecords } from '@/redux/features/reportSlice'; | ||
import axios from 'axios'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
const ReportTable = () => { | ||
const endpoint = process.env.NEXT_PUBLIC_API_ENDPOINT ?? ''; | ||
|
||
const dispatch = useAppDispatch(); | ||
const controller = new AbortController(); | ||
const { push } = useRouter(); | ||
|
||
// Redux store | ||
const reports: Report[] = useAppSelector( | ||
(state) => state.reportReducer.reports | ||
); | ||
|
||
useEffect(() => { | ||
dispatch(getReportedRecords({ controller })); | ||
|
||
return () => { | ||
controller.abort(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
console.log(reports); | ||
}, [reports]); | ||
|
||
const handleBanClick = async (id: Number, userId: Number, reason: String) => { | ||
const confirmResponse = window.confirm( | ||
'Are you sure you want to ban this user?' | ||
); | ||
if (confirmResponse) { | ||
const response = await axios.post(`${endpoint}/ban`, { | ||
id: id, | ||
userId: userId, | ||
bannedReason: reason, | ||
}); | ||
|
||
if (response.data.status === 200) { | ||
push(window.location.pathname + '/bans'); | ||
} else { | ||
alert('An error has occured!'); | ||
} | ||
} else { | ||
console.log('User cancelled the action.'); | ||
} | ||
}; | ||
|
||
const handleViewBanRecords = () => { | ||
push('/admin/user_management/reports/bans'); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className='mt-4'> | ||
<table className='admin-table'> | ||
<thead> | ||
<tr> | ||
<th scope='col'>Report ID</th> | ||
<th scope='col'>Username</th> | ||
<th scope='col'>Reason</th> | ||
<th scope='col'>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{reports.map((report: Report) => ( | ||
<tr key={report.reportId}> | ||
<th scope='row'>{report.reportId}</th> | ||
<td>{report.username}</td> | ||
<td>{report.reportedReason}</td> | ||
<td> | ||
<button | ||
className='btn btn-delete btn-square' | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
|
||
handleBanClick( | ||
report.reportId, | ||
report.userId, | ||
report.reportedReason | ||
); | ||
}} | ||
> | ||
Ban | ||
</button> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
<button | ||
className='btn btn-primary btn-square float-end mt-4' | ||
onClick={handleViewBanRecords} | ||
> | ||
View Ban Records | ||
</button> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ReportTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
const UsersTable = async () => { | ||
redirect('/admin/user_management/reports'); | ||
}; | ||
|
||
export default UsersTable; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.