Refactor verifications portal GUI
This commit is contained in:
+10
-1
@@ -616,7 +616,16 @@ export const app = new Elysia()
|
|||||||
.get("/:id", async ({ params: { id } }) => {
|
.get("/:id", async ({ params: { id } }) => {
|
||||||
const verification = await s.Verifications.get(id);
|
const verification = await s.Verifications.get(id);
|
||||||
if (!verification) return status(404, { error: "Verification not found" });
|
if (!verification) return status(404, { error: "Verification not found" });
|
||||||
return verification;
|
|
||||||
|
const { contents = [] } = await r2.verificationMedia.list({ prefix: `${verification.assessment_id}/` });
|
||||||
|
const media = contents.map(({ key, size, lastModified }) => ({
|
||||||
|
key,
|
||||||
|
size,
|
||||||
|
lastModified,
|
||||||
|
url: r2.verificationMedia.presign(key, { expiresIn: 60 * 60 }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return { ...verification, media };
|
||||||
}, {
|
}, {
|
||||||
params: t.Object({ id: BigIntIdSchema })
|
params: t.Object({ id: BigIntIdSchema })
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
{
|
{
|
||||||
name: "Verification",
|
name: "Verification",
|
||||||
path: "/verification",
|
path: "/verification",
|
||||||
links: [{ name: "Requests", path: "/requests" }],
|
links: [{ name: "Verifications", path: "/verifications" }],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,471 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { goto } from "$app/navigation";
|
|
||||||
import { api } from "$lib/api";
|
|
||||||
import { Activity, cmToIn, kgToLb } from "@blade-and-brawn/domain";
|
|
||||||
import type { ActivityVerifications } from "@blade-and-brawn/domain";
|
|
||||||
import type { VerificationStatus } from "@blade-and-brawn/api";
|
|
||||||
import { onMount } from "svelte";
|
|
||||||
import type { PageProps } from "./$types";
|
|
||||||
|
|
||||||
async function loadVerification(id: string) {
|
|
||||||
return await api.verifications({ id }).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
type VerificationDetail = NonNullable<
|
|
||||||
Awaited<ReturnType<typeof loadVerification>>["data"]
|
|
||||||
>;
|
|
||||||
type VerfChoice = "unset" | "pass" | "fail";
|
|
||||||
|
|
||||||
const ACTIVITIES = Object.values(Activity);
|
|
||||||
|
|
||||||
const STATUS_BADGE: Record<VerificationStatus, string> = {
|
|
||||||
draft: "badge-ghost",
|
|
||||||
submitted: "badge-info",
|
|
||||||
in_review: "badge-warning",
|
|
||||||
action_requested: "badge-error",
|
|
||||||
completed: "badge-success",
|
|
||||||
};
|
|
||||||
|
|
||||||
const MEDIA_KEY_COLUMN = {
|
|
||||||
[Activity.BackSquat]: "media_key_back_squat",
|
|
||||||
[Activity.Deadlift]: "media_key_deadlift",
|
|
||||||
[Activity.BenchPress]: "media_key_bench_press",
|
|
||||||
[Activity.Run]: "media_key_run",
|
|
||||||
[Activity.BroadJump]: "media_key_broad_jump",
|
|
||||||
[Activity.ConeDrill]: "media_key_cone_drill",
|
|
||||||
} as const satisfies Record<Activity, keyof VerificationDetail>;
|
|
||||||
|
|
||||||
const VERF_COLUMN = {
|
|
||||||
[Activity.BackSquat]: "verf_back_squat",
|
|
||||||
[Activity.Deadlift]: "verf_deadlift",
|
|
||||||
[Activity.BenchPress]: "verf_bench_press",
|
|
||||||
[Activity.Run]: "verf_run",
|
|
||||||
[Activity.BroadJump]: "verf_broad_jump",
|
|
||||||
[Activity.ConeDrill]: "verf_cone_drill",
|
|
||||||
} as const satisfies Record<Activity, keyof VerificationDetail>;
|
|
||||||
|
|
||||||
const PERF_COLUMN = {
|
|
||||||
[Activity.BackSquat]: "perf_back_squat",
|
|
||||||
[Activity.Deadlift]: "perf_deadlift",
|
|
||||||
[Activity.BenchPress]: "perf_bench_press",
|
|
||||||
[Activity.Run]: "perf_run",
|
|
||||||
[Activity.BroadJump]: "perf_broad_jump",
|
|
||||||
[Activity.ConeDrill]: "perf_cone_drill",
|
|
||||||
} as const satisfies Record<Activity, keyof VerificationDetail>;
|
|
||||||
|
|
||||||
function formatPerformance(activity: Activity, value: number | null): string {
|
|
||||||
if (value === null) return "—";
|
|
||||||
switch (activity) {
|
|
||||||
case Activity.BackSquat:
|
|
||||||
case Activity.Deadlift:
|
|
||||||
case Activity.BenchPress:
|
|
||||||
return `${Math.round(kgToLb(value))} lb`;
|
|
||||||
case Activity.Run: {
|
|
||||||
const totalSeconds = Math.floor(value / 1000);
|
|
||||||
const minutes = Math.floor(totalSeconds / 60);
|
|
||||||
const seconds = totalSeconds % 60;
|
|
||||||
return `${minutes}m ${seconds}s`;
|
|
||||||
}
|
|
||||||
case Activity.ConeDrill:
|
|
||||||
return `${(value / 1000).toFixed(2)} seconds`;
|
|
||||||
case Activity.BroadJump: {
|
|
||||||
const inches = cmToIn(value);
|
|
||||||
const ft = Math.floor(inches / 12);
|
|
||||||
const rem = Math.round((inches - ft * 12) * 2) / 2;
|
|
||||||
return `${ft}' ${rem}"`;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return "—";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function verfChoiceFrom(value: boolean | null): VerfChoice {
|
|
||||||
if (value === true) return "pass";
|
|
||||||
if (value === false) return "fail";
|
|
||||||
return "unset";
|
|
||||||
}
|
|
||||||
|
|
||||||
function toActivityVerifications(
|
|
||||||
choices: Record<Activity, VerfChoice>,
|
|
||||||
): ActivityVerifications {
|
|
||||||
const result: ActivityVerifications = {};
|
|
||||||
for (const activity of ACTIVITIES) {
|
|
||||||
if (choices[activity] === "pass") result[activity] = true;
|
|
||||||
else if (choices[activity] === "fail") result[activity] = false;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function errorMessage(err: unknown): string {
|
|
||||||
const value = (err as { value?: { error?: string } })?.value;
|
|
||||||
return (
|
|
||||||
value?.error ??
|
|
||||||
(err instanceof Error ? err.message : "Unknown error")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let { params }: PageProps = $props();
|
|
||||||
const id = $derived(params.id);
|
|
||||||
|
|
||||||
let verification = $state<VerificationDetail | null>(null);
|
|
||||||
let loading = $state(true);
|
|
||||||
let loadError = $state<string | null>(null);
|
|
||||||
let stepIndex = $state(0);
|
|
||||||
let notes = $state("");
|
|
||||||
let verf = $state<Record<Activity, VerfChoice>>(
|
|
||||||
Object.fromEntries(ACTIVITIES.map((a) => [a, "unset"])) as Record<
|
|
||||||
Activity,
|
|
||||||
VerfChoice
|
|
||||||
>,
|
|
||||||
);
|
|
||||||
let submitting = $state<"action" | "complete" | undefined>();
|
|
||||||
let submitError = $state<string | null>(null);
|
|
||||||
|
|
||||||
const SUMMARY_STEP = ACTIVITIES.length;
|
|
||||||
const isSummaryStep = $derived(stepIndex === SUMMARY_STEP);
|
|
||||||
const reviewedCount = $derived(
|
|
||||||
ACTIVITIES.filter((a) => verf[a] !== "unset").length,
|
|
||||||
);
|
|
||||||
const allReviewed = $derived(reviewedCount === ACTIVITIES.length);
|
|
||||||
const isReadOnly = $derived(
|
|
||||||
verification?.status !== "submitted" &&
|
|
||||||
verification?.status !== "in_review",
|
|
||||||
);
|
|
||||||
|
|
||||||
async function load() {
|
|
||||||
loading = true;
|
|
||||||
loadError = null;
|
|
||||||
try {
|
|
||||||
const res = await loadVerification(id);
|
|
||||||
if (res.error) throw res.error;
|
|
||||||
if (!res.data) throw new Error("Verification not found");
|
|
||||||
verification = res.data;
|
|
||||||
notes = verification.reviewer_notes ?? "";
|
|
||||||
verf = Object.fromEntries(
|
|
||||||
ACTIVITIES.map((a) => [
|
|
||||||
a,
|
|
||||||
verfChoiceFrom(verification![VERF_COLUMN[a]]),
|
|
||||||
]),
|
|
||||||
) as Record<Activity, VerfChoice>;
|
|
||||||
} catch (err) {
|
|
||||||
loadError = errorMessage(err);
|
|
||||||
} finally {
|
|
||||||
loading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function goPrev() {
|
|
||||||
stepIndex = Math.max(0, stepIndex - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function goNext() {
|
|
||||||
stepIndex = Math.min(SUMMARY_STEP, stepIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setVerf(activity: Activity, choice: VerfChoice) {
|
|
||||||
if (isReadOnly) return;
|
|
||||||
verf[activity] = choice;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function requestAction() {
|
|
||||||
submitting = "action";
|
|
||||||
submitError = null;
|
|
||||||
try {
|
|
||||||
const res = await api
|
|
||||||
.verifications({ id })
|
|
||||||
["request-action"].post({
|
|
||||||
reviewerNotes: notes || undefined,
|
|
||||||
activityVerifications: toActivityVerifications(verf),
|
|
||||||
});
|
|
||||||
if (res.error) throw res.error;
|
|
||||||
await goto("/verification/requests");
|
|
||||||
} catch (err) {
|
|
||||||
submitError = errorMessage(err);
|
|
||||||
} finally {
|
|
||||||
submitting = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function complete() {
|
|
||||||
submitting = "complete";
|
|
||||||
submitError = null;
|
|
||||||
try {
|
|
||||||
const res = await api.verifications({ id }).complete.post({
|
|
||||||
activityVerifications: toActivityVerifications(verf),
|
|
||||||
});
|
|
||||||
if (res.error) throw res.error;
|
|
||||||
await goto("/verification/requests");
|
|
||||||
} catch (err) {
|
|
||||||
submitError = errorMessage(err);
|
|
||||||
} finally {
|
|
||||||
submitting = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(load);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="w-full mt-10 mb-5">
|
|
||||||
<a href="/verification/requests" class="link link-hover text-sm opacity-70"
|
|
||||||
>← Back to requests</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if loading}
|
|
||||||
<div class="w-full flex justify-center pt-10">
|
|
||||||
<span class="loading loading-spinner loading-lg"></span>
|
|
||||||
</div>
|
|
||||||
{:else if loadError}
|
|
||||||
<div role="alert" class="alert alert-error w-full mb-4">
|
|
||||||
<span>{loadError}</span>
|
|
||||||
</div>
|
|
||||||
{:else if verification}
|
|
||||||
{@const v = verification}
|
|
||||||
<div class="w-full flex items-center gap-3 flex-wrap mb-6">
|
|
||||||
<h1 class="text-xl font-semibold">{v.name}</h1>
|
|
||||||
<div class="badge {STATUS_BADGE[v.status as VerificationStatus]}">{v.status}</div>
|
|
||||||
<span class="text-sm opacity-70"
|
|
||||||
>{v.gender} · age {v.age} · {Math.round(kgToLb(v.weight))} lb</span
|
|
||||||
>
|
|
||||||
<div class="flex-1"></div>
|
|
||||||
<span class="text-sm opacity-70"
|
|
||||||
>{reviewedCount} / {ACTIVITIES.length} reviewed</span
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div role="tablist" class="tabs tabs-border w-full">
|
|
||||||
{#each ACTIVITIES as activity, i (activity)}
|
|
||||||
<button
|
|
||||||
role="tab"
|
|
||||||
class="tab gap-2"
|
|
||||||
class:tab-active={stepIndex === i}
|
|
||||||
onclick={() => (stepIndex = i)}
|
|
||||||
>
|
|
||||||
{activity}
|
|
||||||
{#if verf[activity] === "pass"}
|
|
||||||
<span class="text-success">✓</span>
|
|
||||||
{:else if verf[activity] === "fail"}
|
|
||||||
<span class="text-error">✕</span>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
<button
|
|
||||||
role="tab"
|
|
||||||
class="tab"
|
|
||||||
class:tab-active={isSummaryStep}
|
|
||||||
onclick={() => (stepIndex = SUMMARY_STEP)}
|
|
||||||
>
|
|
||||||
Summary
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if !isSummaryStep}
|
|
||||||
{@const activity = ACTIVITIES[stepIndex]}
|
|
||||||
<div class="w-full flex flex-col gap-4 bg-base-200/60 rounded-lg p-6 mt-4">
|
|
||||||
<div class="flex items-center justify-between flex-wrap gap-2">
|
|
||||||
<h2 class="text-lg font-semibold">{activity}</h2>
|
|
||||||
<div class="text-right">
|
|
||||||
<div class="text-xs opacity-60">Claimed</div>
|
|
||||||
<div class="text-2xl font-bold">
|
|
||||||
{formatPerformance(activity, v[PERF_COLUMN[activity]])}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if v[MEDIA_KEY_COLUMN[activity]]}
|
|
||||||
{@const videoUrl = v[MEDIA_KEY_COLUMN[activity]]}
|
|
||||||
<!-- svelte-ignore a11y_media_has_caption -->
|
|
||||||
<video
|
|
||||||
class="w-full max-h-[480px] rounded-lg bg-black"
|
|
||||||
src={videoUrl}
|
|
||||||
controls
|
|
||||||
preload="metadata"
|
|
||||||
></video>
|
|
||||||
<a
|
|
||||||
class="link link-primary text-xs self-start"
|
|
||||||
href={videoUrl}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
Open video in new tab
|
|
||||||
</a>
|
|
||||||
{:else}
|
|
||||||
<div
|
|
||||||
class="w-full aspect-video rounded-lg bg-base-300 flex items-center justify-center opacity-60"
|
|
||||||
>
|
|
||||||
No video uploaded
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="flex gap-2 justify-center mt-2">
|
|
||||||
<button
|
|
||||||
class="btn btn-sm {verf[activity] === 'pass'
|
|
||||||
? 'btn-success'
|
|
||||||
: 'btn-outline btn-success'}"
|
|
||||||
disabled={isReadOnly}
|
|
||||||
onclick={() => setVerf(activity, "pass")}
|
|
||||||
>
|
|
||||||
Pass
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="btn btn-sm {verf[activity] === 'fail'
|
|
||||||
? 'btn-error'
|
|
||||||
: 'btn-outline btn-error'}"
|
|
||||||
disabled={isReadOnly}
|
|
||||||
onclick={() => setVerf(activity, "fail")}
|
|
||||||
>
|
|
||||||
Fail
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="btn btn-sm btn-ghost"
|
|
||||||
disabled={isReadOnly || verf[activity] === "unset"}
|
|
||||||
onclick={() => setVerf(activity, "unset")}
|
|
||||||
>
|
|
||||||
Clear
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-between mt-2">
|
|
||||||
<button
|
|
||||||
class="btn btn-neutral btn-sm"
|
|
||||||
onclick={goPrev}
|
|
||||||
disabled={stepIndex === 0}
|
|
||||||
>
|
|
||||||
← Previous
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-neutral btn-sm" onclick={goNext}>
|
|
||||||
Next →
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="w-full flex flex-col gap-4 bg-base-200/60 rounded-lg p-6 mt-4">
|
|
||||||
<h2 class="text-lg font-semibold">Review summary</h2>
|
|
||||||
|
|
||||||
<div class="overflow-x-auto">
|
|
||||||
<table class="table table-sm">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Activity</th>
|
|
||||||
<th>Claimed</th>
|
|
||||||
<th>Video</th>
|
|
||||||
<th>Result</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{#each ACTIVITIES as activity, i (activity)}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<button
|
|
||||||
class="link link-hover"
|
|
||||||
onclick={() => (stepIndex = i)}
|
|
||||||
>
|
|
||||||
{activity}
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{formatPerformance(
|
|
||||||
activity,
|
|
||||||
v[PERF_COLUMN[activity]],
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{#if v[MEDIA_KEY_COLUMN[activity]]}
|
|
||||||
<a
|
|
||||||
class="link link-primary"
|
|
||||||
href={v[MEDIA_KEY_COLUMN[activity]]}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
{:else}
|
|
||||||
<span class="opacity-50">None</span>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{#if verf[activity] === "pass"}
|
|
||||||
<span class="badge badge-success"
|
|
||||||
>Pass</span
|
|
||||||
>
|
|
||||||
{:else if verf[activity] === "fail"}
|
|
||||||
<span class="badge badge-error"
|
|
||||||
>Fail</span
|
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<span class="badge badge-ghost"
|
|
||||||
>Unreviewed</span
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label class="form-control">
|
|
||||||
<span class="label mb-1 text-xs">Reviewer notes</span>
|
|
||||||
<textarea
|
|
||||||
class="textarea textarea-bordered w-full"
|
|
||||||
rows="3"
|
|
||||||
placeholder="What needs to be fixed?"
|
|
||||||
disabled={isReadOnly}
|
|
||||||
bind:value={notes}
|
|
||||||
></textarea>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
{#if submitError}
|
|
||||||
<div role="alert" class="alert alert-error">
|
|
||||||
<span>{submitError}</span>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="flex items-center gap-2 justify-between">
|
|
||||||
<button
|
|
||||||
class="btn btn-neutral btn-sm"
|
|
||||||
onclick={goPrev}
|
|
||||||
disabled={stepIndex === 0}
|
|
||||||
>
|
|
||||||
← Previous
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{#if isReadOnly}
|
|
||||||
<span class="text-sm opacity-70">
|
|
||||||
{v.status === "completed"
|
|
||||||
? "This verification is completed and read-only."
|
|
||||||
: v.status === "draft"
|
|
||||||
? "This verification is still a draft (the player hasn't finished uploading) and is read-only."
|
|
||||||
: "This verification is waiting on the player to resubmit and is read-only."}
|
|
||||||
</span>
|
|
||||||
{:else}
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
{#if !allReviewed}
|
|
||||||
<span class="text-xs text-warning"
|
|
||||||
>Mark every activity Pass or Fail to complete</span
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
<button
|
|
||||||
class="btn btn-warning"
|
|
||||||
disabled={!!submitting}
|
|
||||||
onclick={requestAction}
|
|
||||||
>
|
|
||||||
{submitting === "action"
|
|
||||||
? "Submitting..."
|
|
||||||
: "Request action"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="btn btn-success"
|
|
||||||
disabled={!!submitting || !allReviewed}
|
|
||||||
onclick={complete}
|
|
||||||
>
|
|
||||||
{submitting === "complete"
|
|
||||||
? "Submitting..."
|
|
||||||
: "Complete"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
|
||||||
+7
-23
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { api } from "$lib/api";
|
import { api } from "$lib/api";
|
||||||
import { Activity } from "@blade-and-brawn/domain";
|
|
||||||
import type { VerificationStatus } from "@blade-and-brawn/api";
|
import type { VerificationStatus } from "@blade-and-brawn/api";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
@@ -18,19 +17,6 @@
|
|||||||
completed: "badge-success",
|
completed: "badge-success",
|
||||||
};
|
};
|
||||||
|
|
||||||
const MEDIA_KEY_COLUMN = {
|
|
||||||
[Activity.BackSquat]: "media_key_back_squat",
|
|
||||||
[Activity.Deadlift]: "media_key_deadlift",
|
|
||||||
[Activity.BenchPress]: "media_key_bench_press",
|
|
||||||
[Activity.Run]: "media_key_run",
|
|
||||||
[Activity.BroadJump]: "media_key_broad_jump",
|
|
||||||
[Activity.ConeDrill]: "media_key_cone_drill",
|
|
||||||
} as const satisfies Record<Activity, keyof VerificationRow>;
|
|
||||||
|
|
||||||
function videoCount(row: VerificationRow): number {
|
|
||||||
return Object.values(Activity).filter((a) => row[MEDIA_KEY_COLUMN[a]]).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(value: string | Date | null): string {
|
function formatDate(value: string | Date | null): string {
|
||||||
if (!value) return "—";
|
if (!value) return "—";
|
||||||
return new Date(value).toLocaleString();
|
return new Date(value).toLocaleString();
|
||||||
@@ -44,7 +30,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let requests = $state<VerificationRow[]>([]);
|
let verifications = $state<VerificationRow[]>([]);
|
||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
let loadError = $state<string | null>(null);
|
let loadError = $state<string | null>(null);
|
||||||
let offset = $state(0);
|
let offset = $state(0);
|
||||||
@@ -58,7 +44,7 @@
|
|||||||
query: { status: status || undefined, limit: LIMIT, offset },
|
query: { status: status || undefined, limit: LIMIT, offset },
|
||||||
});
|
});
|
||||||
if (res.error) throw res.error;
|
if (res.error) throw res.error;
|
||||||
requests = res.data as VerificationRow[];
|
verifications = res.data as VerificationRow[];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
loadError = errorMessage(err);
|
loadError = errorMessage(err);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -118,7 +104,7 @@
|
|||||||
<button
|
<button
|
||||||
class="btn btn-neutral btn-sm"
|
class="btn btn-neutral btn-sm"
|
||||||
onclick={nextPage}
|
onclick={nextPage}
|
||||||
disabled={requests.length < LIMIT || loading}
|
disabled={verifications.length < LIMIT || loading}
|
||||||
>
|
>
|
||||||
Next
|
Next
|
||||||
</button>
|
</button>
|
||||||
@@ -136,13 +122,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Player</th>
|
<th>Player</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Videos</th>
|
|
||||||
<th>Submitted</th>
|
<th>Submitted</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each requests as row (row.id)}
|
{#each verifications as row (row.id)}
|
||||||
<tr class="hover:bg-base-300">
|
<tr class="hover:bg-base-300">
|
||||||
<td>{row.name}</td>
|
<td>{row.name}</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -150,12 +135,11 @@
|
|||||||
{row.status}
|
{row.status}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>{videoCount(row)} / {Object.values(Activity).length}</td>
|
|
||||||
<td class="whitespace-nowrap">{formatDate(row.submitted_at)}</td>
|
<td class="whitespace-nowrap">{formatDate(row.submitted_at)}</td>
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a
|
||||||
class="btn btn-primary btn-xs"
|
class="btn btn-primary btn-xs"
|
||||||
href="/verification/requests/{row.id}"
|
href="/verification/verifications/{row.id}"
|
||||||
>
|
>
|
||||||
Review
|
Review
|
||||||
</a>
|
</a>
|
||||||
@@ -163,8 +147,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{:else}
|
{:else}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5" class="text-center opacity-60">
|
<td colspan="4" class="text-center opacity-60">
|
||||||
{loading ? "Loading..." : "No verification requests"}
|
{loading ? "Loading..." : "No verifications"}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
@@ -0,0 +1,365 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from "$app/navigation";
|
||||||
|
import { api } from "$lib/api";
|
||||||
|
import { Activity, cmToIn, kgToLb } from "@blade-and-brawn/domain";
|
||||||
|
import type { ActivityVerifications } from "@blade-and-brawn/domain";
|
||||||
|
import type { VerificationStatus } from "@blade-and-brawn/api";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { PageProps } from "./$types";
|
||||||
|
|
||||||
|
async function loadVerification(id: string) {
|
||||||
|
return await api.verifications({ id }).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
type VerificationDetail = NonNullable<
|
||||||
|
Awaited<ReturnType<typeof loadVerification>>["data"]
|
||||||
|
>;
|
||||||
|
type VerfChoice = "unset" | "pass" | "fail";
|
||||||
|
|
||||||
|
const ACTIVITIES = Object.values(Activity);
|
||||||
|
|
||||||
|
const STATUS_BADGE: Record<VerificationStatus, string> = {
|
||||||
|
draft: "badge-ghost",
|
||||||
|
submitted: "badge-info",
|
||||||
|
in_review: "badge-warning",
|
||||||
|
action_requested: "badge-error",
|
||||||
|
completed: "badge-success",
|
||||||
|
};
|
||||||
|
|
||||||
|
const VERF_COLUMN = {
|
||||||
|
[Activity.BackSquat]: "verf_back_squat",
|
||||||
|
[Activity.Deadlift]: "verf_deadlift",
|
||||||
|
[Activity.BenchPress]: "verf_bench_press",
|
||||||
|
[Activity.Run]: "verf_run",
|
||||||
|
[Activity.BroadJump]: "verf_broad_jump",
|
||||||
|
[Activity.ConeDrill]: "verf_cone_drill",
|
||||||
|
} as const satisfies Record<Activity, keyof VerificationDetail>;
|
||||||
|
|
||||||
|
const PERF_COLUMN = {
|
||||||
|
[Activity.BackSquat]: "perf_back_squat",
|
||||||
|
[Activity.Deadlift]: "perf_deadlift",
|
||||||
|
[Activity.BenchPress]: "perf_bench_press",
|
||||||
|
[Activity.Run]: "perf_run",
|
||||||
|
[Activity.BroadJump]: "perf_broad_jump",
|
||||||
|
[Activity.ConeDrill]: "perf_cone_drill",
|
||||||
|
} as const satisfies Record<Activity, keyof VerificationDetail>;
|
||||||
|
|
||||||
|
function formatPerformance(activity: Activity, value: number | null): string {
|
||||||
|
if (value === null) return "—";
|
||||||
|
switch (activity) {
|
||||||
|
case Activity.BackSquat:
|
||||||
|
case Activity.Deadlift:
|
||||||
|
case Activity.BenchPress:
|
||||||
|
return `${Math.round(kgToLb(value))} lb`;
|
||||||
|
case Activity.Run: {
|
||||||
|
const totalSeconds = Math.floor(value / 1000);
|
||||||
|
const minutes = Math.floor(totalSeconds / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
return `${minutes}m ${seconds}s`;
|
||||||
|
}
|
||||||
|
case Activity.ConeDrill:
|
||||||
|
return `${(value / 1000).toFixed(2)} seconds`;
|
||||||
|
case Activity.BroadJump: {
|
||||||
|
const inches = cmToIn(value);
|
||||||
|
const ft = Math.floor(inches / 12);
|
||||||
|
const rem = Math.round((inches - ft * 12) * 2) / 2;
|
||||||
|
return `${ft}' ${rem}"`;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return "—";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function verfChoiceFrom(value: boolean | null): VerfChoice {
|
||||||
|
if (value === true) return "pass";
|
||||||
|
if (value === false) return "fail";
|
||||||
|
return "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toActivityVerifications(
|
||||||
|
choices: Record<Activity, VerfChoice>,
|
||||||
|
): ActivityVerifications {
|
||||||
|
const result: ActivityVerifications = {};
|
||||||
|
for (const activity of ACTIVITIES) {
|
||||||
|
if (choices[activity] === "pass") result[activity] = true;
|
||||||
|
else if (choices[activity] === "fail") result[activity] = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSize(bytes: number | undefined): string {
|
||||||
|
if (bytes === undefined) return "—";
|
||||||
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(value: string | undefined): string {
|
||||||
|
return value ? new Date(value).toLocaleString() : "—";
|
||||||
|
}
|
||||||
|
|
||||||
|
function errorMessage(err: unknown): string {
|
||||||
|
const value = (err as { value?: { error?: string } })?.value;
|
||||||
|
return (
|
||||||
|
value?.error ??
|
||||||
|
(err instanceof Error ? err.message : "Unknown error")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let { params }: PageProps = $props();
|
||||||
|
const id = $derived(params.id);
|
||||||
|
|
||||||
|
let verification = $state<VerificationDetail | null>(null);
|
||||||
|
let loading = $state(true);
|
||||||
|
let loadError = $state<string | null>(null);
|
||||||
|
let notes = $state("");
|
||||||
|
let verf = $state<Record<Activity, VerfChoice>>(
|
||||||
|
Object.fromEntries(ACTIVITIES.map((a) => [a, "unset"])) as Record<
|
||||||
|
Activity,
|
||||||
|
VerfChoice
|
||||||
|
>,
|
||||||
|
);
|
||||||
|
let submitting = $state<"action" | "complete" | undefined>();
|
||||||
|
let submitError = $state<string | null>(null);
|
||||||
|
|
||||||
|
const reviewedCount = $derived(
|
||||||
|
ACTIVITIES.filter((a) => verf[a] !== "unset").length,
|
||||||
|
);
|
||||||
|
const allReviewed = $derived(reviewedCount === ACTIVITIES.length);
|
||||||
|
const isReadOnly = $derived(
|
||||||
|
verification?.status !== "submitted" &&
|
||||||
|
verification?.status !== "in_review",
|
||||||
|
);
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading = true;
|
||||||
|
loadError = null;
|
||||||
|
try {
|
||||||
|
const res = await loadVerification(id);
|
||||||
|
if (res.error) throw res.error;
|
||||||
|
if (!res.data) throw new Error("Verification not found");
|
||||||
|
verification = res.data;
|
||||||
|
notes = verification.reviewer_notes ?? "";
|
||||||
|
verf = Object.fromEntries(
|
||||||
|
ACTIVITIES.map((a) => [
|
||||||
|
a,
|
||||||
|
verfChoiceFrom(verification![VERF_COLUMN[a]]),
|
||||||
|
]),
|
||||||
|
) as Record<Activity, VerfChoice>;
|
||||||
|
} catch (err) {
|
||||||
|
loadError = errorMessage(err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleVerf(activity: Activity, choice: VerfChoice) {
|
||||||
|
if (isReadOnly) return;
|
||||||
|
verf[activity] = verf[activity] === choice ? "unset" : choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requestAction() {
|
||||||
|
submitting = "action";
|
||||||
|
submitError = null;
|
||||||
|
try {
|
||||||
|
const res = await api
|
||||||
|
.verifications({ id })
|
||||||
|
["request-action"].post({
|
||||||
|
reviewerNotes: notes || undefined,
|
||||||
|
activityVerifications: toActivityVerifications(verf),
|
||||||
|
});
|
||||||
|
if (res.error) throw res.error;
|
||||||
|
await goto("/verification/verifications");
|
||||||
|
} catch (err) {
|
||||||
|
submitError = errorMessage(err);
|
||||||
|
} finally {
|
||||||
|
submitting = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function complete() {
|
||||||
|
submitting = "complete";
|
||||||
|
submitError = null;
|
||||||
|
try {
|
||||||
|
const res = await api.verifications({ id }).complete.post({
|
||||||
|
activityVerifications: toActivityVerifications(verf),
|
||||||
|
});
|
||||||
|
if (res.error) throw res.error;
|
||||||
|
await goto("/verification/verifications");
|
||||||
|
} catch (err) {
|
||||||
|
submitError = errorMessage(err);
|
||||||
|
} finally {
|
||||||
|
submitting = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(load);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="w-full mt-10 mb-5">
|
||||||
|
<a
|
||||||
|
href="/verification/verifications"
|
||||||
|
class="link link-hover text-sm opacity-70">← Back to verifications</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if loading}
|
||||||
|
<div class="w-full flex justify-center pt-10">
|
||||||
|
<span class="loading loading-spinner loading-lg"></span>
|
||||||
|
</div>
|
||||||
|
{:else if loadError}
|
||||||
|
<div role="alert" class="alert alert-error w-full mb-4">
|
||||||
|
<span>{loadError}</span>
|
||||||
|
</div>
|
||||||
|
{:else if verification}
|
||||||
|
{@const v = verification}
|
||||||
|
<div class="w-full flex items-center gap-3 flex-wrap mb-6">
|
||||||
|
<h1 class="text-xl font-semibold">{v.name}</h1>
|
||||||
|
<div class="badge {STATUS_BADGE[v.status as VerificationStatus]}">
|
||||||
|
{v.status}
|
||||||
|
</div>
|
||||||
|
<span class="text-sm opacity-70"
|
||||||
|
>{v.gender} · age {v.age} · {Math.round(kgToLb(v.weight))} lb</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full flex flex-col gap-4 bg-base-200/60 rounded-lg p-6">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<h2 class="text-lg font-semibold">Activities</h2>
|
||||||
|
<span class="text-sm opacity-70"
|
||||||
|
>{reviewedCount} / {ACTIVITIES.length} reviewed</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Activity</th>
|
||||||
|
<th>Claimed</th>
|
||||||
|
<th>Result</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each ACTIVITIES as activity (activity)}
|
||||||
|
<tr>
|
||||||
|
<td>{activity}</td>
|
||||||
|
<td class="font-semibold">
|
||||||
|
{formatPerformance(
|
||||||
|
activity,
|
||||||
|
v[PERF_COLUMN[activity]],
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="join">
|
||||||
|
<button
|
||||||
|
class="btn btn-xs join-item {verf[
|
||||||
|
activity
|
||||||
|
] === 'pass'
|
||||||
|
? 'btn-success'
|
||||||
|
: 'btn-outline btn-success'}"
|
||||||
|
disabled={isReadOnly}
|
||||||
|
onclick={() =>
|
||||||
|
toggleVerf(activity, "pass")}
|
||||||
|
>
|
||||||
|
Pass
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn btn-xs join-item {verf[
|
||||||
|
activity
|
||||||
|
] === 'fail'
|
||||||
|
? 'btn-error'
|
||||||
|
: 'btn-outline btn-error'}"
|
||||||
|
disabled={isReadOnly}
|
||||||
|
onclick={() =>
|
||||||
|
toggleVerf(activity, "fail")}
|
||||||
|
>
|
||||||
|
Fail
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full flex flex-col gap-4 bg-base-200/60 rounded-lg p-6 mt-4">
|
||||||
|
<h2 class="text-lg font-semibold">Media ({v.media.length})</h2>
|
||||||
|
|
||||||
|
{#if v.media.length === 0}
|
||||||
|
<span class="opacity-60">No media uploaded</span>
|
||||||
|
{:else}
|
||||||
|
<ul class="flex flex-col gap-2">
|
||||||
|
{#each v.media as file, i (file.key)}
|
||||||
|
<li class="flex items-center gap-3 flex-wrap">
|
||||||
|
<a
|
||||||
|
class="link link-primary"
|
||||||
|
href={file.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
File {i + 1}
|
||||||
|
</a>
|
||||||
|
<span class="text-xs opacity-60">
|
||||||
|
{formatSize(file.size)} · uploaded {formatDate(
|
||||||
|
file.lastModified,
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full flex flex-col gap-4 bg-base-200/60 rounded-lg p-6 mt-4">
|
||||||
|
<label class="form-control">
|
||||||
|
<span class="label mb-1 text-xs">Reviewer notes</span>
|
||||||
|
<textarea
|
||||||
|
class="textarea textarea-bordered w-full"
|
||||||
|
rows="3"
|
||||||
|
placeholder="What needs to be fixed?"
|
||||||
|
disabled={isReadOnly}
|
||||||
|
bind:value={notes}
|
||||||
|
></textarea>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{#if submitError}
|
||||||
|
<div role="alert" class="alert alert-error">
|
||||||
|
<span>{submitError}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2 justify-end">
|
||||||
|
{#if isReadOnly}
|
||||||
|
<span class="text-sm opacity-70">
|
||||||
|
{v.status === "completed"
|
||||||
|
? "This verification is completed and read-only."
|
||||||
|
: v.status === "draft"
|
||||||
|
? "This verification is still a draft (the player hasn't finished uploading) and is read-only."
|
||||||
|
: "This verification is waiting on the player to resubmit and is read-only."}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
{#if !allReviewed}
|
||||||
|
<span class="text-xs text-warning"
|
||||||
|
>Mark every activity Pass or Fail to complete</span
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
<button
|
||||||
|
class="btn btn-warning"
|
||||||
|
disabled={!!submitting}
|
||||||
|
onclick={requestAction}
|
||||||
|
>
|
||||||
|
{submitting === "action" ? "Submitting..." : "Request action"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn btn-success"
|
||||||
|
disabled={!!submitting || !allReviewed}
|
||||||
|
onclick={complete}
|
||||||
|
>
|
||||||
|
{submitting === "complete" ? "Submitting..." : "Complete"}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
Reference in New Issue
Block a user