From 7ba96400615b0d67fff9b6967408a0dcfbc235b1 Mon Sep 17 00:00:00 2001 From: Basti Ortiz <39114273+BastiDood@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:45:40 +0800 Subject: [PATCH] feat(admin): provide better instructions on how to start drafts --- .../dashboard/(draft)/drafts/+error.svelte | 57 --------------- src/routes/dashboard/drafts/+error.svelte | 71 +++++++++++++++++++ .../{(draft) => }/drafts/+page.server.js | 6 +- .../{(draft) => }/drafts/+page.svelte | 0 4 files changed, 75 insertions(+), 59 deletions(-) delete mode 100644 src/routes/dashboard/(draft)/drafts/+error.svelte create mode 100644 src/routes/dashboard/drafts/+error.svelte rename src/routes/dashboard/{(draft) => }/drafts/+page.server.js (88%) rename src/routes/dashboard/{(draft) => }/drafts/+page.svelte (100%) diff --git a/src/routes/dashboard/(draft)/drafts/+error.svelte b/src/routes/dashboard/(draft)/drafts/+error.svelte deleted file mode 100644 index 6759ff8..0000000 --- a/src/routes/dashboard/(draft)/drafts/+error.svelte +++ /dev/null @@ -1,57 +0,0 @@ - - -{#if status === 499} -
{ - 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; - } - }; - }} - > - -
-{:else if error !== null} - {status}: {error.message} -{:else} - {status} -{/if} diff --git a/src/routes/dashboard/drafts/+error.svelte b/src/routes/dashboard/drafts/+error.svelte new file mode 100644 index 0000000..1afd00d --- /dev/null +++ b/src/routes/dashboard/drafts/+error.svelte @@ -0,0 +1,71 @@ + + +{#if status === 499} +
+
+

Start a New Draft

+

+ Welcome to the Draft Ranking Automated Processor! There are currently no drafts + happening at the moment, but as an administrator, you have the authorization to start a new one. +

+

+ To begin, simply provide the the maximum number of rounds for the upcoming draft. This has historically + been set to 5. +

+
+
{ + 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; + } + }; + }} + > + +
+
+{:else if error !== null} + {status}: {error.message} +{:else} + {status} +{/if} diff --git a/src/routes/dashboard/(draft)/drafts/+page.server.js b/src/routes/dashboard/drafts/+page.server.js similarity index 88% rename from src/routes/dashboard/(draft)/drafts/+page.server.js rename to src/routes/dashboard/drafts/+page.server.js index 48ae2a3..61de8b8 100644 --- a/src/routes/dashboard/(draft)/drafts/+page.server.js +++ b/src/routes/dashboard/drafts/+page.server.js @@ -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 = { diff --git a/src/routes/dashboard/(draft)/drafts/+page.svelte b/src/routes/dashboard/drafts/+page.svelte similarity index 100% rename from src/routes/dashboard/(draft)/drafts/+page.svelte rename to src/routes/dashboard/drafts/+page.svelte