-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "scheddy", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite dev", | ||
|
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,43 @@ | ||
import { loadUserData } from '$lib/userInfo'; | ||
import { roleOf } from '$lib'; | ||
import { ROLE_STAFF } from '$lib/utils'; | ||
import { redirect } from '@sveltejs/kit'; | ||
import { db } from '$lib/server/db'; | ||
import { mentors, sessions, sessionTypes, students, users } from '$lib/server/db/schema'; | ||
import { eq } from 'drizzle-orm'; | ||
import type { PageServerLoad } from './$types'; | ||
import type { MentorAvailability } from '$lib/availability'; | ||
import { DateTime } from 'luxon'; | ||
|
||
export const load: PageServerLoad = async ({ cookies, params }) => { | ||
const { user } = (await loadUserData(cookies))!; | ||
if (roleOf(user) < ROLE_STAFF) { | ||
redirect(307, '/schedule'); | ||
} | ||
|
||
const validTypes = await db.select().from(sessionTypes); | ||
|
||
const typesMap: Record<string, string> = {}; | ||
for (const typ of validTypes) { | ||
typesMap[typ.id] = typ.name; | ||
} | ||
|
||
const allSessions = await db | ||
.select() | ||
.from(sessions) | ||
.leftJoin(students, eq(students.id, sessions.student)) | ||
.leftJoin(mentors, eq(mentors.id, sessions.mentor)) | ||
|
||
const mentorSessions = []; | ||
const now = DateTime.utc(); | ||
for (const sess of allSessions) { | ||
const start = DateTime.fromISO(sess.session.start); | ||
if (start < now) continue; | ||
mentorSessions.push(sess); | ||
} | ||
|
||
return { | ||
user, | ||
mentorSessions | ||
}; | ||
}; |
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,52 @@ | ||
<script lang="ts"> | ||
import type { PageData } from "./$types"; | ||
import { DateTime } from 'luxon'; | ||
import TableRoot from '$lib/ui/table/TableRoot.svelte'; | ||
import TableHead from '$lib/ui/table/TableHead.svelte'; | ||
import TableHeadColumn from '$lib/ui/table/TableHeadColumn.svelte'; | ||
import TableBody from '$lib/ui/table/TableBody.svelte'; | ||
import TableRow from '$lib/ui/table/TableRow.svelte'; | ||
import TableColumn from '$lib/ui/table/TableColumn.svelte'; | ||
import Button from '$lib/ui/Button.svelte'; | ||
import { PencilIcon } from 'lucide-svelte'; | ||
interface Props { | ||
data: PageData | ||
} | ||
let { data }: Props = $props(); | ||
</script> | ||
|
||
<div class="relative overflow-x-auto shadow-md rounded mt-2"> | ||
<TableRoot> | ||
<TableHead> | ||
<TableHeadColumn>Date</TableHeadColumn> | ||
<TableHeadColumn>Session Type</TableHeadColumn> | ||
<TableHeadColumn>Student</TableHeadColumn> | ||
<TableHeadColumn>Mentor</TableHeadColumn> | ||
<TableHeadColumn> | ||
<div class="flex flex-row align-middle justify-between items-center"> | ||
<span>Actions</span> | ||
</div> | ||
</TableHeadColumn> | ||
</TableHead> | ||
<TableBody> | ||
{#each data.mentorSessions as sess} | ||
<TableRow> | ||
<TableColumn | ||
>{DateTime.fromISO(sess.session.start) | ||
.setZone(data.mentor.timezone) | ||
.toLocaleString(DateTime.DATETIME_MED_WITH_WEEKDAY)}</TableColumn | ||
> | ||
<TableColumn>{data.typesMap[sess.session.type]}</TableColumn> | ||
<TableColumn>{sess.student.firstName} {sess.student.lastName}</TableColumn> | ||
<TableColumn>{sess.mentor.firstName} {sess.mentor.lastName}</TableColumn> | ||
<TableColumn> | ||
<Button size="icon" href="/dash/sessions/{sess.session.id}"> | ||
<PencilIcon class="w-4 h-4" /> | ||
</Button> | ||
</TableColumn> | ||
</TableRow> | ||
{/each} | ||
</TableBody> | ||
</TableRoot> | ||
</div> |