Skip to content

Add Quiz Taking UI #3103

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

Merged
merged 22 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b9f5560
style (Taking Quiz): update style for taking quiz [page
Puppychan Jun 15, 2025
4289697
style (Taking Quiz UI): add styling for before taking quiz
Puppychan Jun 15, 2025
8cdede6
feat (Taking Quiz UI): add taking quiz button, dark light styling
Puppychan Jun 16, 2025
1d0ce00
feat (Taking Quiz UI): add translation
Puppychan Jun 16, 2025
0d51335
ops (Taking Quiz UI): fix deploy
Puppychan Jun 16, 2025
ba85695
ops (Taking Quiz UI): fix deploy
Puppychan Jun 16, 2025
c682863
ops (Taking Quiz UI): fix deploy
Puppychan Jun 16, 2025
c4e13b3
Merge branch 'main' into feat/upskii/taking-quiz-ui
Puppychan Jun 16, 2025
05f7737
style: apply prettier formatting
Puppychan Jun 16, 2025
40fb721
style: apply prettier formatting for feat/upskii/taking-quiz-ui (#3104)
Puppychan Jun 16, 2025
b625bf7
fix (Taking Quiz UI): fix UI displayed when max attempt limit reached
Puppychan Jun 18, 2025
574faea
Merge remote-tracking branch 'origin/feat/upskii/taking-quiz-ui' into…
Puppychan Jun 18, 2025
d218347
style(Taking Quiz UI - Answering Question): styling for input and que…
Puppychan Jun 18, 2025
6c92781
style(Taking Quiz UI - Answering Question): styling for displaying sc…
Puppychan Jun 18, 2025
90fc234
fix (Taking Quiz UI): fix deploy
Puppychan Jun 18, 2025
e1c7076
fix (Taking Quiz UI): duration not recorded to backend
Puppychan Jun 18, 2025
a025cae
revert(Taking Quiz UI): revert working form
Puppychan Jun 18, 2025
d465f77
style: apply prettier formatting
Puppychan Jun 18, 2025
ee415ea
style: apply prettier formatting for feat/upskii/taking-quiz-ui (#3114)
Puppychan Jun 18, 2025
d762d19
Merge branch 'main' into feat/upskii/taking-quiz-ui
vhpx Jun 18, 2025
cc0b7f2
chore(db): consolidate database schema
vhpx Jun 18, 2025
e2d71dd
refactor: standardize customer ID naming and update database schema f…
vhpx Jun 18, 2025
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
11 changes: 11 additions & 0 deletions apps/db/supabase/migrations/20250615100747_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
alter table "public"."workspace_quiz_attempts" add column "duration_seconds" integer;

alter table "public"."workspace_quiz_attempts" add column "submitted_at" timestamp with time zone not null default now();

alter table "public"."workspace_quiz_sets" add column "available_date" timestamp with time zone not null default now();

alter table "public"."workspace_quiz_sets" add column "explanation_mode" smallint not null default 0;

alter table "public"."workspace_quiz_sets" add column "instruction" jsonb;


3 changes: 3 additions & 0 deletions apps/db/supabase/migrations/20250615104201_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table "public"."workspace_quizzes" add column "instruction" jsonb;


3 changes: 3 additions & 0 deletions apps/db/supabase/migrations/20250615190931_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table "public"."workspace_quiz_sets" add column "results_released" boolean not null default false;


5 changes: 5 additions & 0 deletions apps/db/supabase/migrations/20250616085119_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."workspace_quiz_sets" drop column "release_points_immediately";

alter table "public"."workspace_quiz_sets" add column "allow_view_old_attempts" boolean not null default true;


Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default async function UserGroupDetailsPage({ params }: Props) {
<div className="grid gap-4 pt-2 md:grid-cols-2">
<ClientQuizzes
wsId={wsId}
courseId={courseId}
moduleId={moduleId}
quizSets={quizSets}
previewMode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// File: app/[locale]/(dashboard)/[wsId]/quiz-sets/[setId]/result/show-attempt-detail-section.tsx
'use client';

import { Card, CardContent, CardHeader, CardTitle } from '@tuturuuu/ui/card';
import { CheckCircle, Circle, XCircle } from 'lucide-react';

// File: app/[locale]/(dashboard)/[wsId]/quiz-sets/[setId]/result/show-attempt-detail-section.tsx

export interface AttemptDetailDTO {
attemptId: string;
attemptNumber: number;
totalScore: number;
maxPossibleScore: number;
startedAt: string;
completedAt: string | null;
durationSeconds: number;
explanationMode: 0 | 1 | 2;
questions: Array<{
quizId: string;
question: string;
scoreWeight: number;
/** Now optional */
selectedOptionId?: string | null;
isCorrect: boolean;
scoreAwarded: number;
options: Array<{
id: string;
value: string;
isCorrect: boolean;
explanation: string | null;
}>;
}>;
}

export interface ShowAttemptDetailProps {
t: (key: string) => string;
detail: AttemptDetailDTO;
}

export default function ShowAttemptDetailSection({
t,
detail,
}: ShowAttemptDetailProps) {
const fmtDate = (iso: string | null) =>
iso ? new Date(iso).toLocaleString() : '—';
const fmtDuration = (secs: number) => {
const m = Math.floor(secs / 60)
.toString()
.padStart(2, '0');
const s = (secs % 60).toString().padStart(2, '0');
return `${m}:${s}`;
};

return (
<div className="space-y-8">
{/* Metadata */}
<div className="space-y-1 text-sm text-secondary-foreground">
<div>
{t('ws-quizzes.started_at') || 'Started at'}:{' '}
{fmtDate(detail.startedAt)}
</div>
{detail.completedAt && (
<div>
{t('ws-quizzes.completed_at') || 'Completed at'}:{' '}
{fmtDate(detail.completedAt)}
</div>
)}
<div>
{t('ws-quizzes.duration') || 'Duration'}:{' '}
{fmtDuration(detail.durationSeconds)}
</div>
</div>

{/* Questions */}
{detail.questions.map((q, idx) => {
const selId = q.selectedOptionId ?? null;
return (
<Card
key={q.quizId}
className={
!q.isCorrect
? 'border-dynamic-light-red/40 bg-dynamic-light-pink/15'
: ''
}
>
<CardHeader>
<CardTitle>
{idx + 1}. {q.question}{' '}
<span className="text-sm text-muted-foreground">
({t('ws-quizzes.points') || 'Points'}: {q.scoreWeight})
</span>
</CardTitle>
</CardHeader>
<CardContent className="space-y-2 md:space-y-4">
{q.options.map((opt) => {
const chosen = selId === opt.id;
return (
<div
key={opt.id}
className="flex items-center space-x-2 rounded-md border border-dynamic-purple/40 p-2 transition-colors hover:bg-secondary/10 md:space-x-4 md:p-4"
aria-label={`${opt.value} ${
opt.isCorrect
? t('ws-quizzes.correct_option') || '(Correct)'
: chosen
? t('ws-quizzes.your_answer') || '(Your answer)'
: ''
}`}
>
{opt.isCorrect ? (
<CheckCircle className="h-5 w-5 text-green-500" />
) : chosen ? (
<XCircle className="h-5 w-5 text-dynamic-light-red" />
) : (
<Circle className="h-5 w-5 text-gray-400" />
)}
<div className="flex flex-col">
<span className={chosen ? 'font-semibold' : undefined}>
{opt.value}{' '}
{opt.isCorrect && (
<small className="text-green-600">
{t('ws-quizzes.correct') || '(Correct)'}
</small>
)}
{chosen && !opt.isCorrect && (
<small className="text-dynamic-light-red">
{t('ws-quizzes.your_answer') || '(Your answer)'}
</small>
)}
</span>
{opt.explanation && (
<p className="mt-1 text-sm text-primary">
{opt.explanation}
</p>
)}
</div>
</div>
);
})}

<div className={`mt-3 text-sm text-center md:text-right ${q.isCorrect ? "text-green-600" : "text-dynamic-light-red"}`}>
{t('ws-quizzes.score_awarded') || 'Score Awarded'}:{' '}
<strong>
{q.scoreAwarded} / {q.scoreWeight}
</strong>
</div>
</CardContent>
</Card>
);
})}
</div>
);
}
Loading
Loading