Skip to content

Commit

Permalink
feat(admin): provide better instructions on how to start drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Jul 11, 2024
1 parent c46cf50 commit 7ba9640
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
57 changes: 0 additions & 57 deletions src/routes/dashboard/(draft)/drafts/+error.svelte

This file was deleted.

71 changes: 71 additions & 0 deletions src/routes/dashboard/drafts/+error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script>
import { CalendarDays } from '@steeze-ui/heroicons';
import ErrorAlert from '$lib/alerts/Error.svelte';
import { Icon } from '@steeze-ui/svelte-icon';
import { assert } from '$lib/assert';
import { enhance } from '$app/forms';
import { getToastStore } from '@skeletonlabs/skeleton';
import { page } from '$app/stores';
const toast = getToastStore();
$: ({ status, error } = $page);
</script>

{#if status === 499}
<div class="grid grid-cols-1 gap-4 sm:grid-cols-[auto_1fr]">
<div class="prose dark:prose-invert">
<h2>Start a New Draft</h2>
<p>
Welcome to the <strong>Draft Ranking Automated Processor</strong>! There are currently no drafts
happening at the moment, but as an administrator, you have the authorization to start a new one.
</p>
<p>
To begin, simply provide the the maximum number of rounds for the upcoming draft. This has historically
been set to <strong>5</strong>.
</p>
</div>
<form
method="post"
action="?/init"
class="min-w-max"
use:enhance={({ submitter }) => {
assert(submitter !== null);
assert(submitter instanceof HTMLButtonElement);
submitter.disabled = true;
return async ({ update, result }) => {
submitter.disabled = false;
await update();
switch (result.type) {
case 'success':
toast.trigger({
message: 'Successfully started a new draft.',
background: 'variant-filled-success',
});
break;
case 'failure':
toast.trigger({
message: 'Failed to start a new draft.',
background: 'variant-filled-error',
});
break;
default:
break;
}
};
}}
>
<label>
<span>Number of Rounds</span>
<div class="input-group input-group-divider grid-cols-[auto_1fr_auto]">
<div class="input-group-shim"><Icon src={CalendarDays} class="size-6" /></div>
<input type="number" min="1" required name="rounds" placeholder="5" class="px-4 py-2" />
<button class="variant-filled-primary">Start</button>
</div>
</label>
</form>
</div>
{:else if error !== null}
<ErrorAlert><strong>{status}:</strong> {error.message}</ErrorAlert>
{:else}
<ErrorAlert><strong>{status}</strong></ErrorAlert>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { error } from '@sveltejs/kit';
import { validateString } from '$lib/forms';

export async function load({ locals: { db }, parent }) {
const { user, draft } = await parent();
const { user } = await parent();
if (!user.is_admin || user.user_id === null || user.lab_id !== null) error(403);
return { students: await db.getStudentsInDraft(draft.draft_id) };
const draft = await db.getLatestDraft();
if (draft === null) error(499);
return { draft, students: await db.getStudentsInDraft(draft.draft_id) };
}

export const actions = {
Expand Down
File renamed without changes.

0 comments on commit 7ba9640

Please sign in to comment.