Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udate #78

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 5 additions & 40 deletions src/app/dashboard/info/points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,31 @@
import { Column } from 'primereact/column'
import { DataTable } from 'primereact/datatable'

import { JsonUser } from '@/lib/db/models/User'

import { AppPermissions } from '@/lib/db/models/Role'
import { useImmer } from 'use-immer'

export interface UserDataTableProps {
users: JsonUser[]
perms: AppPermissions
allRoles: readonly string[]
users: { name: string; pointsObtained: number }[]
}

export default function UserDataTable({
users: initialUsers,
users,
}: UserDataTableProps) {
const [users] = useImmer(initialUsers)

const sortedUsers = [...users].sort((a, b) =>
(b.pointsObtained || 0) - (a.pointsObtained || 0)
)

const modifiedUsers = sortedUsers.map((user) => {
return {
...user,
pointsObtained: user.pointsObtained === undefined
? 0
: user.pointsObtained,
}
})

return (
<div className="flex flex-col gap-2">
<h2 className="text-2xl font-bold mb-2">Leaderboard</h2>
<DataTable
value={modifiedUsers}
value={users}
// pagination
paginator
rows={5}
rowsPerPageOptions={[5, 10, 25, 50]}
// row expansion

// selection
selectionPageOnly
// sort
removableSort
sortMode="multiple"
// misc
className="text-sm shadow-md rounded-lg"
emptyMessage="No users found."
>
<Column expander />
<Column header="Email" field="email" filter />
<Column
header="First Name"
field="application.firstName"
filter
/>
<Column
header="Last Name"
field="application.lastName"
filter
header="Name"
field="name"
/>
<Column
header="Points"
Expand Down
24 changes: 9 additions & 15 deletions src/app/dashboard/score.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import clientPromise from '@/lib/db'
import { Role } from '@/lib/db/models/Role'
import User from '@/lib/db/models/User'
import { getEnhancedSession } from '@/lib/utils/server'
import { headers } from 'next/headers'
import User, { getFullName } from '@/lib/db/models/User'
import UserDataTable from './info/points'

export default async function Users() {
const { perms } = getEnhancedSession(headers())
const client = await clientPromise
const roles = await client.db()
.collection<Role>('roles')
.find({}, { projection: { granted: 0 } })
.toArray()
const users = await client.db()
const users = (await client.db()
.collection<User>('users')
.find({}, { projection: { 'application.resume': 0 } })
.toArray()
.find({ pointsObtained: { $gt: 0 } }, {
projection: { 'application.resume': 0 },
})
.sort({ pointsObtained: 'descending' })
.toArray())
.map((u) => ({ name: getFullName(u), pointsObtained: u.pointsObtained! }))
return (
<>
<UserDataTable
allRoles={roles.map((r) => r._id)}
users={JSON.parse(JSON.stringify(users))}
perms={perms}
users={users}
/>
<br />
</>
Expand Down