Module Update
This commit is contained in:
@@ -18,6 +18,16 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# 1. ๅขๅ Cache ็ญ็ฅ๏ผๆพ่ๅ ๅฟซ npm ci ้ๅบฆ
|
||||
- name: Cache npm dependencies
|
||||
uses: actions/cache@v3
|
||||
id: npm-cache
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
@@ -27,6 +37,18 @@ jobs:
|
||||
- name: Typecheck
|
||||
run: npm run typecheck
|
||||
|
||||
# 2. ๅขๅ Next.js ๆๅปบ็ผๅญ
|
||||
- name: Cache Next.js build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.npm
|
||||
${{ github.workspace }}/.next/cache
|
||||
# Generate a new cache whenever packages or source files change.
|
||||
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
@@ -35,7 +57,7 @@ jobs:
|
||||
# echo "======================="
|
||||
# echo "1. Root directory files:"
|
||||
# ls -la
|
||||
|
||||
#
|
||||
# echo "======================="
|
||||
# echo "2. Checking .next directory:"
|
||||
# if [ -d ".next" ]; then
|
||||
@@ -58,10 +80,10 @@ jobs:
|
||||
cp -r .next/static/* .next/standalone/.next/static/
|
||||
cp Dockerfile .next/standalone/Dockerfile
|
||||
|
||||
- name: ๐ Debug - List Build Files
|
||||
run: |
|
||||
echo "======================="
|
||||
ls -la .next/standalone
|
||||
# - name: ๐ Debug - List Build Files
|
||||
# run: |
|
||||
# echo "======================="
|
||||
# ls -la .next/standalone
|
||||
|
||||
- name: Upload production build artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
@@ -83,8 +105,21 @@ jobs:
|
||||
|
||||
- name: Deploy to Docker
|
||||
run: |
|
||||
docker build -t nextjs-app .
|
||||
# 1. ไฝฟ็จ --no-cache ้ฒๆญขไฝฟ็จๆง็ๆๅปบๅฑ๏ผ็กฎไฟ้จ็ฝฒ็ๆฏๆๆฐไปฃ็
|
||||
# 2. ไฝฟ็จ --pull ็กฎไฟๅบ็ก้ๅๆฏๆๆฐ็
|
||||
docker build --no-cache --pull -t nextjs-app .
|
||||
|
||||
# 3. ไผ้
ๅๆญข๏ผๅ
ๅฐ่ฏ stop๏ผๅฆๆๅคฑ่ดฅๅๆ ้ๅค็ (|| true)
|
||||
docker stop nextjs-app || true
|
||||
docker rm nextjs-app || true
|
||||
docker run -d -p 8015:3000 --restart unless-stopped --name nextjs-app nextjs-app
|
||||
|
||||
# 4. ่ฟ่กๅฎนๅจ๏ผ
|
||||
# --init: ่งฃๅณ Node.js PID 1 ๅตๅฐธ่ฟ็จ้ฎ้ข
|
||||
# --restart unless-stopped: ่ชๅจ้ๅฏ็ญ็ฅ
|
||||
docker run -d \
|
||||
--init \
|
||||
-p 8015:3000 \
|
||||
--restart unless-stopped \
|
||||
--name nextjs-app \
|
||||
nextjs-app
|
||||
|
||||
|
||||
332
ARCHITECTURE.md
Normal file
332
ARCHITECTURE.md
Normal file
@@ -0,0 +1,332 @@
|
||||
# Next_Edu Architecture RFC
|
||||
|
||||
**Status**: PROPOSED
|
||||
**Date**: 2025-12-22
|
||||
**Author**: Principal Software Architect
|
||||
**Version**: 1.0.0
|
||||
|
||||
---
|
||||
|
||||
## 1. ๆ ธๅฟๅๅ (Core Principles)
|
||||
|
||||
ๆฌๆถๆ่ฎพ่ฎก้ตๅพชไปฅไธๆ ธๅฟๅๅ๏ผๆจๅจๆๅปบไธไธช้ซๆง่ฝใๅฏๆฉๅฑใๆ็ปดๆค็ไผไธ็บงๅจ็บฟๆ่ฒๅนณๅฐใ
|
||||
|
||||
1. **Vertical Slice Architecture (ๅ็ดๅ็)**: ๆ็ปไผ ็ป็ๆๆๆฏๅๅฑ๏ผLayered Architecture๏ผ๏ผ้็จๆไธๅกๅ่ฝๅๅฑใไปฃ็ ๅบๆ นๆฎโๅฎๅฑไบๅชไธชๅ่ฝโ่ไธๆฏโๅฎๆฏไปไนๆไปถโๆฅ็ป็ปใ
|
||||
2. **Type Safety First (็ฑปๅๅฎๅ
จไผๅ
)**: ๅ
จ้พ่ทฏ TypeScript (Strict Mode)ใไปๆฐๆฎๅบ Schema ๅฐ API ๅๅฐ UI ็ปไปถ๏ผๅฟ
้กปไฟๆ็ฑปๅไธ่ดๆงใ
|
||||
3. **Server-First (ๆๅก็ซฏไผๅ
)**: ๅ
ๅๅฉ็จ Next.js 15 App Router ็ RSC (React Server Components) ่ฝๅ๏ผๅๅฐๅฎขๆท็ซฏ Bundle ไฝ็งฏใ
|
||||
4. **Performance by Default (้ป่ฎค้ซๆง่ฝ)**: ไธฅ็ฆๅผๅ
ฅ้ๅๅจ็ปๅบ๏ผๅจๆไผๅ
ไฝฟ็จ CSS Native ๅฎ็ฐใWeb Vitals ๆๆ ไฝไธบ CI ้ปๆญๆ ๅใ
|
||||
5. **Strict Engineering (ไธฅๆ ผๅทฅ็จๅ)**: CI/CD ๆต็จๆ ๅๅ๏ผไปฃ็ ้ฃๆ ผ็ปไธ๏ผ่ชๅจๅๆต่ฏ่ฆ็ใ
|
||||
|
||||
---
|
||||
|
||||
## 2. ๆๆฏๆ ๅ
จๆฏๅพ (Technology Panorama)
|
||||
|
||||
### ๆ ธๅฟๆกๆถ
|
||||
* **Framework**: Next.js 15 (App Router)
|
||||
* **Language**: TypeScript 5.x (Strict Mode enabled)
|
||||
* *Correction*: ้ดไบ Next.js App Router ็็นๆง๏ผ`.tsx` ไป
็จไบๅ
ๅซ JSX ็็ปไปถๆไปถใๆๆ็ไธๅก้ป่พใHooksใAPI ่ทฏ็ฑใLib ๅทฅๅ
ทๅฝๆฐๅฟ
้กปไฝฟ็จ `.ts` ๅ็ผ๏ผไปฅๆ็กฎๅบๅโๆธฒๆๅฑโไธโ้ป่พๅฑโใ
|
||||
* **Runtime**: Node.js 20.x (LTS)
|
||||
|
||||
### ๆฐๆฎๅฑ
|
||||
* **Database**: MySQL 8.0+
|
||||
* **ORM**: Drizzle ORM (่ฝป้ใๆ ่ฟ่กๆถๅผ้ใ็ฑปๅๅฎๅ
จ)
|
||||
* **Driver**: `mysql2` (้
ๅ่ฟๆฅๆฑ ) ๆ `serverless-mysql` (้ๅฏน็นๅฎ Serverless ็ฏๅข)
|
||||
* **Validation**: Zod (Schema ๅฎไนไธ่ฟ่กๆถ้ช่ฏ)
|
||||
|
||||
### UI/UX ๅฑ
|
||||
* **Styling**: Tailwind CSS v3.4+
|
||||
* **Components**: Shadcn/UI (ๅบไบ Radix UI ็ Headless ็ปไปถๆท่ด)
|
||||
* **Icons**: Lucide React
|
||||
* **Animations**: CSS Transitions / Tailwind `animate-*` / `tailwindcss-animate`
|
||||
* *Complex Interactions*: Framer Motion (ไป
้ๆ้ๅ ่ฝฝ `LazyMotion`)
|
||||
|
||||
### ่บซไปฝ้ช่ฏไธๆๆ
|
||||
* **Auth**: Auth.js v5 (NextAuth)
|
||||
* *Decision Driver*: ็ธๆฏ Clerk๏ผAuth.js ๆไพไบๅฎๅ
จ็**ๆฐๆฎๆๆๆ**ๅ**ๆ Vendor Lock-in**ใ
|
||||
* *Enterprise Needs*: ๅ
่ฎธ่ชๅฎไน Session ็ปๆ๏ผๅฆๆณจๅ
ฅ `Role` ๅญๆฎต๏ผๅนถ็ดๆฅๅฏนๆฅ็ฐๆ MySQL ๆฐๆฎๅบ๏ผๆปก่ถณๅคๆ็ไผไธ็บงๆ้็ฎก็้ๆฑใ
|
||||
|
||||
### ็ถๆ็ฎก็
|
||||
* **Server State**: TanStack Query v5 (ไป
็จไบๅคๆๅฎขๆท็ซฏ่ฝฎ่ฏข/ๆ ้ๅ ่ฝฝ)
|
||||
* **URL State (Primary)**: Nuqs (Type-safe search params state manager)
|
||||
* *Principle*: ็ปๅคงๅคๆฐ็ถๆ๏ผ็ญ้ใๅ้กตใTab๏ผๅบๅญๅจ URL ไธญ๏ผไปฅๆฏๆๅไบซๅไนฆ็ญพใ
|
||||
* **Global Client State (Secondary)**: Zustand
|
||||
* *Usage*: ไป
้ๆๅฐๆฐๅ
จๅฑไบคไบ็ถๆ๏ผๅฆๆญๆพๅจๆฌๆตฎ็ชใๅ
จๅฑ Modal๏ผใ
|
||||
* *Anti-pattern*: **ไธฅ็ฆไฝฟ็จ Redux**ใ้ฟๅ
ไธๅฟ
่ฆ็ๆ ทๆฟไปฃ็ ๅ Bundle ไฝ็งฏใ
|
||||
|
||||
### ๅบ็ก่ฎพๆฝ & DevOps
|
||||
* **CI/CD**: GitHub Actions (Strictly v3)
|
||||
* **Linting**: ESLint (Next.js config), Prettier
|
||||
* **Package Manager**: pnpm (ๆจ่) ๆ npm
|
||||
|
||||
---
|
||||
|
||||
## 3. ้กน็ฎ็ฎๅฝ็ปๆ่ง่ (Project Structure)
|
||||
|
||||
้็จ **Feature-based / Vertical Slice** ๆถๆใๆๆไธๅก้ป่พๅบๅฐ่ฃ
ๅจ `src/modules` ไธญใ
|
||||
|
||||
ๆๆกฃๅญๆพไฝ็ฝฎ:
|
||||
* ๆถๆ่ฎพ่ฎกๆๆกฃ: `docs/architecture/`
|
||||
* API ่ง่ๆๆกฃ: `docs/api/`
|
||||
|
||||
### ็ฎๅฝๆ (Directory Tree)
|
||||
|
||||
```
|
||||
Next_Edu/
|
||||
โโโ .github/
|
||||
โ โโโ workflows/
|
||||
โ โโโ ci.yml # GitHub Actions (v3 strict)
|
||||
โโโ docs/
|
||||
โ โโโ architecture/ # ๆถๆๅณ็ญ่ฎฐๅฝ (ADR)
|
||||
โโโ drizzle/ # ๆฐๆฎๅบ่ฟ็งปๆไปถ (Generated)
|
||||
โโโ public/ # ้ๆ่ตๆบ
|
||||
โโโ src/
|
||||
โ โโโ app/ # [่ทฏ็ฑๅฑ] ๆ่๏ผไป
่ด่ดฃ่ทฏ็ฑๅๅๅๅธๅฑ
|
||||
โ โ โโโ (auth)/ # ่ทฏ็ฑ็ป
|
||||
โ โ โโโ (dashboard)/
|
||||
โ โ โโโ api/ # Webhooks / External APIs
|
||||
โ โ โโโ layout.tsx
|
||||
โ โ โโโ page.tsx
|
||||
โ โ
|
||||
โ โโโ modules/ # [ๆ ธๅฟไธๅกๅฑ] ๅ็ดๅ็
|
||||
โ โ โโโ courses/ # ่ฏพ็จๆจกๅ
|
||||
โ โ โ โโโ components/ # ๆจกๅ็งๆ็ปไปถ (CourseCard, Player)
|
||||
โ โ โ โโโ actions.ts # Server Actions (ไธๅก้ป่พๅ
ฅๅฃ)
|
||||
โ โ โ โโโ service.ts # ้ขๅๆๅก (ๅฏ้๏ผๅคๆ้ป่พๆๅ)
|
||||
โ โ โ โโโ data-access.ts # ๆฐๆฎๅบๆฅ่ฏข (DTOs)
|
||||
โ โ โ โโโ types.ts # ๆจกๅ็งๆ็ฑปๅ
|
||||
โ โ โ
|
||||
โ โ โโโ users/ # ็จๆทๆจกๅ
|
||||
โ โ โโโ payments/ # ๆฏไปๆจกๅ
|
||||
โ โ โโโ community/ # ็คพๅบๆจกๅ
|
||||
โ โ
|
||||
โ โโโ shared/ # [ๅ
ฑไบซๅฑ] ไป
ๅญๆพ็ๆญฃ้็จ็ไปฃ็
|
||||
โ โ โโโ components/ # ้็จ UI (Button, Dialog - Shadcn)
|
||||
โ โ โโโ lib/ # ้็จๅทฅๅ
ท (utils, date formatting)
|
||||
โ โ โโโ db/ # Drizzle Client & Schema
|
||||
โ โ โ โโโ index.ts # DB ่ฟๆฅๅฎไพ
|
||||
โ โ โ โโโ schema.ts # ๅ
จๅฑ Schema ๅฎไน (ๆๆๆจกๅๆๅๅฏผๅบ)
|
||||
โ โ โโโ hooks/ # ้็จ Hooks
|
||||
โ โ
|
||||
โ โโโ env.mjs # ็ฏๅขๅ้็ฑปๅๆฃๆฅ
|
||||
โ โโโ middleware.ts # ่พน็ผไธญ้ดไปถ (Auth check)
|
||||
โโโ drizzle.config.ts # Drizzle ้
็ฝฎๆไปถ
|
||||
โโโ next.config.mjs
|
||||
โโโ package.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. ๆฐๆฎๅบๅฑ่ฎพ่ฎก (Database Strategy)
|
||||
|
||||
### ่ฟๆฅ้
็ฝฎ (Connection Pooling)
|
||||
ๅจ Next.js ็ Serverless/Edge ็ฏๅขไธญ๏ผ็ดๆฅ่ฟๆฅ MySQL ๅฏ่ฝๅฏผ่ด่ฟๆฅๆฐ่ๅฐฝใๆไปฌ้ๅไปฅไธ็ญ็ฅ๏ผ
|
||||
|
||||
1. **ๅผๅ็ฏๅข**: ไฝฟ็จ Global Singleton ๆจกๅผ้ฒๆญข Hot Reload ๅฏผ่ด่ฟๆฅๆณ้ฒใ
|
||||
2. **็ไบง็ฏๅข**:
|
||||
* ๆจ่ไฝฟ็จๆฏๆ HTTP ่ฟๆฅๆๅ
็ฝฎ่ฟๆฅๆฑ ็ Serverless MySQL ๆนๆก (ๅฆ PlanetScale)ใ
|
||||
* ่ฅไฝฟ็จๆ ๅ MySQL๏ผๅฟ
้กป้
็ฝฎ่ฟๆฅๆฑ (`connectionLimit`) ๅนถๅ็่ฎพ็ฝฎ็ฉบ้ฒ่ถ
ๆถใ
|
||||
|
||||
**ไปฃ็ ็คบไพ (`src/shared/db/index.ts`)**:
|
||||
|
||||
```typescript
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import mysql from "mysql2/promise";
|
||||
import * as schema from "./schema";
|
||||
|
||||
// Global cache to prevent connection exhaustion in development
|
||||
const globalForDb = globalThis as unknown as {
|
||||
conn: mysql.Pool | undefined;
|
||||
};
|
||||
|
||||
const poolConnection = globalForDb.conn ?? mysql.createPool({
|
||||
uri: process.env.DATABASE_URL,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10, // ๆ นๆฎๆฐๆฎๅบ่งๆ ผ่ฐๆด
|
||||
queueLimit: 0
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForDb.conn = poolConnection;
|
||||
|
||||
export const db = drizzle(poolConnection, { schema, mode: "default" });
|
||||
```
|
||||
|
||||
### Migration ็ญ็ฅ
|
||||
* ไฝฟ็จ `drizzle-kit` ่ฟ่ก่ฟ็งป็ฎก็ใ
|
||||
* ไธฅ็ฆๅจ็ไบง็ฏๅข่ฟ่กๆถ่ชๅจๆง่ก Migrationใ
|
||||
* **ๆต็จ**:
|
||||
1. ไฟฎๆน Schema (`schema.ts`).
|
||||
2. ่ฟ่ก `pnpm drizzle-kit generate` ็ๆ SQL ๆไปถใ
|
||||
3. Review SQL ๆไปถใ
|
||||
4. ๅจ CI/CD ้จ็ฝฒๅ็ฝฎๆญฅ้ชคๆๆๅจ่ฟ่ก `pnpm drizzle-kit migrate`ใ
|
||||
|
||||
### Server Components ไธญ็ๆฐๆฎๆฅ่ฏข
|
||||
* **Colocation**: ๆฅ่ฏข้ป่พๅบๅฐฝ้้ ่ฟไฝฟ็จๅฎ็็ปไปถ๏ผๆ่
ๅฐ่ฃ
ๅจ `data-access.ts` ไธญใ
|
||||
* **Request Memoization**: ๅณไฝฟๅจไธไธช่ฏทๆฑไธญๅคๆฌก่ฐ็จ็ธๅ็ๆฅ่ฏขๅฝๆฐ๏ผNext.js ็ `cache` (ๆ React `cache`) ไนไผ่ชๅจๅป้ใ
|
||||
|
||||
```typescript
|
||||
// src/modules/courses/data-access.ts
|
||||
import { cache } from 'react';
|
||||
import { db } from '@/shared/db';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { courses } from '@/shared/db/schema';
|
||||
|
||||
// ไฝฟ็จ React cache ็กฎไฟๅๆฌก่ฏทๆฑๅ
็ๅป้
|
||||
export const getCourseById = cache(async (id: string) => {
|
||||
return await db.query.courses.findFirst({
|
||||
where: eq(courses.id, id),
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. UI/UX ๅจๆ่ง่ (Animation Guidelines)
|
||||
|
||||
### ๆ ธๅฟ็ญ็ฅ
|
||||
* **CSS Native First**: 90% ็ไบคไบ้่ฟ CSS `transition` ๅ `animation` ๅฎ็ฐใ
|
||||
* **Hardware Acceleration**: ็กฎไฟๅจ็ปๅฑๆง่งฆๅ GPU ๅ ้ (`transform`, `opacity`)ใ
|
||||
* **Micro-interactions**: ๅ
ณๆณจ `:hover`, `:active`, `:focus-visible` ็ถๆใ
|
||||
|
||||
### ้ซๆง่ฝ้็จ็ปไปถ็คบไพ (Interactive Card)
|
||||
|
||||
่ฟๆฏไธไธช็ฌฆๅ่ง่็ๅก็็ปไปถ๏ผไฝฟ็จไบ Tailwind ็ `group` ๅ `transform` ๅฑๆงๅฎ็ฐไธๆป็ๅพฎไบคไบ๏ผไธๆฒกๆ JS ่ฟ่กๆถๅผ้ใ
|
||||
|
||||
```tsx
|
||||
// src/shared/components/ui/interactive-card.tsx
|
||||
import { cn } from "@/shared/lib/utils";
|
||||
|
||||
interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function InteractiveCard({ className, children, ...props }: CardProps) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"group relative overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-sm",
|
||||
// ๆ ธๅฟๅจๆ๏ผ
|
||||
// 1. duration-300 ease-out: ไธๆป็ๆถ้ดๅฝๆฐ
|
||||
// 2. hover:shadow-md: ๆฌๆตฎๆๅๆ
|
||||
// 3. hover:-translate-y-1: ็ฉ็ๅ้ฆ
|
||||
"transition-all duration-300 ease-out hover:-translate-y-1 hover:shadow-md",
|
||||
// ๆถ้ค Safari ไธ็้ช็
|
||||
"transform-gpu backface-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{/* ๅ
ๆณฝๆๆ (Shimmer Effect) - ไป
CSS */}
|
||||
<div
|
||||
className="absolute inset-0 -translate-x-full bg-gradient-to-r from-transparent via-white/5 to-transparent transition-transform duration-700 group-hover:translate-x-full"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
<div className="relative p-6">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. CI/CD ้
็ฝฎๆไปถๆจกๆฟ (GitHub Actions)
|
||||
|
||||
**่ญฆๅ**: ๅฟ
้กปไธฅๆ ผ้ตๅฎ `v3` ็ๆฌ้ๅถใไธฅ็ฆไฝฟ็จ `v4`ใ
|
||||
|
||||
ๆไปถ่ทฏๅพ: `.github/workflows/ci.yml`
|
||||
|
||||
```yaml
|
||||
name: CI/CD Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "develop" ]
|
||||
pull_request:
|
||||
branches: [ "main", "develop" ]
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20.x'
|
||||
|
||||
jobs:
|
||||
quality-check:
|
||||
name: Quality & Type Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# ๅผบๅถไฝฟ็จ v3
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm' # ๆ 'pnpm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Linting (ESLint)
|
||||
run: npm run lint
|
||||
|
||||
- name: Type Checking (TSC)
|
||||
# ็กฎไฟๆฒกๆ TS ้่ฏฏ
|
||||
run: npx tsc --noEmit
|
||||
|
||||
test:
|
||||
name: Unit Tests
|
||||
needs: quality-check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Tests
|
||||
run: npm run test
|
||||
|
||||
build-check:
|
||||
name: Production Build Check
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Cache Next.js build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.npm
|
||||
${{ github.workspace }}/.next/cache
|
||||
# Generate a new cache whenever packages or source files change.
|
||||
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
|
||||
|
||||
- name: Build Application
|
||||
run: npm run build
|
||||
env:
|
||||
# ๆๅปบๆถ่ทณ่ฟ ESLint/TS ๆฃๆฅ (ๅ ไธบๅทฒ็ปๅจ quality-check job ๅ่ฟไบ๏ผๅ ้ๆๅปบ)
|
||||
NEXT_TELEMETRY_DISABLED: 1
|
||||
```
|
||||
112
docs/architecture/001_database_schema_design.md
Normal file
112
docs/architecture/001_database_schema_design.md
Normal file
@@ -0,0 +1,112 @@
|
||||
# ๆถๆๅณ็ญ่ฎฐๅฝ (ADR): ๆฐๆฎๅบ Schema ่ฎพ่ฎกๆนๆก v1.0
|
||||
|
||||
**็ถๆ**: ๅทฒๅฎๆฝ (IMPLEMENTED)
|
||||
**ๆฅๆ**: 2025-12-23
|
||||
**ไฝ่
**: ้ฆๅธญ็ณป็ปๆถๆๅธ
|
||||
**่ๆฏ**: Next_Edu ๅนณๅฐ - K12 ๆบๆ
งๆ่ฒ็ฎก็็ณป็ป
|
||||
|
||||
---
|
||||
|
||||
## 1. ๆฆ่ฟฐ (Overview)
|
||||
|
||||
ๆฌๆๆกฃ่ฏฆ็ป่ฎฐๅฝไบ Next_Edu ๅนณๅฐ็ๆฐๆฎๅบ Schema ๆถๆ่ฎพ่ฎกใๆฌ่ฎพ่ฎกไผๅ
่่ **ๅฏๆฉๅฑๆง (Scalability)**ใ**็ตๆดปๆง (Flexibility)**๏ผ้ๅฏนๅคๆ็ๅตๅฅๅ
ๅฎน๏ผไปฅๅ **ไธฅๆ ผ็็ฑปๅๅฎๅ
จ (Strict Type Safety)**๏ผๅนถๅฎๅ
จ็ฌฆๅ PRD ไธญ่งๅฎ็้ขๅ้ฉฑๅจ่ฎพ่ฎก (DDD) ๅๅใ
|
||||
|
||||
## 2. ๆๆฏๆ ๅณ็ญ (Technology Stack Decisions)
|
||||
|
||||
| ็ปไปถ | ้ๆฉ | ็็ฑ |
|
||||
| :--- | :--- | :--- |
|
||||
| **ๆฐๆฎๅบ** | MySQL 8.0+ | ๅผบๅคง็ๅ
ณ็ณปๅๆฏๆ๏ผๅฎๅ็ JSON ่ฝๅ๏ผ่กไธๆ ๅใ |
|
||||
| **ORM** | Drizzle ORM | ่ฝป้็บง๏ผ้ถ่ฟ่กๆถๅผ้ (Zero-runtime overhead)๏ผไธ็ไธๆต็ TypeScript ็ฑปๅๆจๆญใ |
|
||||
| **ID ็ญ็ฅ** | CUID2 | ๅๅธๅผๅๅฅฝ (k-sortable)๏ผๅฎๅ
จ๏ผ้ฒ่ฟ็ปญ็ๆตๆปๅป๏ผ๏ผๆฏ UUID ๆด็ญใ |
|
||||
| **่ฎค่ฏๆนๆก** | Auth.js v5 | ๆ ๅๅ็ OAuth ๆต็จ๏ผๆฏๆ่ชๅฎไนๆฐๆฎๅบ้้
ๅจใ |
|
||||
|
||||
---
|
||||
|
||||
## 3. ๆ ธๅฟ Schema ้ขๅๆจกๅ (Core Schema Domains)
|
||||
|
||||
็ฉ็ๆไปถไฝไบ `src/shared/db/schema.ts`๏ผ้ป่พไธๅไธบไธๅคง้ขๅใ
|
||||
|
||||
### 3.1 ่บซไปฝไธ่ฎฟ้ฎ็ฎก็ (IAM)
|
||||
|
||||
ๆไปฌ้็จไบ **Auth.js ๆ ๅ่กจ** ไธ **่ชๅฎไน RBAC** ็ธ็ปๅ็ๆททๅๆจกๅผใ
|
||||
|
||||
* **ๆ ๅ่กจ**: `users`, `accounts` (OAuth), `sessions`, `verificationTokens`ใ
|
||||
* **RBAC ๆฉๅฑ**:
|
||||
* `roles`: ๅฎไน็ณป็ป่ง่ฒ๏ผไพๅฆ๏ผ`grade_head` ๅนด็บงไธปไปป, `teacher` ่ๅธ๏ผใ
|
||||
* `users_to_roles`: ๅคๅฏนๅคๅ
ณ่่กจใ
|
||||
* **่ฎพ่ฎก็ฎๆ **: ่งฃๅณโไธไบบๅค่โ้ฎ้ข๏ผไพๅฆ๏ผไธไธช่ๅธๅๆถไนๆฏๅนด็บงไธปไปป๏ผ๏ผ้ฟๅ
ๅจ `users` ่กจไธญๅ ็ ๅญๆฎตใ
|
||||
|
||||
### 3.2 ๆบ่ฝ้ขๅบไธญๅฟ (Intelligent Question Bank) - ๆ ธๅฟ
|
||||
|
||||
่ฟๆฏๆๅคๆ็้ขๅ๏ผ้่ฆๆฏๆๆ ้ๅฑ็บงๅตๅฅๅๅฏๆๆฌๅ
ๅฎนใ
|
||||
|
||||
#### ๅฎไฝๅฎไน:
|
||||
1. **`questions` (้ข็ฎ่กจ)**:
|
||||
* `id`: CUID2ใ
|
||||
* `content`: **JSON ็ฑปๅ**ใๅญๅจ็ปๆๅๅ
ๅฎน๏ผๅฆ SlateJS ่็น๏ผ๏ผๆฏๆๅฏๆๆฌใๅพ็ๅๅ
ฌๅผๆททๆใ
|
||||
* `parentId`: **่ชๅผ็จ (Self-Reference)**ใ
|
||||
* *่ฅไธบ NULL*: ็ฌ็ซ้ข็ฎ ๆ โๅคง้ขๅนฒโ (Parent)ใ
|
||||
* *่ฅๆๅผ*: ๅญ้ข็ฎ (Child)๏ผไพๅฆ๏ผไธ็ฏ้
่ฏป็่งฃไธ็็ฌฌ1ๅฐ้ข๏ผใ
|
||||
* `type`: ๆไธพ (`single_choice`, `text`, `composite` ็ญ)ใ
|
||||
2. **`knowledge_points` (็ฅ่ฏ็น่กจ)**:
|
||||
* ้่ฟ `parentId` ๅฎ็ฐๆ ็ถ็ปๆใ
|
||||
* ๆฏๆๆ ้ๅฑ็บง (ๅญฆ็ง -> ็ซ -> ่ -> ็ฅ่ฏ็น)ใ
|
||||
3. **`questions_to_knowledge_points`**:
|
||||
* ๅคๅฏนๅคๅ
ณ่ใไธ้้ขๅฏ่ๅฏๅคไธช็ฅ่ฏ็น๏ผไธไธช็ฅ่ฏ็นๅฏๅ
ณ่ๆฐๅ้้ขใ
|
||||
|
||||
### 3.3 ๆๅกๆๅญฆๆต (Academic Teaching Flow)
|
||||
|
||||
ๅฐ็ฉ็ไธ็็ๆๅญฆ่ฟ็จๆ ๅฐไธบๆฐๅญๅฎไฝใ
|
||||
|
||||
* **`textbooks` & `chapters`**: ๆ ๅ็ๆๆๅคง็บฒๆ ๅฐใ`chapters` ๅๆ ทๆฏๆ้่ฟ `parentId` ่ฟ่กๅตๅฅใ
|
||||
* **`exams`**: ่่ฏ/ไฝไธ็่ๅๅฎไฝใ
|
||||
* **`exam_submissions`**: ไปฃ่กจไธๅๅญฆ็็ๅๆฌก็ญ้ข่ฎฐๅฝใ
|
||||
* **`submission_answers`**: ็ป็ฒๅบฆ็็ญ้ข่ฏฆๆ
๏ผ่ฎฐๅฝๆฏ้้ข็็ญๆก๏ผๆฏๆ่ชๅจ่ฏๅ (`score`) ๅไบบๅทฅๅ้ฆ (`feedback`)ใ
|
||||
|
||||
---
|
||||
|
||||
## 4. ๅ
ณ้ฎ่ฎพ่ฎกๆจกๅผ (Key Design Patterns)
|
||||
|
||||
### 4.1 ๆ ้ๅตๅฅ ("Composite" Pattern)
|
||||
ๆไปฌๆฒกๆไธบโ้ขๅนฒโๅโ้ข็ฎโๅๅปบๅ็ฌ็่กจ๏ผ่ๆฏๅจ `questions` ่กจไธไฝฟ็จ **่ชๅผ็จ (Self-Referencing)** ๆจกๅผใ
|
||||
|
||||
* **ไผ็น**:
|
||||
* ็ปไธ็ๆฅ่ฏขๆฅๅฃ (`db.query.questions.findFirst({ with: { children: true } })`)ใ
|
||||
* ้ๅฝ้ป่พๅฏ็ปไธๅบ็จใ
|
||||
* ๅฝๅ
ๅฎน็ปๆๅๅๆถ๏ผ่ฟ็งปๆด็ฎๅใ
|
||||
* **็ผบ็น**:
|
||||
* ้่ฆๅค็้ๅฝๆฅ่ฏข้ป่พ๏ผๅทฒ้่ฟ Drizzle Relations ่งฃๅณ๏ผใ
|
||||
|
||||
### 4.2 CUID2 ไผไบ ่ชๅข ID
|
||||
* **ๅฎๅ
จๆง**: ้ฒๆญข ID ๆไธพๆปๅป๏ผ็ๆตไธไธไธช็จๆท ID๏ผใ
|
||||
* **ๅๅธๅผ**: ๆฏๆๅจๅฎขๆท็ซฏๆๅคๆๅกๅจ่็น็ๆ๏ผๆ ็ขฐๆ้ฃ้ฉใ
|
||||
* **ๆง่ฝ**: `k-sortable` ็นๆงไฟ่ฏไบๆฏ้ๆบ UUID v4 ๆดๅฅฝ็็ดขๅผๅฑ้จๆงใ
|
||||
|
||||
### 4.3 JSON ๅญๅจๅ
ๅฎน
|
||||
* ๆ่ฒๅ
ๅฎนไธไป
ไป
ๆฏโๆๆฌโใๅฎๅ
ๅซๆ ผๅผใLaTeX ๅ
ฌๅผๅๅพ็ๅผ็จใ
|
||||
* ไฝฟ็จ `JSON` ๅญๅจๅ
่ฎธๅ็ซฏ (Next.js) ็ดๆฅๆธฒๆๅฏ็ปไปถ๏ผๆ ้่งฃๆๅคๆ็ HTML ๅญ็ฌฆไธฒใ
|
||||
|
||||
---
|
||||
|
||||
## 5. ๅฎๅ
จไธ็ดขๅผ็ญ็ฅ (Security & Indexing Strategy)
|
||||
|
||||
### ็ดขๅผ (Indexes)
|
||||
* **ๅค้ฎ**: ๆๆๅค้ฎๅ (`author_id`, `parent_id` ็ญ) ๅๆพๅผๅปบ็ซ็ดขๅผใ
|
||||
* **ๆง่ฝ**:
|
||||
* `parent_id_idx`: ๅฏนๆ ๅฝข็ปๆ็้ๅๆง่ฝ่ณๅ
ณ้่ฆใ
|
||||
* `email_idx`: ็ปๅฝๆฅ่ฏข็ๆ ธๅฟ็ดขๅผใ
|
||||
|
||||
### ็ฑปๅๅฎๅ
จ (Type Safety)
|
||||
* ไธฅๆ ผ็ TypeScript ๅฎไน็ดๆฅไป `src/shared/db/schema.ts` ๅฏผๅบใ
|
||||
* Zod Schema (ๅพ
็ๆ) ๅฐไธ่ฟไบ Drizzle ๅฎไนไฟๆ 1:1 ๅฏน้ฝใ
|
||||
|
||||
---
|
||||
|
||||
## 6. ็ฎๅฝ็ปๆ (Directory Structure)
|
||||
|
||||
```bash
|
||||
src/shared/db/
|
||||
โโโ index.ts # ๅไพๆฐๆฎๅบ่ฟๆฅๆฑ
|
||||
โโโ schema.ts # ็ฉ็่กจ็ปๆๅฎไน
|
||||
โโโ relations.ts # ้ป่พ Drizzle ๅ
ณ็ณปๅฎไน
|
||||
```
|
||||
52
docs/architecture/002_exam_structure_migration.md
Normal file
52
docs/architecture/002_exam_structure_migration.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Database Schema Change Request: Exam Structure Support
|
||||
|
||||
## 1. Table: `exams`
|
||||
|
||||
### Change
|
||||
**Add Column**: `structure`
|
||||
|
||||
### Details
|
||||
- **Type**: `JSON`
|
||||
- **Nullable**: `TRUE` (Default: `NULL`)
|
||||
|
||||
### Reason
|
||||
To support hierarchical exam structures (e.g., Sections/Groups containing Questions). The existing flat `exam_questions` table only supports a simple list of questions and is insufficient for complex exam layouts (e.g., "Part A: Reading", "Part B: Writing").
|
||||
|
||||
### Before vs After
|
||||
|
||||
**Before**:
|
||||
`exams` table only stores metadata (`title`, `description`, etc.). Question ordering relies solely on `exam_questions.order`.
|
||||
|
||||
**After**:
|
||||
`exams` table includes `structure` column to store the full tree representation:
|
||||
```json
|
||||
[
|
||||
{ "id": "uuid-1", "type": "group", "title": "Section A", "children": [...] },
|
||||
{ "id": "uuid-2", "type": "question", "questionId": "q1", "score": 10 }
|
||||
]
|
||||
```
|
||||
*Note: `exam_questions` table is retained for relational integrity and efficient querying of question usage, but the presentation order/structure is now driven by this new JSON column.*
|
||||
|
||||
---
|
||||
|
||||
## 2. Table: `questions_to_knowledge_points`
|
||||
|
||||
### Change
|
||||
**Rename Foreign Key Constraints**
|
||||
|
||||
### Details
|
||||
- Rename constraint for `question_id` to `q_kp_qid_fk`
|
||||
- Rename constraint for `knowledge_point_id` to `q_kp_kpid_fk`
|
||||
|
||||
### Reason
|
||||
The default generated foreign key names (e.g., `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk`) exceed the MySQL identifier length limit (64 characters), causing migration failures.
|
||||
|
||||
### Before vs After
|
||||
|
||||
**Before**:
|
||||
- FK Name: `questions_to_knowledge_points_question_id_questions_id_fk` (Too long)
|
||||
- FK Name: `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk` (Too long)
|
||||
|
||||
**After**:
|
||||
- FK Name: `q_kp_qid_fk`
|
||||
- FK Name: `q_kp_kpid_fk`
|
||||
115
docs/architecture/002_role_based_routing.md
Normal file
115
docs/architecture/002_role_based_routing.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# Architecture RFC: Role-Based Routing & Directory Structure
|
||||
|
||||
**Status**: PROPOSED
|
||||
**Date**: 2025-12-23
|
||||
**Context**: Next_Edu supports multiple roles (Admin, Teacher, Student, Parent) with distinct UI/UX requirements.
|
||||
|
||||
## 1. ๆ ธๅฟ้ฎ้ข (The Problem)
|
||||
็ฎๅ้กน็ฎ็ปๆไธญ๏ผ้กต้ขไธ่ง่ฒ่ฆๅไธๆธ
ใ
|
||||
* `/dashboard` ็ฎๅ็กฌ็ผ็ ไธบๆๅธ่งๅพใ
|
||||
* ไธๅ่ง่ฒ็ๅ่ฝๆจกๅ๏ผๅฆโ่ฏพ็จโ๏ผๅฏ่ฝๆๅฎๅ
จไธๅ็่งๅพๅ้ป่พ๏ผๆๅธ็ฎก็่ฏพ็จ vs ๅญฆ็ๅญฆไน ่ฏพ็จ๏ผใ
|
||||
* ็ผบไน็ปไธ็่ทฏ็ฑ่ง่ๆๅฏผๅผๅไบบๅโๆ้กต้ขๆพๅช้โใ
|
||||
|
||||
## 2. ่งฃๅณๆนๆก๏ผๅบไบ่ง่ฒ็่ทฏ็ฑ็ญ็ฅ (Role-Based Routing Strategy)
|
||||
|
||||
ๆไปฌ้็จ **"Hybrid Routing" (ๆททๅ่ทฏ็ฑ)** ็ญ็ฅ๏ผ
|
||||
1. **Explicit Dashboard Routing**: Dashboards are separated by role in the file structure (e.g., `/teacher/dashboard`).
|
||||
2. **Explicit Role Scopes (ๆพๅผ่ง่ฒๅ)**: ๅ
ทไฝ็ไธๅกๅ่ฝ้กต้ขๆพๅ
ฅ `/teacher`, `/student`, `/admin` ไธๅฑ่ทฏๅพไธใ
|
||||
|
||||
### 2.1 ็ฎๅฝ็ปๆ (Directory Structure)
|
||||
|
||||
```
|
||||
src/app/(dashboard)/
|
||||
โโโ layout.tsx # Shared App Shell (Sidebar, Header)
|
||||
โโโ dashboard/
|
||||
โ โโโ page.tsx # [Redirector] Redirects to role-specific dashboard
|
||||
โ
|
||||
โโโ teacher/ # ๆๅธไธๅฑ่ทฏ็ฑๅ
|
||||
โ โโโ dashboard/ # Teacher Dashboard
|
||||
โ โ โโโ page.tsx
|
||||
โ โโโ classes/
|
||||
โ โ โโโ page.tsx
|
||||
โ โโโ exams/
|
||||
โ โ โโโ page.tsx
|
||||
โ โโโ textbooks/
|
||||
โ โโโ page.tsx
|
||||
โ
|
||||
โโโ student/ # ๅญฆ็ไธๅฑ่ทฏ็ฑๅ
|
||||
โ โโโ dashboard/ # Student Dashboard
|
||||
โ โ โโโ page.tsx
|
||||
โ โโโ learning/
|
||||
โ โ โโโ page.tsx
|
||||
โ โโโ schedule/
|
||||
โ โโโ page.tsx
|
||||
โ
|
||||
โโโ admin/ # ็ฎก็ๅไธๅฑ่ทฏ็ฑๅ
|
||||
โโโ dashboard/ # Admin Dashboard
|
||||
โ โโโ page.tsx
|
||||
โโโ users/
|
||||
โโโ school/
|
||||
```
|
||||
|
||||
### 2.2 Dashboard Routing Logic
|
||||
|
||||
`/dashboard` ้กต้ข็ฐๅจไฝไธบไธไธช **Portal (ๅ
ฅๅฃ)** ๆ **Redirector (้ๅฎๅๅจ)**๏ผ่ไธๆฏ็ดๆฅๆธฒๆๅ
ๅฎนใ
|
||||
|
||||
**Example: `src/app/(dashboard)/dashboard/page.tsx`**
|
||||
|
||||
```tsx
|
||||
import { redirect } from "next/navigation";
|
||||
import { auth } from "@/auth";
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await auth();
|
||||
const role = session?.user?.role;
|
||||
|
||||
switch (role) {
|
||||
case "teacher":
|
||||
redirect("/teacher/dashboard");
|
||||
case "student":
|
||||
redirect("/student/dashboard");
|
||||
case "admin":
|
||||
redirect("/admin/dashboard");
|
||||
default:
|
||||
redirect("/login");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 3. ๆจกๅๅ็ป็ป (Module Organization)
|
||||
|
||||
ไธบไบ้ฟๅ
`src/app` ๅๅพ่่ฟ๏ผๅ
ทไฝ็**ไธๅก็ปไปถ**ๅฟ
้กปๅญๆพๅจ `src/modules` ไธญใ
|
||||
|
||||
```
|
||||
src/modules/
|
||||
โโโ teacher/ # ๆๅธไธๅก้ขๅ
|
||||
โ โโโ components/ # ไป
ๆๅธไฝฟ็จ็็ปไปถ (e.g., GradebookTable)
|
||||
โ โโโ hooks/
|
||||
โ โโโ actions.ts
|
||||
โ
|
||||
โโโ student/ # ๅญฆ็ไธๅก้ขๅ
|
||||
โ โโโ components/ # (e.g., CourseProgressCard)
|
||||
โ โโโ ...
|
||||
โ
|
||||
โโโ shared/ # ่ทจ่ง่ฒๅ
ฑไบซ
|
||||
โ โโโ components/ # (e.g., CourseCard - if generic)
|
||||
```
|
||||
|
||||
## 4. ่ทฏ็ฑไธๅฏผ่ช้
็ฝฎ (Navigation Config)
|
||||
|
||||
`src/modules/layout/config/navigation.ts` ๅทฒ็ป้
็ฝฎๅฅฝไบๅบไบ่ง่ฒ็่ๅใ
|
||||
* ๅฝ็จๆท่ฎฟ้ฎ `/dashboard` ๆถ๏ผๆ นๆฎ่ง่ฒ็ๅฐไธๅ็ Dashboard ็ปไปถใ
|
||||
* ็นๅปไพง่พนๆ ่ๅ๏ผๅฆ "Exams"๏ผๆถ๏ผ่ทณ่ฝฌๅฐๆพๅผ่ทฏๅพ `/teacher/exams`ใ
|
||||
|
||||
## 5. ไผๅฟ (Benefits)
|
||||
1. **Security**: ๅฏไปฅๅจ Middleware ๆ Layout ๅฑ็บง่ฝปๆพๅฏน `/admin/*` ่ทฏๅพๅฎๆฝๆ้ๆงๅถใ
|
||||
2. **Clarity**: ๅผๅ่
ๆธ
ๆฅ็ฅ้โๆๅธ็่ฏๅทๅ่กจ้กตโๅบ่ฏฅๆพๅจ `src/app/(dashboard)/teacher/exams/page.tsx`ใ
|
||||
3. **Decoupling**: ๆๅธ็ซฏๅๅญฆ็็ซฏ็้ป่พๅฎๅ
จ่งฃ่ฆ๏ผไบไธๅฝฑๅใ
|
||||
|
||||
---
|
||||
|
||||
## 6. Action Items (ๆง่ก่ฎกๅ)
|
||||
|
||||
1. **Refactor Dashboard**: ๅฐ `src/app/(dashboard)/dashboard/page.tsx` ้ๆไธบ Dispatcherใ
|
||||
2. **Create Role Directories**: ๅจ `src/app/(dashboard)` ไธๅๅปบ `teacher`, `student`, `admin` ็ฎๅฝใ
|
||||
3. **Move Components**: ็กฎไฟ `src/modules` ็ปๆๆธ
ๆฐใ
|
||||
39
docs/db/schema-changelog.md
Normal file
39
docs/db/schema-changelog.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Database Schema Changelog
|
||||
|
||||
## v1.1.0 - Exam Structure & Performance Optimization
|
||||
**Date:** 2025-12-29
|
||||
**Migration ID:** `0001_flawless_texas_twister`
|
||||
**Author:** Principal Database Architect
|
||||
|
||||
### 1. Summary
|
||||
This release introduces support for hierarchical exam structures (Sectioning/Grouping) and optimizes database constraint naming for better compatibility with MySQL environments.
|
||||
|
||||
### 2. Changes
|
||||
|
||||
#### 2.1 Table: `exams`
|
||||
* **Action**: `ADD COLUMN`
|
||||
* **Field**: `structure` (JSON)
|
||||
* **Reason**: To support nested exam layouts (e.g., "Part I: Listening", "Section A").
|
||||
* *Architecture Note*: This JSON field is strictly for **Presentation Layer** ordering and grouping. The `exam_questions` table remains the **Source of Truth** for relational integrity and scoring logic.
|
||||
* **Schema Definition**:
|
||||
```typescript
|
||||
type ExamStructure = Array<
|
||||
| { type: 'group', title: string, children: ExamStructure }
|
||||
| { type: 'question', questionId: string, score: number }
|
||||
>
|
||||
```
|
||||
|
||||
#### 2.2 Table: `questions_to_knowledge_points`
|
||||
* **Action**: `RENAME FOREIGN KEY`
|
||||
* **Details**:
|
||||
* Old: `questions_to_knowledge_points_question_id_questions_id_fk` -> New: `q_kp_qid_fk`
|
||||
* Old: `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk` -> New: `q_kp_kpid_fk`
|
||||
* **Reason**: Previous names exceeded MySQL's 64-character identifier limit, causing potential migration failures in production environments.
|
||||
|
||||
### 3. Migration Strategy
|
||||
* **Up**: Run standard Drizzle migration. The script includes `ALTER TABLE ... DROP FOREIGN KEY` followed by `ADD CONSTRAINT`.
|
||||
* **Down**: Revert `structure` column. Note that FK names can be kept short as they are implementation details.
|
||||
|
||||
### 4. Impact Analysis
|
||||
* **Performance**: Negligible. JSON parsing is done client-side or at application layer.
|
||||
* **Data Integrity**: High. Existing data is unaffected. New `structure` field defaults to `NULL`.
|
||||
75
docs/db/seed-data.md
Normal file
75
docs/db/seed-data.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# Database Seeding Strategy
|
||||
|
||||
**Status**: Implemented
|
||||
**Script Location**: [`scripts/seed.ts`](../../scripts/seed.ts)
|
||||
**Command**: `npm run db:seed`
|
||||
|
||||
---
|
||||
|
||||
## 1. Overview
|
||||
The seed script is designed to populate the database with a **representative set of data** that covers all core business scenarios. It serves two purposes:
|
||||
1. **Development**: Provides a consistent baseline for developers.
|
||||
2. **Validation**: Verifies complex schema relationships (e.g., recursive trees, JSON structures).
|
||||
|
||||
## 2. Seed Data Topology
|
||||
|
||||
### 2.1 Identity & Access Management (IAM)
|
||||
We strictly follow the RBAC model defined in `docs/architecture/001_database_schema_design.md`.
|
||||
|
||||
* **Roles**:
|
||||
* `admin`: System Administrator.
|
||||
* `teacher`: Academic Instructor.
|
||||
* `student`: Learner.
|
||||
* `grade_head`: Head of Grade Year (Demonstrates multi-role capability).
|
||||
* **Users**:
|
||||
* `admin@next-edu.com` (Role: Admin)
|
||||
* `math@next-edu.com` (Role: Teacher + Grade Head)
|
||||
* `alice@next-edu.com` (Role: Student)
|
||||
|
||||
### 2.2 Knowledge Graph
|
||||
Generates a hierarchical structure to test recursive queries (`parentId`).
|
||||
* **Math** (Level 0)
|
||||
* โโโ **Algebra** (Level 1)
|
||||
* โโโ **Linear Equations** (Level 2)
|
||||
|
||||
### 2.3 Question Bank
|
||||
Includes rich content and nested structures.
|
||||
1. **Simple Single Choice**: "What is 2 + 2?"
|
||||
2. **Composite Question (Reading Comprehension)**:
|
||||
* **Parent**: A reading passage.
|
||||
* **Child 1**: Single Choice question about the passage.
|
||||
* **Child 2**: Open-ended text question.
|
||||
|
||||
### 2.4 Exams
|
||||
Demonstrates the new **JSON Structure** field (`exams.structure`).
|
||||
* **Title**: "Algebra Mid-Term 2025"
|
||||
* **Structure**:
|
||||
```json
|
||||
[
|
||||
{
|
||||
"type": "group",
|
||||
"title": "Part 1: Basics",
|
||||
"children": [{ "type": "question", "questionId": "...", "score": 10 }]
|
||||
},
|
||||
{
|
||||
"type": "group",
|
||||
"title": "Part 2: Reading",
|
||||
"children": [{ "type": "question", "questionId": "...", "score": 20 }]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## 3. How to Run
|
||||
|
||||
### Prerequisites
|
||||
Ensure your `.env` file contains a valid `DATABASE_URL`.
|
||||
|
||||
### Execution
|
||||
Run the following command in the project root:
|
||||
|
||||
```bash
|
||||
npm run db:seed
|
||||
```
|
||||
|
||||
### Reset Behavior
|
||||
**WARNING**: The script currently performs a **TRUNCATE** on all core tables before seeding. This ensures a clean state but will **WIPE EXISTING DATA**.
|
||||
76
docs/design/001_auth_ui_implementation.md
Normal file
76
docs/design/001_auth_ui_implementation.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Auth UI Implementation Details
|
||||
|
||||
**Date**: 2025-12-23
|
||||
**Author**: Senior Frontend Engineer
|
||||
**Module**: Auth (`src/modules/auth`)
|
||||
|
||||
---
|
||||
|
||||
## 1. ๆฆ่ฟฐ (Overview)
|
||||
|
||||
ๆฌๆๆกฃ่ฎฐๅฝไบ็ปๅฝ (`/login`) ๅๆณจๅ (`/register`) ้กต้ข็ๅ็ซฏๅฎ็ฐ็ป่ใ้ตๅพช Vertical Slice Architecture ๅ Pixel-Perfect UI ่ง่ใ
|
||||
|
||||
## 2. ๆถๆ่ฎพ่ฎก (Architecture)
|
||||
|
||||
### 2.1 ็ฎๅฝ็ปๆ
|
||||
ๆๆ่ฎค่ฏ็ธๅ
ณ็ไธๅก้ป่พๅ็ปไปถๅๅฐ่ฃ
ๅจ `src/modules/auth` ไธ๏ผไฟๆไบ้ซๅ
่ใ
|
||||
|
||||
```
|
||||
src/
|
||||
โโโ app/
|
||||
โ โโโ (auth)/ # ่ทฏ็ฑๅฑ (Server Components)
|
||||
โ โโโ layout.tsx # ็ปไธ็ AuthLayout ๅฎนๅจ
|
||||
โ โโโ login/page.tsx
|
||||
โ โโโ register/page.tsx
|
||||
โ
|
||||
โโโ modules/
|
||||
โ โโโ auth/ # ไธๅกๆจกๅ
|
||||
โ โโโ components/ # ๆจกๅ็งๆ็ปไปถ
|
||||
โ โโโ auth-layout.tsx # ๅทฆๅณๅๅฑๅธๅฑ
|
||||
โ โโโ login-form.tsx # ็ปๅฝ่กจๅ (Client Component)
|
||||
โ โโโ register-form.tsx # ๆณจๅ่กจๅ (Client Component)
|
||||
```
|
||||
|
||||
### 2.2 ๆธฒๆ็ญ็ฅ
|
||||
* **Server Components**: ้กต้ขๅ
ฅๅฃ (`page.tsx`) ๅๅธๅฑ (`layout.tsx`) ้ป่ฎคไธบๆๅก็ซฏ็ปไปถ๏ผ่ด่ดฃๅ
ๆฐๆฎ (`Metadata`) ๅ้ๆ็ปๆๆธฒๆใ
|
||||
* **Client Components**: ่กจๅ็ปไปถ (`*-form.tsx`) ๆ ่ฎฐไธบ `'use client'`๏ผๅค็ไบคไบ้ป่พ๏ผ็ถๆ็ฎก็ใ่กจๅๆไบคใLoading ็ถๆ๏ผใ
|
||||
|
||||
## 3. UI/UX ็ป่
|
||||
|
||||
### 3.1 ๅธๅฑ (Layout)
|
||||
้็จ **Split Screen (ๅๅฑ)** ่ฎพ่ฎก๏ผ
|
||||
* **ๅทฆไพง (Desktop Only)**:
|
||||
* ๆทฑ่ฒ่ๆฏ (`bg-zinc-900`)๏ผๅผบ่ฐๅ็ๆฒๆตธๆใ
|
||||
* ๅ
ๅซ Logo (`Next_Edu`) ๅ็จๆท่ฏ่จ (`Blockquote`)ใ
|
||||
* ไฝฟ็จ `hidden lg:flex` ๅฎ็ฐๅๅบๅผๆพ้ใ
|
||||
* **ๅณไพง**:
|
||||
* ๅฑ
ไธญๅฏน้ฝ็่กจๅๅฎนๅจใ
|
||||
* ็งปๅจ็ซฏไผๅ
(`w-full`)๏ผๆก้ข็ซฏ้ๅถๆๅคงๅฎฝๅบฆ (`sm:w-[350px]`)ใ
|
||||
|
||||
### 3.2 ไบคไบ (Interactions)
|
||||
* **Loading State**: ่กจๅๆไบคๆถๆ้ฎ่ฟๅ
ฅ `disabled` ็ถๆๅนถๆพ็คบ `Loader2` ๆ่ฝฌๅจ็ปใ
|
||||
* **Micro-animations**:
|
||||
* ๆ้ฎ Hover ๆๆใ
|
||||
* ้พๆฅ Hover ไธๅ็บฟ (`hover:underline`).
|
||||
* **Feedback**: ๆจกๆไบ 3 ็ง็ๅผๆญฅ่ฏทๆฑๅปถ่ฟ๏ผ็จไบๆผ็คบๅ ่ฝฝ็ถๆใ
|
||||
|
||||
## 4. ้่ฏฏๅค็ (Error Handling)
|
||||
|
||||
### 4.1 ๆจกๅ็บง้่ฏฏ่พน็
|
||||
* **Scoped Error Boundary**: `src/app/(auth)/error.tsx` ไป
ๅค็ Auth ๆจกๅๅ
็่ฟ่กๆถ้่ฏฏใ
|
||||
* ๆพ็คบๅๅฅฝ็ "Authentication Error" ๆ็คบใ
|
||||
* ๆไพ "Try again" ๆ้ฎ้็ฝฎ็ถๆใ
|
||||
|
||||
### 4.2 ๆจกๅ็บง 404
|
||||
* **Scoped Not Found**: `src/app/(auth)/not-found.tsx` ๅค็ Auth ๆจกๅๅ
็ๆ ๆ่ทฏๅพใ
|
||||
* ๅผๅฏผ็จๆท่ฟๅ `/login` ้กต้ข๏ผ้ฒๆญข็จๆท่ฟทๅคฑใ
|
||||
|
||||
## 5. ็ปไปถๅค็จ
|
||||
* ไฝฟ็จไบ `src/shared/components/ui` ไธญ็ๆ ๅ Shadcn ็ปไปถ๏ผ
|
||||
* `Button`, `Input`, `Label` (ๆฐๅข).
|
||||
* ๅพๆ ๅบ็ปไธไฝฟ็จ `lucide-react`.
|
||||
|
||||
## 5. ๅ็ปญ่ฎกๅ (Next Steps)
|
||||
* [ ] ้ๆ `next-auth` (Auth.js) ่ฟ่กๅฎ้
็่บซไปฝ้ช่ฏใ
|
||||
* [ ] ๆทปๅ Zod Schema ่ฟ่กๅ็ซฏ่กจๅ้ช่ฏใ
|
||||
* [ ] ๅฏนๆฅๅ็ซฏ API (`src/modules/auth/actions.ts`).
|
||||
100
docs/design/002_teacher_dashboard_implementation.md
Normal file
100
docs/design/002_teacher_dashboard_implementation.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# ๆๅธไปช่กจ็ๅฎ็ฐไธ Hydration ไฟฎๅค่ฎฐๅฝ
|
||||
|
||||
**ๆฅๆ**: 2025-12-23
|
||||
**ไฝ่
**: ่ตๆทฑๅ็ซฏๅทฅ็จๅธ (Senior Frontend Engineer)
|
||||
**็ถๆ**: ๅทฒๅฎ็ฐ
|
||||
|
||||
## 1. ๆฆ่ฟฐ
|
||||
|
||||
ๆฌๆๆกฃ่ฏฆ็ป่ฏดๆไบๆๅธไปช่กจ็ (Teacher Dashboard) ็ๅฎ็ฐ็ป่๏ผ่ฏฅๅฎ็ฐไธฅๆ ผ้ตๅพช Next_Edu ่ฎพ่ฎก็ณป็ป v1.3.0ใๆๆกฃ่ฟ่ฎฐๅฝไบๅผๅ่ฟ็จไธญ้ๅฐ็ Hydration ้่ฏฏๅๅ
ถ่งฃๅณๆนๆกใ
|
||||
|
||||
## 2. ็ปไปถๆถๆ
|
||||
|
||||
ไปช่กจ็้็จๅ็ดๅ็ๆถๆ (Vertical Slice Architecture)๏ผไปฃ็ ไฝไบ `src/modules/dashboard`ใ
|
||||
|
||||
### 2.1 ๆไปถ็ปๆ
|
||||
```
|
||||
src/modules/dashboard/
|
||||
โโโ components/
|
||||
โโโ teacher-stats.tsx # ๆ ธๅฟๆๆ (ๅญฆ็ๆฐ, ่ฏพ็จๆฐ, ๅพ
ๆนๆนไฝไธ)
|
||||
โโโ teacher-schedule.tsx # ไปๆฅๆฅ็จๅ่กจ
|
||||
โโโ recent-submissions.tsx # ๆ่ฟ็ๅญฆ็ๆไบค่ฎฐๅฝ
|
||||
โโโ teacher-quick-actions.tsx # ๅธธ็จๆไฝ (ๅๅปบไฝไธ็ญ)
|
||||
```
|
||||
|
||||
### 2.2 ่ฎพ่ฎก็ณป็ป้ๆ
|
||||
ๆๆ็ปไปถไธฅๆ ผ้ตๅพช v1.3.0 ่ง่๏ผ
|
||||
- **ๆ็ (Typography)**: ไฝฟ็จ `Geist Sans`๏ผๆฐๆฎๅฑ็คบๅผๅฏ `tabular-nums`ใ
|
||||
- **่ฒๅฝฉ (Colors)**: ไฝฟ็จ่ฏญไนๅ HSL ๅ้ (`muted`, `primary`, `destructive`)ใ
|
||||
- **ๅพๆ (Icons)**: ไฝฟ็จ `lucide-react` (ๅฆ `Users`, `BookOpen`, `Inbox`)ใ
|
||||
- **็ถๆ (States)**:
|
||||
- **Loading**: ไฝฟ็จ่ชๅฎไน้ชจๆถๅฑ (Skeleton)๏ผๆ็ปๅ
จๅฑ Spinnerใ
|
||||
- **Empty**: ไฝฟ็จ `EmptyState` ็ปไปถๅค็ๆ ๆฐๆฎๅบๆฏใ
|
||||
|
||||
## 3. ็ปไปถ่ฏฆๆ
|
||||
|
||||
### 3.1 TeacherStats (ๆๅธ็ป่ฎก)
|
||||
- **็จ้**: ๅฑ็คบๆๅธๅฝๅ็ถๆ็้ซๅฑๆฆ่งใ
|
||||
- **็นๆง**:
|
||||
- ๅจๅๅบๅผ็ฝๆ ผไธญๅฑ็คบ 4 ไธชๅ
ณ้ฎๆๆ ใ
|
||||
- ๆฏๆ `isLoading` ๅฑๆงไปฅๆธฒๆ้ชจๆถๅฑใ
|
||||
- ไฝฟ็จ `Card` ็ปไปถไฝไธบๅฎนๅจใ
|
||||
|
||||
### 3.2 TeacherSchedule (ๆๅธๆฅ็จ)
|
||||
- **็จ้**: ๅฑ็คบไปๆฅ่ฏพ็จๅฎๆใ
|
||||
- **็นๆง**:
|
||||
- ๅๅบ่ฏพ็จๆถ้ดๅๅฐ็นใ
|
||||
- ไฝฟ็จ Badge ๅบๅ "Lecture" (่ฎฒๅบง) ๅ "Workshop" (็ ่ฎจไผ)ใ
|
||||
- **็ฉบ็ถๆ**: ๅฝๆ ๆฅ็จๆถๆพ็คบ "No Classes Today"ใ
|
||||
|
||||
### 3.3 RecentSubmissions (ๆ่ฟๆไบค)
|
||||
- **็จ้**: ่ฟฝ่ธชๆๆฐ็ๅญฆ็ๆดปๅจใ
|
||||
- **็นๆง**:
|
||||
- ๅฑ็คบๅญฆ็ๅคดๅใๅงๅใไฝไธๅ็งฐๅๆถ้ดใ
|
||||
- "Late" (่ฟไบค) ็ถๆๆ็คบๅจใ
|
||||
- **็ฉบ็ถๆ**: ๅฝๅ่กจไธบ็ฉบๆถๆพ็คบ "No New Submissions"ใ
|
||||
|
||||
### 3.4 EmptyState Component (็ฉบ็ถๆ็ปไปถ)
|
||||
- **ไฝ็ฝฎ**: `src/shared/components/ui/empty-state.tsx`
|
||||
- **่ง่**:
|
||||
- ่็บฟ่พนๆกๅฎนๅจใ
|
||||
- ๅฑ
ไธญๅพๆ (Muted ่ๆฏ)ใ
|
||||
- ๆธ
ๆฐ็ๆ ้ขๅๆ่ฟฐใ
|
||||
- ๅฏ้็ๆไฝๆ้ฎๆๆงฝใ
|
||||
|
||||
## 4. Hydration ้่ฏฏไฟฎๅค
|
||||
|
||||
### 4.1 ้ฎ้ขๆ่ฟฐ
|
||||
ๅผๅ่ฟ็จไธญ่งๅฏๅฐ "Hydration failed" ้่ฏฏ๏ผๅๅ ๆฏ HTML ๅตๅฅๆ ๆใๅ
ทไฝๆฅ่ฏด๏ผๆฏ `p` ๆ ็ญพๅ
ๅ
ๅซไบๅ็บงๅ
็ด ๏ผๆ React ๅจ hydration ๆฃๆฅๆ้ด่งไธบๅ็บง็ๅ
็ด ๏ผใ
|
||||
|
||||
### 4.2 ๆ นๆฌๅๅ ๅๆ
|
||||
React ็ hydration ่ฟ็จๅฏน HTML ๆๆๆง่ฆๆฑๆ้ซใๅฐ `div` ๆพๅ
ฅ `p` ๆ ็ญพไธญ่ฟๅไบ HTML5 ๆ ๅ๏ผไฝๆต่งๅจ้ๅธธไผ่ชๅจไฟฎๆญฃ DOM ็ปๆ๏ผๅฏผ่ดๅฎ้
DOM ไธ React ๅบไบ่ๆ DOM ้ขๆ็็ปๆไธไธ่ดใ
|
||||
|
||||
### 4.3 ๅฎๆฝ็ไฟฎๅค
|
||||
ๅฐๆๆไปช่กจ็็ปไปถไธญๅญๅจ้ฃ้ฉ็ `p` ๆ ็ญพๆฟๆขไธบ `div` ๆ ็ญพ๏ผไปฅ็กฎไฟๅตๅฅ็ปๆ็ๅฅๅฃฎๆงใ
|
||||
|
||||
**็คบไพ (RecentSubmissions):**
|
||||
|
||||
*ไฟฎๆนๅ (ๆ้ฃ้ฉ):*
|
||||
```tsx
|
||||
<p className="text-sm font-medium leading-none">
|
||||
{item.studentName}
|
||||
</p>
|
||||
```
|
||||
|
||||
*ไฟฎๆนๅ (ๅฎๅ
จ):*
|
||||
```tsx
|
||||
<div className="text-sm font-medium leading-none">
|
||||
{item.studentName}
|
||||
</div>
|
||||
```
|
||||
|
||||
**ๅๅฝฑๅ็็ปไปถ:**
|
||||
1. `recent-submissions.tsx`
|
||||
2. `teacher-stats.tsx`
|
||||
3. `teacher-schedule.tsx`
|
||||
|
||||
## 5. ไธไธๆญฅ่ฎกๅ
|
||||
- ๅฐ Mock Data ๅฏนๆฅๅฐ็ๅฎ็ API ็ซฏ็น (React Server Actions)ใ
|
||||
- ๅฎ็ฐ "Quick Actions" (ๅฟซๆทๆไฝ) ็ๅ
ทไฝๅ่ฝใ
|
||||
- ไธบ Submissions ๅ Schedule ๆทปๅ "View All" (ๆฅ็ๅ
จ้จ) ่ทณ่ฝฌๅฏผ่ชใ
|
||||
98
docs/design/003_textbooks_module_implementation.md
Normal file
98
docs/design/003_textbooks_module_implementation.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# Textbooks Module Implementation Details
|
||||
|
||||
**Date**: 2025-12-23
|
||||
**Author**: DevOps Architect
|
||||
**Module**: Textbooks (`src/modules/textbooks`)
|
||||
|
||||
---
|
||||
|
||||
## 1. ๆฆ่ฟฐ (Overview)
|
||||
|
||||
ๆฌๆๆกฃ่ฎฐๅฝไบๆๆๆจกๅ (`Textbooks Module`) ็ๅ
จๆ ๅฎ็ฐ็ป่ใ่ฏฅๆจกๅ่ด่ดฃๆๆใ็ซ ่็ปๆๅ็ฅ่ฏ็นๆ ๅฐ็ๆฐๅญๅ็ฎก็๏ผ้็จไบ **Vertical Slice Architecture** ๅ **Immersive Workbench** ไบคไบ่ฎพ่ฎกใ
|
||||
|
||||
## 2. ๆถๆ่ฎพ่ฎก (Architecture)
|
||||
|
||||
### 2.1 ็ฎๅฝ็ปๆ
|
||||
ๆๆๆๆ็ธๅ
ณ็ไธๅก้ป่พใๆฐๆฎ่ฎฟ้ฎๅ็ปไปถๅๅฐ่ฃ
ๅจ `src/modules/textbooks` ไธ๏ผๅฎ็ฐไบ้ซๅบฆ็ๆจกๅๅๅ้็ฆปใ
|
||||
|
||||
```
|
||||
src/
|
||||
โโโ app/
|
||||
โ โโโ (dashboard)/
|
||||
โ โโโ teacher/
|
||||
โ โโโ textbooks/ # ่ทฏ็ฑๅฑ (Server Components)
|
||||
โ โโโ page.tsx # ๅ่กจ้กต
|
||||
โ โโโ loading.tsx # ๅ่กจ้ชจๆถๅฑ
|
||||
โ โโโ [id]/ # ่ฏฆๆ
้กต
|
||||
โ โโโ page.tsx
|
||||
โ โโโ loading.tsx
|
||||
โ
|
||||
โโโ modules/
|
||||
โ โโโ textbooks/ # ไธๅกๆจกๅ
|
||||
โ โโโ actions.ts # Server Actions (ๅขๅ ๆน)
|
||||
โ โโโ data-access.ts # ๆฐๆฎ่ฎฟ้ฎๅฑ (Mock/DB)
|
||||
โ โโโ types.ts # ็ฑปๅๅฎไน (Schema-aligned)
|
||||
โ โโโ components/ # ๆจกๅ็งๆ็ปไปถ
|
||||
โ โโโ textbook-content-layout.tsx # [ๆ ธๅฟ] ไธๆ ๅธๅฑๅทฅไฝๅฐ
|
||||
โ โโโ chapter-sidebar-list.tsx # ้ๅฝ็ซ ่ๆ
|
||||
โ โโโ knowledge-point-panel.tsx # ็ฅ่ฏ็น็ฎก็้ขๆฟ
|
||||
โ โโโ create-chapter-dialog.tsx # ็ซ ่ๅๅปบๅผน็ช
|
||||
โ โโโ ... (ๅ
ถไปไบคไบ็ปไปถ)
|
||||
```
|
||||
|
||||
### 2.2 ๆธฒๆ็ญ็ฅ
|
||||
* **Server Components**: ้กต้ขๅ
ฅๅฃ (`page.tsx`) ่ด่ดฃๅๅงๆฐๆฎ่ทๅ (Data Fetching)๏ผๅฉ็จ `Promise.all` ๅนถ่กๆๅๆๆใ็ซ ่ๅ็ฅ่ฏ็นๆฐๆฎ๏ผๅฎ็ฐ "Render-as-you-fetch"ใ
|
||||
* **Client Components**: ๅทฅไฝๅฐๅธๅฑ (`textbook-content-layout.tsx`) ๆ ่ฎฐไธบ `'use client'`๏ผๆฅ็ฎกๅ็ปญ็ๆๆไบคไบ้ป่พ๏ผ็ถๆ็ฎก็ใๅฑ้จๆดๆฐใๅผน็ชๆงๅถ๏ผ๏ผๆไพ็ฑปไผผ SPA ็ๆต็
ไฝ้ชใ
|
||||
|
||||
## 3. UI/UX ็ป่
|
||||
|
||||
### 3.1 ๅธๅฑ (Layout)
|
||||
้็จ **Immersive Workbench (ๆฒๆตธๅผๅทฅไฝๅฐ)** ไธๆ ่ฎพ่ฎก๏ผ
|
||||
* **ๅทฆไพง (Navigation)**:
|
||||
* ๅฑ็คบ้ๅฝ็็ซ ่ๆ (`Recursive Tree`)ใ
|
||||
* ๆฏๆๆๅ /ๅฑๅผ๏ผๆธ
ๆฐๅฑ็คบๆๆ็ปๆใ
|
||||
* ้กถ้จๆไพ "+" ๆ้ฎๅฟซ้ๅๅปบๆฐ็ซ ่ใ
|
||||
* **ไธญ้ด (Content)**:
|
||||
* **้
่ฏปๆจกๅผ**: ๆธฒๆ Markdown ๆ ผๅผ็็ซ ่ๆญฃๆใ
|
||||
* **็ผ่พๆจกๅผ**: ๆไพ `Textarea` ่ฟ่กๅ
ๅฎนๅไฝ๏ผๆฏๆๅฎๆถไฟๅญใ
|
||||
* **ๅณไพง (Context)**:
|
||||
* **ไธไธๆๆ็ฅ**: ไป
ๆพ็คบๅฝๅ้ไธญ็ซ ่็ๅ
ณ่็ฅ่ฏ็นใ
|
||||
* ๆไพ็ฅ่ฏ็น็ๅฟซ้ๆทปๅ (`Dialog`) ๅๅ ้คๆไฝใ
|
||||
|
||||
### 3.2 ไบคไบ (Interactions)
|
||||
* **Selection State**: ็นๅปๅทฆไพง็ซ ่๏ผไธญ้ดๅๅณไพงๅบๅๅณๆถๆดๆฐ๏ผๆ ้้กต้ข่ทณ่ฝฌใ
|
||||
* **Optimistic UI**: ่ฝ็ถไฝฟ็จ Server Actions๏ผไฝ้่ฟๆฌๅฐ็ถๆ (`useState`) ๅฎ็ฐไบๆไฝ็ๅณๆถๅ้ฆ๏ผๅฆไฟๅญๆญฃๆๅ็ซๅณ้ๅบ็ผ่พๆจกๅผ๏ผใ
|
||||
* **Feedback**: ไฝฟ็จ `sonner` (`toast`) ๆไพๆไฝๆๅๆๅคฑ่ดฅ็ๆ็คบใ
|
||||
|
||||
## 4. ๆฐๆฎๆตไธ้ป่พ (Data Flow)
|
||||
|
||||
### 4.1 Server Actions
|
||||
ๆๆๆฐๆฎๅๆดๆไฝๅ้่ฟ `src/modules/textbooks/actions.ts` ๅฎไน็ Server Actions ๅค็๏ผ
|
||||
* `createChapterAction`: ๅๅปบ็ซ ่๏ผๆฏๆๅตๅฅ๏ผใ
|
||||
* `updateChapterContentAction`: ๆดๆฐๆญฃๆๅ
ๅฎนใ
|
||||
* `createKnowledgePointAction`: ๅๅปบ็ฅ่ฏ็นๅนถ่ชๅจๅ
ณ่ๅฝๅ็ซ ่ใ
|
||||
* `updateTextbookAction`: ๆดๆฐๆๆๅ
ๆฐๆฎ๏ผTitle, Subject, Grade, Publisher๏ผใ
|
||||
* `deleteTextbookAction`: ๅ ้คๆๆๅๅ
ถๅ
ณ่ๆฐๆฎใ
|
||||
* `delete...Action`: ๅค็ๅ ้ค้ป่พใ
|
||||
|
||||
### 4.2 ๆฐๆฎ่ฎฟ้ฎๅฑ (Data Access)
|
||||
* **Mock Implementation**: ็ฎๅๅจ `data-access.ts` ไธญไฝฟ็จๅ
ๅญๆฐ็ปๆจกๆๆฐๆฎๅบๆไฝ๏ผๅนถไบบไธบๅขๅ ไบๅปถ่ฟ (`setTimeout`) ไปฅๆต่ฏ Loading ็ถๆใ
|
||||
* **Type Safety**: ๅฎไนไบไธฅๆ ผ็ TypeScript ็ฑปๅ (`Chapter`, `KnowledgePoint`, `UpdateTextbookInput`)๏ผ็กฎไฟๅๅ็ซฏๆฐๆฎๅฅ็บฆไธ่ดใ
|
||||
|
||||
## 5. ็ปไปถๅค็จ
|
||||
* ไฝฟ็จไบ `src/shared/components/ui` ไธญ็ Shadcn ็ปไปถ๏ผ
|
||||
* `Dialog`, `ScrollArea`, `Card`, `Button`, `Input`, `Textarea`, `Select`.
|
||||
* `Collapsible` ็จไบๅฎ็ฐ้ๅฝ็ซ ่ๆ ใ
|
||||
* ๅพๆ ๅบ็ปไธไฝฟ็จ `lucide-react`.
|
||||
|
||||
## 6. Settings ๅ่ฝๅฎ็ฐ (New)
|
||||
* **ๅ
ฅๅฃ**: ่ฏฆๆ
้กตๅณไธ่ง็ "Settings" ๆ้ฎใ
|
||||
* **็ปไปถ**: `TextbookSettingsDialog`ใ
|
||||
* **ๅ่ฝ**:
|
||||
* **Edit**: ไฟฎๆนๆๆ็ๅบๆฌไฟกๆฏใ
|
||||
* **Delete**: ๆไพ็บข่ฒๅ ้คๆ้ฎ๏ผไบๆฌก็กฎ่ฎคๅๆง่กๅ ้คๅนถ่ทณ่ฝฌๅๅ่กจ้กตใ
|
||||
|
||||
## 7. ๅ็ปญ่ฎกๅ (Next Steps)
|
||||
* [ ] **ๅฏๆๆฌ็ผ่พๅจ**: ้ๆ Tiptap ๆฟๆข็ฐๆ็ Markdown Textarea๏ผๆฏๆๆดไธฐๅฏ็ๆ ผๅผใ
|
||||
* [ ] **ๆๆฝๆๅบ**: ๅฎ็ฐ็ซ ่ๆ ็ๆๆฝๆๅบ (`dnd-kit`)ใ
|
||||
* [ ] **ๆฐๆฎๅบๅฏนๆฅ**: ๅฐ `data-access.ts` ไธญ็ Mock ้ป่พๆฟๆขไธบ็ๅฎ็ `drizzle-orm` ๆฐๆฎๅบ่ฐ็จใ
|
||||
87
docs/design/004_question_bank_implementation.md
Normal file
87
docs/design/004_question_bank_implementation.md
Normal file
@@ -0,0 +1,87 @@
|
||||
# Question Bank Module Implementation
|
||||
|
||||
## 1. Overview
|
||||
The Question Bank module (`src/modules/questions`) is a core component for teachers to manage their examination resources. It implements a comprehensive CRUD interface with advanced filtering and batch operations.
|
||||
|
||||
**Status**: IMPLEMENTED
|
||||
**Date**: 2025-12-23
|
||||
**Author**: Senior Frontend Engineer
|
||||
|
||||
---
|
||||
|
||||
## 2. Architecture & Tech Stack
|
||||
|
||||
### 2.1 Vertical Slice Architecture
|
||||
Following the project's architectural guidelines, all question-related logic is encapsulated within `src/modules/questions`:
|
||||
- `components/`: UI components (Data Table, Dialogs, Filters)
|
||||
- `actions.ts`: Server Actions for data mutation
|
||||
- `data-access.ts`: Database query logic
|
||||
- `schema.ts`: Zod schemas for validation
|
||||
- `types.ts`: TypeScript interfaces
|
||||
|
||||
### 2.2 Key Technologies
|
||||
- **Data Grid**: `@tanstack/react-table` for high-performance rendering.
|
||||
- **State Management**: `nuqs` for URL-based state (filters, search).
|
||||
- **Forms**: `react-hook-form` + `zod` + `shadcn/ui` form components.
|
||||
- **Validation**: Strict server-side and client-side validation using Zod schemas.
|
||||
|
||||
---
|
||||
|
||||
## 3. Component Design
|
||||
|
||||
### 3.1 QuestionDataTable (`question-data-table.tsx`)
|
||||
- **Features**: Pagination, Sorting, Row Selection.
|
||||
- **Performance**: Uses `React.memo` compatible patterns where possible (though `useReactTable` itself is not memoized).
|
||||
- **Responsiveness**: Mobile-first design with horizontal scroll for complex columns.
|
||||
|
||||
### 3.2 QuestionColumns (`question-columns.tsx`)
|
||||
Custom cell renderers for rich data display:
|
||||
- **Type Badge**: Color-coded badges for different question types (Single Choice, Multiple Choice, etc.).
|
||||
- **Difficulty**: Visual indicator with color (Green -> Red) and numerical value.
|
||||
- **Actions**: Dropdown menu for Edit, Delete, View Details, and Copy ID.
|
||||
|
||||
### 3.3 Create/Edit Dialog (`create-question-dialog.tsx`)
|
||||
A unified dialog component for both creating and editing questions.
|
||||
- **Dynamic Fields**: Shows/hides "Options" field based on question type.
|
||||
- **Interactive Options**: Allows adding/removing/reordering options for choice questions.
|
||||
- **Optimistic UI**: Shows loading states during submission.
|
||||
|
||||
### 3.4 Filters (`question-filters.tsx`)
|
||||
- **URL Sync**: All filter states (Search, Type, Difficulty) are synced to URL parameters.
|
||||
- **Debounce**: Search input uses debounce to prevent excessive requests.
|
||||
- **Server Filtering**: Filtering logic is executed on the server side (currently simulated in `page.tsx`, ready for DB integration).
|
||||
|
||||
---
|
||||
|
||||
## 4. Implementation Details
|
||||
|
||||
### 4.1 Data Flow
|
||||
1. **Read**: `page.tsx` (Server Component) fetches data based on `searchParams`.
|
||||
2. **Write**: Client components invoke Server Actions (simulated) -> Revalidate Path -> UI Updates.
|
||||
3. **Filter**: User interaction -> Update URL -> Server Component Re-render -> New Data.
|
||||
|
||||
### 4.2 Type Safety
|
||||
A shared `Question` interface ensures consistency across the stack:
|
||||
```typescript
|
||||
export interface Question {
|
||||
id: string;
|
||||
content: any; // Rich text structure
|
||||
type: QuestionType;
|
||||
difficulty: number;
|
||||
// ... relations
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 UI/UX Standards
|
||||
- **Empty States**: Custom `EmptyState` component when no data matches.
|
||||
- **Loading States**: Skeleton screens for table loading.
|
||||
- **Feedback**: `Sonner` toasts for success/error notifications.
|
||||
- **Confirmation**: `AlertDialog` for destructive actions (Delete).
|
||||
|
||||
---
|
||||
|
||||
## 5. Next Steps
|
||||
- [ ] Integrate with real Database (replace Mock Data).
|
||||
- [ ] Implement Rich Text Editor (Slate.js / Tiptap) for question content.
|
||||
- [ ] Add "Batch Import" functionality.
|
||||
- [ ] Implement "Tags" management for Knowledge Points.
|
||||
90
docs/design/005_exam_module_implementation.md
Normal file
90
docs/design/005_exam_module_implementation.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# ่่ฏๆจกๅๅฎ็ฐ่ฎพ่ฎกๆๆกฃ
|
||||
|
||||
## 1. ๆฆ่ฟฐ
|
||||
่่ฏๆจกๅๆไพไบไธไธชๅฎๆด็่ฏไผฐ็ฎก็็ๅฝๅจๆ๏ผไฝฟๆๅธ่ฝๅคๅๅปบ่่ฏใ็ปๅท๏ผๆฏๆๅตๅฅๅ็ป๏ผใๅๅธ่ฏไผฐไปฅๅๅฏนๅญฆ็็ๆไบค่ฟ่ก่ฏๅใ
|
||||
|
||||
## 2. ๆฐๆฎๆถๆ
|
||||
|
||||
### 2.1 ๆ ธๅฟๅฎไฝ
|
||||
- **Exams**: ๆ นๅฎไฝ๏ผๅ
ๅซๅ
ๆฐๆฎ๏ผๆ ้ขใๆถ้ดๅฎๆ๏ผๅ็ปๆไฟกๆฏใ
|
||||
- **ExamQuestions**: ๅ
ณ็ณป้พๆฅ๏ผ็จไบๆฅ่ฏข้ข็ฎ็ไฝฟ็จๆ
ๅต๏ผๆๅนณๅ่กจ็คบ๏ผใ
|
||||
- **ExamSubmissions**: ๅญฆ็็่่ฏๅฐ่ฏ่ฎฐๅฝใ
|
||||
- **SubmissionAnswers**: ้พๆฅๅฐ็นๅฎ้ข็ฎ็ๅไธช็ญๆกใ
|
||||
|
||||
### 2.2 `structure` ๅญๆฎต
|
||||
ไธบไบๆฏๆๅฑ็บงๅธๅฑ๏ผๅฆ็ซ ่/ๅ็ป๏ผ๏ผๆไปฌๅจ `exams` ่กจไธญๅผๅ
ฅไบไธไธช JSON ๅ `structure`ใ่ฟไฝไธบ่่ฏๅธๅฑ็โๅไธไบๅฎๆฅๆบโ๏ผSource of Truth๏ผใ
|
||||
|
||||
**JSON Schema:**
|
||||
```typescript
|
||||
type ExamNode = {
|
||||
id: string; // ่็น็ๅฏไธ UUID
|
||||
type: 'group' | 'question';
|
||||
title?: string; // 'group' ็ฑปๅๅฟ
ๅกซ
|
||||
questionId?: string; // 'question' ็ฑปๅๅฟ
ๅกซ
|
||||
score?: number; // ๅจๆญค่่ฏไธไธๆไธญ็ๅๅผ
|
||||
children?: ExamNode[]; // 'group' ็ฑปๅ็้ๅฝๅญ่็น
|
||||
}
|
||||
```
|
||||
|
||||
## 3. ็ปไปถๆถๆ
|
||||
|
||||
### 3.1 ็ปๅท๏ผๆๅปบๅจ๏ผ
|
||||
ไฝไบ `/teacher/exams/[id]/build`ใ
|
||||
|
||||
- **`ExamAssembly` (ๅฎขๆท็ซฏ็ปไปถ)**
|
||||
- ็ฎก็ `structure` ็ถๆๆ ใ
|
||||
- ๅค็โๆทปๅ ้ข็ฎโใโๆทปๅ ็ซ ่โใโ็งป้คโๅโ้ๆฐๆๅบโๆไฝใ
|
||||
- ๅฎๆถ่ฎก็ฎๆปๅๅ่ฟๅบฆใ
|
||||
- **`StructureEditor` (ๅฎขๆท็ซฏ็ปไปถ)**
|
||||
- ๅบไบ `@dnd-kit` ๆๅปบใ
|
||||
- ๆไพๅตๅฅ็ๅฏๆๅบ๏ผSortable๏ผ็้ขใ
|
||||
- ๆฏๆๅจ็ปๅ
/็ป้ดๆๆฝ้ข็ฎ๏ผๅฝๅไผๅไธบ 2 ๅฑๆทฑๅบฆ๏ผใ
|
||||
- **`QuestionBankList`**
|
||||
- ๅฏๆ็ดข/็ญ้็ๅฏ็จ้ข็ฎๅ่กจใ
|
||||
- โๆทปๅ โๆไฝๅฐ่็น่ฟฝๅ ๅฐ็ปๆๆ ไธญใ
|
||||
|
||||
### 3.2 ้
ๅท็้ข
|
||||
ไฝไบ `/teacher/exams/grading/[submissionId]`ใ
|
||||
|
||||
- **`GradingView` (ๅฎขๆท็ซฏ็ปไปถ)**
|
||||
- **ๅทฆไพง้ขๆฟ**: ๅช่ฏป่งๅพ๏ผๆพ็คบๅญฆ็็็ญๆกไธ้ข็ฎๅ
ๅฎนใ
|
||||
- **ๅณไพง้ขๆฟ**: ่ฏๅๅๅ้ฆ็่พๅ
ฅๅญๆฎตใ
|
||||
- **็ถๆ**: ๅจๆไบคๅ็ฎก็ๆฌๅฐๆดๆนใ
|
||||
- **Actions**: `gradeSubmissionAction` ๆดๆฐ `submissionAnswers` ๅนถๅฐๆปๅ่ๅๅฐ `examSubmissions`ใ
|
||||
|
||||
## 4. ๅ
ณ้ฎๅทฅไฝๆต
|
||||
|
||||
### 4.1 ๅๅปบไธๆๅปบ่่ฏ
|
||||
1. **ๅๅปบ**: ๆๅธ่พๅ
ฅๅบๆฌไฟกๆฏ๏ผๆ ้ขใ็ง็ฎ๏ผใๆฐๆฎๅบๅๅปบ่ฎฐๅฝ๏ผ่็จฟ็ถๆ๏ผใ
|
||||
2. **ๆๅปบ**:
|
||||
- ๆๅธๆๅผโๆๅปบโ้กต้ขใ
|
||||
- ๆๅกๅจไปๆฐๆฎๅบ Hydrate๏ผๆณจๆฐด๏ผ`initialStructure`ใ
|
||||
- ๆๅธไป้ขๅบๆๆฝ้ข็ฎๅฐ็ปๆๆ ใ
|
||||
- ๆๅธๅๅปบ็ซ ่๏ผๅ็ป๏ผใ
|
||||
- **ไฟๅญ**: ๅๆถๆไบค `questionsJson`๏ผๆๅนณๅ๏ผ็จไบ็ดขๅผ๏ผๅ `structureJson`๏ผๆ ็ถ๏ผ็จไบๅธๅฑ๏ผๅฐ `updateExamAction`ใ
|
||||
3. **ๅๅธ**: ็ถๆๅๆดไธบ `published`ใ
|
||||
|
||||
### 4.2 ้
ๅทๆต็จ
|
||||
1. **ๅ่กจ**: ๆๅธๆฅ็ `submission-data-table`ใ
|
||||
2. **่ฏๅ**: ๆๅผ็นๅฎๆไบคใ
|
||||
3. **ๅฎกๆฅ**: ้ๅ้ข็ฎใ
|
||||
- ็ณป็ปๆพ็คบๅญฆ็็ญๆกใ
|
||||
- ๆๅธ่พๅ
ฅๅๆฐ๏ผไธ้ไธบๆปกๅ๏ผๅๅ้ฆใ
|
||||
4. **ๆไบค**: ๆๅกๅจๆดๆฐๅไธช็ญๆก่ฎฐๅฝๅนถ้ๆฐ่ฎก็ฎๆไบคๆปๅใ
|
||||
|
||||
## 5. ๆๆฏๅณ็ญ
|
||||
|
||||
### 5.1 ๆททๅๅญๅจ็ญ็ฅ
|
||||
ๆไปฌๅจๅญๅจ่่ฏ้ข็ฎๆถ้็จไบ **ๆททๅๆนๆณ**๏ผ
|
||||
- **ๅ
ณ็ณปๅ (`exam_questions`)**: ็จไบโๆฅๆพๆๆไฝฟ็จ้ข็ฎ X ็่่ฏโๆฅ่ฏขๅๅค้ฎ็บฆๆใ
|
||||
- **ๆๆกฃๅ (`exams.structure`)**: ็จไบๆธฒๆๅตๅฅ UI ๅไฟ็ไปปๆๆๅบ/ๅ็ปใ
|
||||
*็็ฑ*: ่ฟ็ปๅไบ SQL ็ๅฎๆดๆงๅ NoSQL ๅจ UI ๅธๅฑไธ็็ตๆดปๆงใ
|
||||
|
||||
### 5.2 ๆๆฝๅ่ฝ
|
||||
ไฝฟ็จ `@dnd-kit` ไปฃๆฟๆงๅบ๏ผๅ ไธบ๏ผ
|
||||
- ๆดๅฅฝ็ๆ ้็ขๆฏๆ๏ผ้ฎ็ๆฏๆ๏ผใ
|
||||
- ๆจกๅๅๆถๆ๏ผSensors, Modifiers๏ผใ
|
||||
- ้ขๅๆชๆฅ๏ผ็ฐไปฃ React Hooks ๆจกๅผ๏ผใ
|
||||
|
||||
### 5.3 Server Actions
|
||||
ๆๆๅๆดๆไฝ๏ผไฟๅญ่็จฟใๅๅธใ่ฏๅ๏ผๅไฝฟ็จ Next.js Server Actions๏ผไปฅ็กฎไฟ็ฑปๅๅฎๅ
จๅนถ่ชๅจ้ๆฐ้ช่ฏ็ผๅญใ
|
||||
258
docs/design/design_system.md
Normal file
258
docs/design/design_system.md
Normal file
@@ -0,0 +1,258 @@
|
||||
# Next_Edu Design System Specs
|
||||
|
||||
**Version**: 1.4.0 (Updated)
|
||||
**Status**: ACTIVE
|
||||
**Role**: Chief Creative Director
|
||||
**Philosophy**: "Data as Art" - Clean, Minimalist, Information-Dense.
|
||||
|
||||
---
|
||||
|
||||
## 1. ๆ ธๅฟ็ๅฟต (Core Philosophy)
|
||||
|
||||
Next_Edu ๆจๅจๅฏนๆๆ่ฒ็ณป็ปๅธธ่ง็ไฟกๆฏ่ฟ่ฝฝใๆไปฌ็่ฎพ่ฎก้ฃๆ ผๆทฑๅ **International Typographic Style (ๅฝ้
ไธปไน่ฎพ่ฎก้ฃๆ ผ)** ๅฝฑๅใ
|
||||
|
||||
* **Precision (็ฒพๅ)**: ๆฏไธไธชๅ็ด ็็็ฝ้ฝๆๅ
ถ็ฎ็ใ
|
||||
* **Clarity (ๆธ
ๆฐ)**: ้่ฟๆ็ๅๅฏนๆฏๅบฆๅบๅๅฑ็บง๏ผ่้่ฃ
้ฅฐๆง็่ฒๅใ
|
||||
* **Efficiency (ๆ็)**: ไธไธบ้ซๅฏๅบฆๆฐๆฎๆไฝไผๅ๏ผๅๅฐ่ง่งๅช้ณใ
|
||||
|
||||
---
|
||||
|
||||
## 2. ่ง่งๅบ็ก (Visual Foundation)
|
||||
|
||||
### 2.1 ่ฒๅฝฉ็ณป็ป (Color System)
|
||||
|
||||
ๆไปฌๆพๅผ Hex ็ด้๏ผๅ
จ้ข้็จ **HSL ่ฏญไนๅๅ้** ไปฅๆฏๆๅฎ็พ็ๅคไธป้ข้้
ใ
|
||||
|
||||
#### **Base (ๅบ่ฐ)**
|
||||
* **Neutral**: Zinc (้่ฒ). ๅทๅณปใ็บฏๅ๏ผๆ ๅ่ฒใ
|
||||
* **Brand**: Deep Indigo (ๆทฑ้่).
|
||||
* `Primary`: ไธไธใๆๅจ๏ผ้ฟๅ
ๅนผ็จ็้ซ้ฅฑๅ่ใ
|
||||
* ่ฏญไน: `hsl(var(--primary))`
|
||||
|
||||
#### **Functional (ๅ่ฝ่ฒ)**
|
||||
| ่ฏญไน | ่ฒ็ณป | ็จ้ |
|
||||
| :--- | :--- | :--- |
|
||||
| **Destructive** | Red | ๅ ้คใๅฑ้ฉๆไฝใ็ณป็ป้่ฏฏ |
|
||||
| **Warning** | Amber | ้ๆณจๆ็็ถๆใ้้ปๆญๆง่ญฆๅ |
|
||||
| **Success** | Emerald | ๆไฝๆๅใ็ถๆๆญฃๅธธ |
|
||||
| **Info** | Blue | ไธ่ฌๆงๆ็คบใๅธฎๅฉไฟกๆฏ |
|
||||
|
||||
#### **Surface Hierarchy (ๅฑ็บง)**
|
||||
1. **Background**: ๅบ็จๅบๅฑ่ๆฏใ
|
||||
2. **Card**: ๅ
ๅฎนๆฟ่ฝฝๅฎนๅจ๏ผ่ฝปๅพฎๆๅๅฑ็บงใ
|
||||
3. **Popover**: ๆฌๆตฎๅฑใไธๆ่ๅ๏ผๆ้ซๅฑ็บงใ
|
||||
4. **Muted**: ็จไบๆฌก็บงไฟกๆฏๆ็ฆ็จ็ถๆ่ๆฏใ
|
||||
|
||||
### 2.2 ๆ็ (Typography)
|
||||
|
||||
* **Font Family**: `Geist Sans` > `Inter` > `System UI`.
|
||||
* *Requirement*: ๅฟ
้กปๅผๅฏ `tabular-nums` (็ญๅฎฝๆฐๅญ) ็นๆง๏ผ็กฎไฟ่กจๆ ผๆฐๆฎๅฏน้ฝใ
|
||||
* **Scale**:
|
||||
* **Base Body**: 14px (0.875rem) - ๆๅไฟกๆฏๅฏๅบฆใ
|
||||
* **H1 (Page Title)**: 24px, Tracking -0.02em, Weight 600.
|
||||
* **H2 (Section Title)**: 20px, Tracking -0.01em, Weight 600.
|
||||
* **H3 (Card Title)**: 16px, Weight 600.
|
||||
* **Tiny/Caption**: 12px, Text-Muted-Foreground.
|
||||
|
||||
### 2.3 ่ดจๆ (Look & Feel)
|
||||
|
||||
* **Borders**: `1px solid var(--border)`. ็้ข้ชจๆถ๏ผไปฅๆญคๅๅฒๅบๅ่้่ๆฏ่ฒๅใ
|
||||
* **Radius**:
|
||||
* `sm` (4px): Badges, Checkboxes.
|
||||
* `md` (8px): **Default**. Buttons, Inputs, Cards.
|
||||
* `lg` (12px): Modals, Dialogs.
|
||||
* **Shadows**:
|
||||
* Default: None (Flat).
|
||||
* Hover: `shadow-sm` (ไป
็จไบๅฏไบคไบๅ
็ด ).
|
||||
* Dropdown/Popover: `shadow-md`.
|
||||
* *Ban*: ็ฆๆญขไฝฟ็จๅคง้ข็งฏๅผฅๆฃ้ดๅฝฑใ
|
||||
|
||||
---
|
||||
|
||||
## 3. ๆ ธๅฟๅธๅฑ (App Shell)
|
||||
|
||||
### 3.1 ๆถๆ (Architecture)
|
||||
ๆไปฌ้็จไบ `SidebarProvider` + `AppSidebar` ็็ปๅๆจกๅผ๏ผ็กฎไฟไบๅธๅฑ็็ตๆดปๆงๅ็งปๅจ็ซฏ็ๅฎ็พ้้
ใ
|
||||
|
||||
* **Provider**: `SidebarProvider` (src/modules/layout/components/sidebar-provider.tsx)
|
||||
* ็ฎก็ไพง่พนๆ ็ถๆ (`expanded`, `isMobile`).
|
||||
* ่ด่ดฃๅจ็งปๅจ็ซฏๆธฒๆ Sheet (Drawer)ใ
|
||||
* ่ด่ดฃๅจๆก้ข็ซฏๆธฒๆ Sticky Sidebarใ
|
||||
* **Key Prop**: `sidebar` (ๆพๅผไผ ้ไพง่พนๆ ็ปไปถ)ใ
|
||||
|
||||
### 3.2 ๅธๅฑ็ปๆ
|
||||
```
|
||||
+-------------------------------------------------------+
|
||||
| Sidebar | Header (Sticky) |
|
||||
| |-------------------------------------------|
|
||||
| (Collap- | Main Content |
|
||||
| sible) | |
|
||||
| | +-------------------------------------+ |
|
||||
| | | Card | |
|
||||
| | | +---------------------------------+ | |
|
||||
| | | | Data Table | | |
|
||||
| | | +---------------------------------+ | |
|
||||
| | +-------------------------------------+ |
|
||||
| | |
|
||||
+-------------------------------------------------------+
|
||||
```
|
||||
|
||||
### 3.3 ่ฏฆ็ป่ง่
|
||||
|
||||
#### **Sidebar (ไพง่พนๆ )**
|
||||
* **Width**: Expanded `260px` | Collapsed `64px` | Mobile `Sheet (Drawer)`.
|
||||
* **Behavior**:
|
||||
* Desktop: ๅบๅฎๅทฆไพง๏ผๆฏๆๆๅ ใ
|
||||
* Mobile: ้ป่ฎค้่๏ผ็นๅปๆฑๅ ก่ๅไปๅทฆไพงๆปๅบใ
|
||||
* **Navigation Item**:
|
||||
* Height: `36px` (Compact).
|
||||
* State:
|
||||
* `Inactive`: `text-muted-foreground hover:text-foreground`.
|
||||
* `Active`: `bg-sidebar-accent text-sidebar-accent-foreground font-medium`.
|
||||
|
||||
#### **Header (้กถๆ )**
|
||||
* **Height**: `64px` (h-16).
|
||||
* **Layout**: `flex items-center justify-between px-6 border-b`.
|
||||
* **Components**:
|
||||
1. **Breadcrumb**: ๆพ็คบๅฝๅ่ทฏๅพ๏ผๅฑ็บงๆธ
ๆฐใ
|
||||
2. **Global Search**: `Cmd+K` ่งฆๅ๏ผๅฑ
ไธญๆ้ ๅณใ
|
||||
3. **User Nav**: ๅคดๅ + ไธๆ่ๅใ
|
||||
|
||||
#### **Main Content (ๅ
ๅฎนๅบ)**
|
||||
* **Padding**: `p-6` (Desktop) / `p-4` (Mobile).
|
||||
* **Max Width**: `max-w-[1600px]` (้ป่ฎค) ๆ `w-full` (้ๅฏน่ถ
ๅฎฝๆฅ่กจ)ใ
|
||||
|
||||
---
|
||||
|
||||
## 4. ๅฏผ่ชไธ่ง่ฒ็ณป็ป (Navigation & Roles)
|
||||
|
||||
Next_Edu ๆฏๆๅค่ง่ฒ๏ผMulti-Tenant / Role-Based๏ผๅฏผ่ช็ณป็ปใ
|
||||
|
||||
### 4.1 ้
็ฝฎๆไปถ
|
||||
ๅฏผ่ช็ปๆๅทฒไป UI ็ปไปถไธญ่งฃ่ฆ๏ผ็ปไธ้
็ฝฎๅจ๏ผ
|
||||
`src/modules/layout/config/navigation.ts`
|
||||
|
||||
### 4.2 ๆฏๆ็่ง่ฒ (Roles)
|
||||
็ณป็ปๅ
็ฝฎๆฏๆไปฅไธ่ง่ฒ๏ผๆฏไธช่ง่ฒๆฅๆ็ฌ็ซ็ไพง่พนๆ ่ๅ็ปๆ๏ผ
|
||||
* **Admin**: ็ณป็ป็ฎก็ๅ๏ผๆฅๆๆๆ็ฎก็ๆ้ (School Management, User Management, Finance)ใ
|
||||
* **Teacher**: ๆๅธ๏ผๅ
ณๆณจ็ญ็บง็ฎก็ (My Classes)ใๆ็ปฉๅฝๅ
ฅ (Gradebook) ๅๆฅ็จใ
|
||||
* **Student**: ๅญฆ็๏ผๅ
ณๆณจ่ฏพ็จๅญฆไน (My Learning) ๅไฝไธๆไบคใ
|
||||
* **Parent**: ๅฎถ้ฟ๏ผๅ
ณๆณจๅญๅฅณๅจๆๅๅญฆ่ดน็ผด็บณใ
|
||||
|
||||
### 4.3 ๅผๅไธ่ฐ่ฏ
|
||||
* **View As (Dev Mode)**: ๅจๅผๅ็ฏๅขไธ๏ผไพง่พนๆ ้กถ้จๆไพ "View As" ไธๆ่ๅ๏ผๅ
่ฎธๅผๅ่
ๅฎๆถๅๆข่ง่ฒ่ง่ง๏ผ้ข่งไธๅ่ง่ฒ็ๅฏผ่ช็ปๆใ
|
||||
* **Implementation**: `AppSidebar` ็ปไปถ้่ฟ่ฏปๅ `NAV_CONFIG[currentRole]` ๅจๆๆธฒๆ่ๅ้กนใ
|
||||
|
||||
---
|
||||
|
||||
## 5. ้่ฏฏๅค็ไธ่พน็ๆ
ๅต (Error Handling & Boundaries)
|
||||
|
||||
็ณป็ปๅฟ
้กปไผ้
ๅฐๅค็้่ฏฏๅ่พน็ผๆ
ๅต๏ผ้ฟๅ
็ฝๅฑๆๆ ๅ้ฆใ
|
||||
|
||||
### 5.1 ๅ
จๅฑ้่ฏฏ่พน็ (Global Error Boundary)
|
||||
* **Scope**: ๆ่ทๆธฒๆๆ้ด็ๆชๅค็ๅผๅธธใ
|
||||
* **UI**: ๆพ็คบๅๅฅฝ็้่ฏฏ้กต้ข๏ผ้ๆๆฏๅ ๆ ไฟกๆฏ๏ผ๏ผๆไพ "Try Again" ๆ้ฎ้็ฝฎ็ถๆใ
|
||||
* **Implementation**: ไฝฟ็จ React `ErrorBoundary` ๆ Next.js `error.tsx`ใ
|
||||
|
||||
### 5.2 404 Not Found
|
||||
* **Design**: ๅฟ
้กปไฟ็ App Shell (Sidebar + Header)๏ผไป
ๅจ Main Content ๅบๅๆพ็คบ 404 ๆ็คบใ
|
||||
* **Content**: "Page not found" ๆๆก + ่ฟๅ Dashboard ็ไธปๆไฝๆ้ฎใ
|
||||
|
||||
### 5.3 ็ฉบ็ถๆ (Empty States)
|
||||
ๅฝๅ่กจๆ่กจๆ ผๆ ๆฐๆฎๆถ๏ผ**ไธฅ็ฆ**ๅชๆพ็คบ็ฉบ็ฝใ
|
||||
* **Component**: `EmptyState`ใ
|
||||
* **Composition**:
|
||||
1. **Icon**: ็บฟๆง้ฃๆ ผๅพๆ (muted foreground).
|
||||
2. **Title**: ็ฎ็ญ่ฏดๆ (e.g., "No students found").
|
||||
3. **Description**: ่งฃ้ๅๅ ๆไธไธๆญฅๆไฝ (e.g., "Add a student to get started").
|
||||
4. **Action**: (ๅฏ้) "Create New" ๆ้ฎใ
|
||||
|
||||
### 5.4 ๅ ่ฝฝ็ถๆ (Loading States)
|
||||
* **Initial Load**: ไฝฟ็จ `Skeleton` ้ชจๆถๅฑ๏ผๆจกๆๅ
ๅฎนๅธๅฑ๏ผ้ฟๅ
CLS (Content Layout Shift)ใ็ฆๆญขไฝฟ็จๅ
จๅฑ Spinnerใ
|
||||
* **Action Loading**: ๆ้ฎ็นๅปๅ่ฟๅ
ฅ `disabled` + `spinner` ็ถๆใ
|
||||
* **Table Loading**: ่กจๆ ผๅ
ๅฎนๅบๅๆพ็คบ 3-5 ่ก Skeleton Rowsใ
|
||||
|
||||
### 5.5 ่กจๅ้ช่ฏ (Form Validation)
|
||||
* **Style**: ้่ฏฏไฟกๆฏๆพ็คบๅจ่พๅ
ฅๆกไธๆน๏ผๅญๅท `text-xs`๏ผ้ข่ฒ `text-destructive`ใ
|
||||
* **Input**: ่พนๆกๅ็บข (`border-destructive`)ใ
|
||||
|
||||
---
|
||||
|
||||
## 6. ่่ดฃ่พน็ไธๅไฝ (Responsibility Boundaries)
|
||||
|
||||
**[IMPORTANT] ไธฅ็ฆ่ถ็ไฟฎๆน (Strict No-Modification Policy)**
|
||||
|
||||
ไธบไบ็ปดๆคๅคงๅ้กน็ฎ็ๅฏ็ปดๆคๆง๏ผUI ๅทฅ็จๅธๅๅผๅไบบๅๅฟ
้กป้ตๅฎไปฅไธ่พน็่งๅ๏ผ
|
||||
|
||||
### 6.1 ๆจกๅๅๅๅ (Modularity)
|
||||
* **Scope**: ๅผๅ่
ไป
ๅบๅฏนๅ้
็ป่ชๅทฑ็ๆจกๅ่ด่ดฃใไพๅฆ๏ผ่ด่ดฃ "Dashboard" ็ๅผๅ่
**ไธๅบ**ไฟฎๆน "Sidebar" ๆ "Auth" ๆจกๅ็ไปฃ็ ใ
|
||||
* **Dependencies**: ๅฆๆไฝ ็ๆจกๅไพ่ตไบๅ
ถไปๆจกๅ็ๅๆด๏ผ**ๅฟ
้กป**ๅ
ไธ่ฏฅๆจกๅ็่ด่ดฃไบบๆฒ้๏ผๆๅจ PR ไธญๆ็กฎๆ ๆณจใ
|
||||
|
||||
### 6.2 ๅ
ฑไบซ็ปไปถ (Shared Components)
|
||||
* **Immutable Core**: `src/shared/components/ui` ไธ็ๅบ็ก็ปไปถ๏ผๅฆ Button, Card๏ผ่งไธบ**ๆ ธๅฟๅบ**ใ
|
||||
* **Extension**: ๅฆๆๅบ็ก็ปไปถไธ่ฝๆปก่ถณ้ๆฑ๏ผไผๅ
่่็ปๅ๏ผComposition๏ผๆๅๅปบๆฐ็ไธๅก็ปไปถ๏ผ่ไธๆฏไฟฎๆนๆ ธๅฟ็ปไปถ็ๆบ็ ใ
|
||||
* **Modification Request**: ๅชๆๅจๅ็ฐไธฅ้ Bug ๆ้่ฆๅ
จๅฑๆ ทๅผ่ฐๆดๆถ๏ผๆๅ
่ฎธไฟฎๆนๆ ธๅฟ็ปไปถ๏ผไธๅฟ
้กป็ป่ฟ Design Lead ๅฎกๆนใ
|
||||
|
||||
### 6.3 ๆ ทๅผไธ่ดๆง (Consistency)
|
||||
* **Global CSS**: `globals.css` ๅฎไนไบ็ณป็ป็็ฉ็ๆณๅใไธฅ็ฆๅจๅฑ้จ็ปไปถไธญ้ๆ่ฆ็ๅ
จๅฑ CSS ๅ้ใ
|
||||
* **Tailwind Config**: ็ฆๆญข้ๆๅจ็ปไปถไธญๆทปๅ ไปปๆๅผ๏ผArbitrary Values, e.g., `w-[123px]`๏ผ๏ผๅฟ
้กปไฝฟ็จ Design Tokenใ
|
||||
|
||||
---
|
||||
|
||||
## 7. ็ปไปถ่ฎพ่ฎก่ง่ (Component Specs)
|
||||
|
||||
### 7.1 Card (ๅก็)
|
||||
ๅก็ๆฏไฟกๆฏ็ป็ป็ๅบๆฌๅๅ
ใ
|
||||
* **Class**: `bg-card text-card-foreground border rounded-lg shadow-none`.
|
||||
* **Header**: `p-6 pb-2`. Title (`font-semibold leading-none tracking-tight`).
|
||||
* **Content**: `p-6 pt-0`.
|
||||
|
||||
### 7.2 Data Table (ๆฐๆฎ่กจๆ ผ)
|
||||
ๆๅก็ณป็ป็ๆ ธๅฟ็ปไปถใ
|
||||
* **Density**:
|
||||
* `Default`: Row Height `48px` (h-12).
|
||||
* `Compact`: Row Height `36px` (h-9).
|
||||
* **Header**: `bg-muted/50 text-muted-foreground text-xs uppercase font-medium`.
|
||||
* **Stripes**: ้ป่ฎคๅ
ณ้ญใไป
ๅจๅๆฐ > 8 ๆถๅผๅฏ `even:bg-muted/50`ใ
|
||||
* **Actions**: ่กๆไฝๆ้ฎๅบ้ป่ฎค้ๅฝข (`opacity-0`)๏ผHover ๆถๆพ็คบ (`group-hover:opacity-100`)๏ผๅๅฐ่ง่งๅนฒๆฐใ
|
||||
|
||||
### 7.3 Feedback (ๅ้ฆไธ้็ฅ)
|
||||
* **Toast**: ไฝฟ็จ `Sonner` ็ปไปถใ
|
||||
* ไฝ็ฝฎ: ้ป่ฎคๅณไธ่ง (Bottom Right).
|
||||
* ๆ ทๅผ: ๆ็ฎ้ป็ฝ้ฃๆ ผ (่ท้ไธป้ข)๏ผๆฏๆๆค้ๆไฝใ
|
||||
* ่ฐ็จ: `toast("Event has been created", { description: "Sunday, December 03, 2023 at 9:00 AM" })`.
|
||||
* **Skeleton**: ๅ ่ฝฝ็ถๆๅฟ
้กปไฝฟ็จ Skeleton ้ชจๆถๅฑ๏ผ็ฆๆญขไฝฟ็จๅ
จๅฑ Spinnerใ
|
||||
* **Badge**: ็ถๆๆ็คบๅจใ
|
||||
* `default`: ไธป่ฆ็ถๆ (Primary).
|
||||
* `secondary`: ๆฌก่ฆ็ถๆ (Neutral).
|
||||
* `destructive`: ้่ฏฏ/่ญฆๅ็ถๆ (Error).
|
||||
* `outline`: ๆ่พน้ฃๆ ผ (Subtle).
|
||||
|
||||
---
|
||||
|
||||
## 8. ๅผๅๆๅ (Developer Guide)
|
||||
|
||||
### 8.1 CSS Variables
|
||||
ๆๆ้ข่ฒๅๅ่งๅ้่ฟ CSS ๅ้ๆงๅถ๏ผๅฎไนๅจ `globals.css` ไธญใ็ฆๆญขๅจไปฃ็ ไธญ Hardcode ้ข่ฒๅผ (ๅฆ `#FFFFFF`, `rgb(0,0,0)` )ใ
|
||||
|
||||
### 8.2 Tailwind Utility ไผๅ
|
||||
ไผๅ
ไฝฟ็จ Tailwind Utility Classesใ
|
||||
* โ
`text-sm text-muted-foreground`
|
||||
* โ `.custom-text-class { font-size: 14px; color: #666; }`
|
||||
|
||||
### 8.3 Dark Mode
|
||||
่ฎพ่ฎก็ณป็ปๅ็ๆฏๆๆทฑ่ฒๆจกๅผใๅช่ฆๆญฃ็กฎไฝฟ็จ่ฏญไนๅ้ข่ฒๅ้๏ผๅฆ `bg-background`, `text-foreground`๏ผ๏ผDark Mode ๅฐ่ชๅจๅฎ็พ้้
๏ผๆ ้้ขๅค็ผๅ `dark:` ไฟฎ้ฅฐ็ฌฆ๏ผ้ค้ไธบไบ็นๆฎ่ฐๆด๏ผใ
|
||||
|
||||
### 8.4 ็ปไปถๅบๅผ็จ
|
||||
ๆๆ UI ็ปไปถไฝไบ `src/shared/components/ui`ใ
|
||||
* `Button`: ๅบ็กๆ้ฎ
|
||||
* `Input`: ่พๅ
ฅๆก
|
||||
* `Select`: ไธๆ้ๆฉๅจ (New)
|
||||
* `Sheet`: ไพง่พนๆ /ๆฝๅฑ
|
||||
* `Sonner`: Toast ้็ฅ
|
||||
* `Badge`: ๅพฝ็ซ /ๆ ็ญพ
|
||||
* `Skeleton`: ๅ ่ฝฝๅ ไฝ็ฌฆ
|
||||
* `DropdownMenu`: ไธๆ่ๅ
|
||||
* `Avatar`: ๅคดๅ
|
||||
* `Label`: ่กจๅๆ ็ญพ
|
||||
* `EmptyState`: ็ฉบ็ถๆๅ ไฝ (New)
|
||||
180
docs/product_requirements.md
Normal file
180
docs/product_requirements.md
Normal file
@@ -0,0 +1,180 @@
|
||||
# Next_Edu ไบงๅ้ๆฑๆๆกฃ (PRD) - K12 ๆบๆ
งๆๅญฆ็ฎก็็ณป็ป
|
||||
|
||||
**็ๆฌ**: 2.0.0 (K12 Enterprise Edition)
|
||||
**็ถๆ**: ่งๅไธญ
|
||||
**ๆๅๆดๆฐ**: 2025-12-22
|
||||
**ไฝ่
**: Senior EdTech Product Manager
|
||||
**้็จ่ๅด**: ๅ
จๆ ก็บงๆๅญฆ็ฎก็ (ๆ-่-็ป-่ฏ)
|
||||
|
||||
---
|
||||
|
||||
## 1. ่ง่ฒไธๆ้็ฉ้ต (Complex Role Matrix)
|
||||
|
||||
ๆฌ็ณป็ป้็จๅบไบ RBAC (Role-Based Access Control) ็ๅค็ปดๆ้่ฎพ่ฎก๏ผๅนถ็ปๅ **่ก็บงๅฎๅ
จ (Row-Level Security, RLS)** ็ญ็ฅ๏ผ็กฎไฟๆฐๆฎ้็ฆปไธ่กๆฟ็ฎก็็็ฒพ็กฎๅน้
ใ
|
||||
|
||||
### 1.1 ่ง่ฒๅฎไนไธๆ ธๅฟ่่ดฃ
|
||||
|
||||
| ่ง่ฒ | ๆ ธๅฟ่่ดฃ | ๆ้็นๅพ (Scope) |
|
||||
| :--- | :--- | :--- |
|
||||
| **็ณป็ป็ฎก็ๅ (Admin)** | ๅบ็กๆฐๆฎ็ปดๆคใ่ดฆๅท็ฎก็ใๅญฆๆ่ฎพ็ฝฎ | ๅ
จๅฑ็ณป็ป้
็ฝฎ๏ผไธๅฏ่งฆ็ขฐๆๅญฆไธๅกๆฐๆฎๅ
ๅฎน๏ผ้็งไฟๆค๏ผใ |
|
||||
| **ๆ ก้ฟ (Principal)** | ๅ
จๆ กๆๅญฆๆฆๅต็ๆงใๅฎ่ง็ป่ฎกๆฅ่กจ | **ๅ
จๆ กๅฏ่ง**ใๆฅ็ๆๆๅนด็บงใๅญฆ็ง็็ป่ฎกๆฐๆฎ๏ผๅนณๅๅใไฝไธๅฎๆ็๏ผ๏ผๆ ไฟฎๆนๅ
ทไฝ็้ข็ฎ/ไฝไธๆ้ใ |
|
||||
| **ๅนด็บงไธปไปป (Grade Head)** | ๆฌๅนด็บง่กๆฟ็ฎก็ใ็ญ็บงๅ่กกๅบฆๅๆ | **ๅนด็บงๅฏ่ง**ใ็ฎก็ๆฌๅนด็บงๆๆ่กๆฟ็ญ็บง๏ผๆฅ็ๆฌๅนด็บง่ทจๅญฆ็งๅฏนๆฏ๏ผๆ ๆๅนฒๆถๅ
ถไปๅนด็บงใ |
|
||||
| **ๆ็ ็ป้ฟ (Subject Head)** | ๅญฆ็ง่ตๆบๅปบ่ฎพใๅฝ้ข่ดจ้ๆๆง | **ๅญฆ็งๅฏ่ง**ใ็ฎก็ๆฌๅญฆ็งๅ
ฌๅ
ฑ้ขๅบใๆๆกๆจกๆฟ๏ผๆฅ็ๅ
จๆ ก่ฏฅๅญฆ็งๆๅญฆ่ดจ้๏ผๆ ๆๆฅ็ๅ
ถไปๅญฆ็ง่ฏฆๆ
ใ |
|
||||
| **็ญไธปไปป (Class Teacher)** | ็ญ็บงๅญฆ็็ฎก็ใๅฎถๆ ก้็ฅใ็ปผๅ่ฏไปท | **่กๆฟ็ญๅฏ่ง**ใๆฅ็ๆฌ็ญๆๆๅญฆ็็่ทจๅญฆ็งๆ็ปฉใ่ๅค๏ผๅๅธ็ญ็บงๅ
ฌๅใ |
|
||||
| **ไปป่ฏพ่ๅธ (Teacher)** | ๅค่ฏพใๅบๅทใๆนๆนใไธชๅซ่พ
ๅฏผ | **ๆๅญฆ็ญๅฏ่ง**ใไป
่ฝๆไฝ่ชๅทฑๆๆ็ญ็บง็่ฏฅๅญฆ็งไฝไธ/่่ฏ๏ผ็งๆ้ขๅบ็ฎก็ใ |
|
||||
| **ๅญฆ็ (Student)** | ๅฎๆไฝไธใๅๅ ่่ฏใๆฅ็้้ขๆฌ | **ไธชไบบๅฏ่ง**ใไป
่ฝ่ฎฟ้ฎๅ้
็ป่ชๅทฑ็ไปปๅก๏ผๆฅ็ไธชไบบๆ้ฟๆกฃๆกใ |
|
||||
|
||||
### 1.2 ๅ
ณ้ฎๆ้่พจๆ๏ผๅนด็บงไธปไปป vs ๆ็ ็ป้ฟ
|
||||
|
||||
* **็ปดๅบฆๅทฎๅผ**:
|
||||
* **ๅนด็บงไธปไปป (ๆจชๅ็ฎก็)**: ๅ
ณๆณจ็ๆฏ **"ไบบ" (People & Administration)**ใไพๅฆ๏ผ้ซไธ(3)็ญ็ๆดไฝ็บชๅพๅฆไฝ๏ผ้ซไธๅนด็บงๆดไฝๆฏๅฆๅจๆไธญ่่ฏไธญ่พพๆ ๏ผไปไปฌ้่ฆ่ทจๅญฆ็ง็ๆฐๆฎ่งๅพ๏ผๅฆ๏ผๆๅญฆ็ๆฏๅฆๅ็ง๏ผใ
|
||||
* **ๆ็ ็ป้ฟ (็บตๅ็ฎก็)**: ๅ
ณๆณจ็ๆฏ **"ๅ
ๅฎน" (Content & Pedagogy)**ใไพๅฆ๏ผ่ฑ่ฏญ็ง็ฎ็โ้
่ฏป็่งฃโ้ขๅๅพๅ็ๅ
จๆ กๆฏๅฆๅไฝ๏ผๅ
ฌๅ
ฑ้ขๅบ็้ข็ฎ่ดจ้ๅฆไฝ๏ผไปไปฌ้่ฆ่ทจๅนด็บงไฝๅๅญฆ็ง็ๆทฑๅบฆ่งๅพใ
|
||||
|
||||
* **ๆฐๆฎๅฏ่งๆง (RLS ็ญ็ฅ)**:
|
||||
* `GradeHead_View`: `WHERE class.grade_id = :current_user_grade_id`
|
||||
* `SubjectHead_View`: `WHERE course.subject_id = :current_user_subject_id` (ๅฏ่ฝ่ทจๆๆๅนด็บง)
|
||||
|
||||
---
|
||||
|
||||
## 2. ๆ ธๅฟๅ่ฝๆจกๅๆทฑๅบฆๆ่งฃ
|
||||
|
||||
### 2.1 ๆบ่ฝ้ขๅบไธญๅฟ (Smart Question Bank)
|
||||
|
||||
่ฟๆฏ็ณป็ป็ๆ ธๅฟ่ตไบงๅบ๏ผๅฟ
้กปๆฏๆ้ซๅคๆๅบฆ็้ข็ฎ็ปๆใ
|
||||
|
||||
* **ๅคๅฑๅตๅฅ้ข็ฎ็ปๆ (Nested Questions)**:
|
||||
* **ๅบๆฏ**: ่ฑ่ฏญๅฎๅฝขๅกซ็ฉบใ่ฏญๆ็ฐไปฃๆ้
่ฏปใ็็ปผๅคง้ขใ
|
||||
* **้ป่พ**: ๅผๅ
ฅ **"้ขๅนฒ (Stem)"** ไธ **"ๅญ้ข (Sub-question)"** ็ๆฆๅฟตใ
|
||||
* **็ถ้ข (Parent)**: ๆฟ่ฝฝๅ
ฌๅ
ฑ้ขๅนฒ๏ผๅฆไธ็ฏ 500 ๅญ็ๆ็ซ ใไธๅผ ็ฉ็ๅฎ้ชๅพ่กจ๏ผใ้ๅธธไธ็ดๆฅ่ฎพๅ๏ผๆ่
่ฎพๆปๅใ
|
||||
* **ๅญ้ข (Child)**: ไพ้ไบ็ถ้ข๏ผๆฏๅ
ทไฝ็็ญ้ข็น๏ผ้ๆฉใๅกซ็ฉบใ็ฎ็ญ๏ผใๆฏไธชๅญ้ขๆ็ฌ็ซ็ๅๅผใ็ญๆกๅ่งฃๆใ
|
||||
* **ไบคไบ**: ็ปๅทๆถ๏ผๆๅจโ็ถ้ขโ๏ผๆๆโๅญ้ขโๅฟ
้กปไฝไธบไธไธชๅๅญๆดไฝ่ท้็งปๅจ๏ผไธๅฏๆๅใ
|
||||
|
||||
* **็ฅ่ฏ็นๅพ่ฐฑ (Knowledge Graph)**:
|
||||
* **็ปๆ**: ๆ ็ถ็ปๆ (Tree)ใไพๅฆ๏ผ`ๆฐๅญฆ -> ไปฃๆฐ -> ๅฝๆฐ -> ไบๆฌกๅฝๆฐ -> ไบๆฌกๅฝๆฐ็ๅพๅ`ใ
|
||||
* **ๅ
ณ่**:
|
||||
* **ๅคๅฏนๅค (Many-to-Many)**: ไธ้้ขๅฏ่ฝ่ๅฏๅคไธช็ฅ่ฏ็น๏ผ็ปผๅ้ข๏ผใ
|
||||
* **ๆ้**: (ๅฏ้้ซ็บง้ๆฑ) ๆ ่ฎฐไธป่ฆ่็นไธๆฌก่ฆ่็นใ
|
||||
|
||||
### 2.2 ่ฏพๆฌไธๅคง็บฒๆ ๅฐ (Textbook & Curriculum)
|
||||
|
||||
* **่ฏพๆฌๆฐๅญๅ**:
|
||||
* ็ณป็ป้ข็ฝฎไธปๆตๆๆ็ๆฌ (ๅฆไบบๆ็ใๅๅธๅคง็)ใ
|
||||
* **ๆ ธๅฟๆ ๅฐ**: `Textbook Chapter` (่ฏพๆฌ็ซ ่) <--> `Knowledge Point` (็ฅ่ฏ็น)ใ
|
||||
* **ไปทๅผ**: ่ๅธๅค่ฏพๆถ๏ผๅช้้ๆฉโๅฟ
ไฟฎไธ ็ฌฌไธ็ซ โ๏ผ็ณป็ป่ชๅจๆจ่ๅ
ณ่็โ้ๅโ็ธๅ
ณ้ข็ฎ๏ผๆ ้ๆๅจๅปๆตท้้ขๅบๆ็ดขใ
|
||||
|
||||
### 2.3 ่ฏๅท/ไฝไธ็ป่ฃ
ๅผๆ (Assembly Engine)
|
||||
|
||||
* **ๆบ่ฝ็ญ้**: ๆฏๆไบค้็ญ้๏ผๅๆถๅ
ๅซโๅๅญฆโๅโไธ่งๅฝๆฐโ็้ข็ฎ๏ผใ
|
||||
* **AB ๅท็ๆ**: ้ๅฏน้ฒไฝๅผๅบๆฏ๏ผๆฏๆ้ข็ฎไนฑๅบๆ้้กนไนฑๅบ๏ผShuffle๏ผใ
|
||||
* **ไฝไธๅๅฑ**: ๆฏๆโๅฟ
ๅ้ขโไธโ้ๅ้ขโ่ฎพ็ฝฎ๏ผๆปก่ถณๅๅฑๆๅญฆ้ๆฑใ
|
||||
|
||||
### 2.4 ๆถๆฏ้็ฅไธญๅฟ (Notification System)
|
||||
|
||||
ๅ็บงๅ็ญ็ฅ็ๆถๆฏๅๅ๏ผ
|
||||
|
||||
* **ๅผบๆ้ (High Priority)**: ็ณป็ปๅ
ฌๅใ่่ฏๅผๅงๆ้ใ้่ฟ็ซๅ
ไฟก + ๅผน็ช + (้ๆ)็ญไฟก/ๅพฎไฟกๆจกๆฟๆถๆฏใ
|
||||
* **ไธๅกๆต (Medium Priority)**: ไฝไธๅๅธใๆ็ปฉๅบ็ใ็ซๅ
็บข็น + ๅ่กจๆจ้ใ
|
||||
* **ๅผฑๆ้ (Low Priority)**: ้้ขๆฌๆดๆฐใๅจๆฅ็ๆใไป
ๅจ่ฟๅ
ฅ็ธๅ
ณๆจกๅๆถๆ็คบใ
|
||||
|
||||
---
|
||||
|
||||
## 3. ๆฐๆฎๅฎไฝๅ
ณ็ณปๆจๆผ (Data Entity Relationships)
|
||||
|
||||
ๅบไบ MySQL ๅ
ณ็ณปๅๆฐๆฎๅบ็่ฎพ่ฎกๆนๆกใ
|
||||
|
||||
### 3.1 ๆ ธๅฟๅฎไฝๆจกๅ (ER Draft)
|
||||
|
||||
1. **SysUser**: `id`, `username`, `role`, `school_id`
|
||||
2. **TeacherProfile**: `user_id`, `is_grade_head`, `is_subject_head`
|
||||
3. **Class**: `id`, `grade_level` (e.g., 10), `class_name` (e.g., "3็ญ"), `homeroom_teacher_id`
|
||||
4. **Subject**: `id`, `name` (e.g., "Math")
|
||||
5. **Course**: `id`, `class_id`, `subject_id`, `teacher_id` (ๆ ธๅฟๆๅญฆๅ
ณ็ณป่กจ: ่ฐๆๅชไธช็ญ็ๅช้จ่ฏพ)
|
||||
|
||||
### 3.2 ้ขๅบไธ็ฅ่ฏ็น่ฎพ่ฎก (ๅ
ณ้ฎ้พ็น)
|
||||
|
||||
#### Table: `knowledge_points` (็ฅ่ฏ็นๆ )
|
||||
* `id`: UUID
|
||||
* `subject_id`: FK
|
||||
* `name`: VARCHAR
|
||||
* `parent_id`: UUID (Self-reference, Root is NULL)
|
||||
* `level`: INT (1, 2, 3...)
|
||||
* `code`: VARCHAR (e.g., "M-ALG-01-02" ็จไบๅฟซ้ๆฃ็ดข)
|
||||
|
||||
#### Table: `questions` (ๆฏๆๅตๅฅ)
|
||||
* `id`: UUID
|
||||
* `content`: TEXT (HTML/Markdown, store images as URLs)
|
||||
* `type`: ENUM ('SINGLE', 'MULTI', 'FILL', 'ESSAY', 'COMPOSITE')
|
||||
* `parent_id`: UUID (Self-reference, **ๆ ธๅฟ่ฎพ่ฎก**)
|
||||
* If `NULL`: ่ฟๆฏไธ้็ฌ็ซ้ข็ฎ OR ๅคๅ้ข็ๅคง้ขๅนฒใ
|
||||
* If `NOT NULL`: ่ฟๆฏไธไธชๅญ้ข็ฎ๏ผๅฑไบ `parent_id` ๅฏนๅบ็้ขๅนฒใ
|
||||
* `difficulty`: INT (1-5)
|
||||
* `answer`: TEXT (JSON structure for structured answers)
|
||||
* `analysis`: TEXT (่งฃๆ)
|
||||
* `created_by`: FK (Teacher)
|
||||
* `scope`: ENUM ('PUBLIC', 'PRIVATE')
|
||||
|
||||
#### Table: `question_knowledge` (้ข็ฎ-็ฅ่ฏ็นๅ
ณ่)
|
||||
* `question_id`: FK
|
||||
* `knowledge_point_id`: FK
|
||||
* **Primary Key**: (`question_id`, `knowledge_point_id`)
|
||||
|
||||
### 3.3 ่ฏพๆฌๆ ๅฐ่ฎพ่ฎก
|
||||
|
||||
#### Table: `textbooks`
|
||||
* `id`: UUID
|
||||
* `name`: VARCHAR
|
||||
* `grade_level`: INT
|
||||
* `subject_id`: FK
|
||||
|
||||
#### Table: `textbook_chapters`
|
||||
* `id`: UUID
|
||||
* `textbook_id`: FK
|
||||
* `name`: VARCHAR
|
||||
* `parent_id`: UUID (Sections within Chapters)
|
||||
* `content`: TEXT (Rich text content of the chapter/section) -- [ADDED for Content Viewing]
|
||||
* `order`: INT
|
||||
|
||||
#### Table: `chapter_knowledge_mapping`
|
||||
* `chapter_id`: FK
|
||||
* `knowledge_point_id`: FK
|
||||
* *่งฃ้*: ่ฟๅผ ่กจๆฏ่ฟๆฅโๆๅญฆ่ฟๅบฆโไธโๅบๅฑ็ฅ่ฏโ็ๆกฅๆขใ
|
||||
|
||||
---
|
||||
|
||||
## 4. ๅ
ณ้ฎไธๅกๆต็จ (User Flows)
|
||||
|
||||
### 4.1 ๆบ่ฝ็ปๅทไธๅๅธๆต็จ (Exam Creation Flow)
|
||||
|
||||
่ฟๆฏไธไธช้ซ้ขไธๅคๆ็่ทฏๅพ๏ผ้่ฆๆ้ซ็ๆต็
ๅบฆใ
|
||||
|
||||
1. **ๅฏๅจ็ปๅท**:
|
||||
* ่ๅธ่ฟๅ
ฅ [ๆๅญฆๅทฅไฝๅฐ] -> ็นๅป [ๆฐๅปบ่ฏๅท/ไฝไธ]ใ
|
||||
* ่พๅ
ฅๅบๆฌไฟกๆฏ๏ผๅ็งฐใ่่ฏๆถ้ฟใๆปๅ๏ผใ
|
||||
|
||||
2. **่ฎพๅฎ่ๅด (้ๅฎ่ฏพๆฌ)**:
|
||||
* ่ๅธ้ๆฉๆๆ็ๆฌ๏ผ`ไบบๆ็้ซไธญๆฐๅญฆๅฟ
ไฟฎไธ`ใ
|
||||
* ้ๆฉ็ซ ่๏ผๅพ้ `็ฌฌไธ็ซ ้ๅ` ๅ `็ฌฌไบ็ซ ๅฝๆฐๆฆๅฟต`ใ
|
||||
* *็ณป็ปๅจไฝ*: ๅๅฐๆฅ่ฏข `chapter_knowledge_mapping`๏ผๆๅๅบ่ฟๅ ็ซ ๅฏนๅบ็ๆๆ `knowledge_points`ใ
|
||||
|
||||
3. **็ญ้้ข็ฎ**:
|
||||
* ็ณป็ปๅฑ็คบ้ข็ฎๅ่กจ๏ผ้ป่ฎค่ฟๆปคๆกไปถไธบไธ่ฟฐๆๅ็็ฅ่ฏ็นใ
|
||||
* ่ๅธๅขๅ ็ญ้๏ผ`้พๅบฆ: ไธญ็ญ`, `้ขๅ: ้ๆฉ้ข`ใ
|
||||
* **ๅค็ๅตๅฅ้ข**: ๅฆๆ็ญ้็ปๆๅ
ๅซไธไธชโๅฎๅฝขๅกซ็ฉบโ็ๅญ้ข๏ผ็ณป็ปๅจ UI ไธๅฟ
้กป**ๅผบๅถๅฑ็คบ**ๅ
ถๅฏนๅบ็็ถ้ขๅนฒ๏ผๅนถๆ็คบ่ๅธโ้ๆดไฝๆทปๅ โใ
|
||||
|
||||
4. **ๅ ๅ
ฅ่ฏ้ข็ฏฎ (Cart)**:
|
||||
* ่ๅธ็นๅปโ+โๅทใ
|
||||
* ่ฏ้ข็ฏฎๅจๆๆดๆฐ๏ผ`ๅฝๅ้ข็ฎๆฐ: 15, ้ข่ฎกๆปๅ: 85`ใ
|
||||
|
||||
5. **่ฏๅท็ฒพไฟฎ (Refine)**:
|
||||
* ่ฟๅ
ฅโ่ฏๅท้ข่งโๆจกๅผใ
|
||||
* ่ฐๆด้ข็ฎ้กบๅบ (Drag & drop)ใ
|
||||
* ไฟฎๆนๆ้้ข็ๅๅผ๏ผ่ฆ็้ป่ฎคๅๅผ๏ผใ
|
||||
|
||||
6. **ๅๅธ่ฎพ็ฝฎ**:
|
||||
* ้ๆฉๅๅธๅฏน่ฑก๏ผ`้ซไธ(3)็ญ`, `้ซไธ(5)็ญ` (ๅบไบ `Course` ่กจๆ้)ใ
|
||||
* ่ฎพ็ฝฎๆถ้ด๏ผ`ๅผๅงๆถ้ด`, `ๆชๆญขๆถ้ด`ใ
|
||||
* ๅๅธๆจกๅผ๏ผ`ๅจ็บฟไฝ็ญ` ๆ `็บฟไธ็ญ้ขๅก` (่ฅ็บฟไธ๏ผ็ณป็ป็ๆ PDF ๅ็ญ้ขๅกๆ ทๅผ)ใ
|
||||
|
||||
7. **ๅฎๆ**:
|
||||
* ๅญฆ็็ซฏๆถๅฐ `Notifications` ๆจ้ใ
|
||||
* `Exams` ่กจ็ๆ่ฎฐๅฝ๏ผ`ExamAllocations` ่กจไธบๆฏไธช็ญ็บง/ๅญฆ็็ๆ็ถๆ่ฎฐๅฝใ
|
||||
35
docs/scripts/reset-db.ts
Normal file
35
docs/scripts/reset-db.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import "dotenv/config"
|
||||
import { db } from "@/shared/db"
|
||||
import { sql } from "drizzle-orm"
|
||||
|
||||
async function reset() {
|
||||
console.log("๐ฅ Resetting database...")
|
||||
|
||||
// Disable foreign key checks
|
||||
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 0;`)
|
||||
|
||||
// Get all table names
|
||||
const tables = await db.execute(sql`
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE();
|
||||
`)
|
||||
|
||||
// Drop each table
|
||||
for (const row of (tables[0] as unknown as any[])) {
|
||||
const tableName = row.TABLE_NAME || row.table_name
|
||||
console.log(`Dropping table: ${tableName}`)
|
||||
await db.execute(sql.raw(`DROP TABLE IF EXISTS \`${tableName}\`;`))
|
||||
}
|
||||
|
||||
// Re-enable foreign key checks
|
||||
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 1;`)
|
||||
|
||||
console.log("โ
Database reset complete.")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
reset().catch((err) => {
|
||||
console.error("โ Reset failed:", err)
|
||||
process.exit(1)
|
||||
})
|
||||
346
docs/scripts/seed-exams.ts
Normal file
346
docs/scripts/seed-exams.ts
Normal file
@@ -0,0 +1,346 @@
|
||||
import "dotenv/config"
|
||||
import { db } from "@/shared/db"
|
||||
import { users, exams, questions, knowledgePoints, examSubmissions, examQuestions, submissionAnswers } from "@/shared/db/schema"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
import { faker } from "@faker-js/faker"
|
||||
import { eq } from "drizzle-orm"
|
||||
|
||||
/**
|
||||
* Seed Script for Next_Edu
|
||||
*
|
||||
* Usage:
|
||||
* 1. Ensure DATABASE_URL is set in .env
|
||||
* 2. Run with tsx: npx tsx docs/scripts/seed-exams.ts
|
||||
*/
|
||||
|
||||
const SUBJECTS = ["Mathematics", "Physics", "English", "Chemistry", "Biology"]
|
||||
const GRADES = ["Grade 10", "Grade 11", "Grade 12"]
|
||||
const DIFFICULTY = [1, 2, 3, 4, 5]
|
||||
|
||||
async function seed() {
|
||||
console.log("๐ฑ Starting seed process...")
|
||||
|
||||
// 1. Create a Teacher User if not exists
|
||||
const teacherEmail = "teacher@example.com"
|
||||
let teacherId = "user_teacher_123"
|
||||
|
||||
const existingTeacher = await db.query.users.findFirst({
|
||||
where: eq(users.email, teacherEmail)
|
||||
})
|
||||
|
||||
if (!existingTeacher) {
|
||||
console.log("Creating teacher user...")
|
||||
await db.insert(users).values({
|
||||
id: teacherId,
|
||||
name: "Senior Teacher",
|
||||
email: teacherEmail,
|
||||
role: "teacher",
|
||||
image: "https://api.dicebear.com/7.x/avataaars/svg?seed=Teacher",
|
||||
})
|
||||
} else {
|
||||
teacherId = existingTeacher.id
|
||||
console.log("Teacher user exists:", teacherId)
|
||||
}
|
||||
|
||||
// 1b. Create Students
|
||||
console.log("Creating students...")
|
||||
const studentIds: string[] = []
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const sId = createId()
|
||||
studentIds.push(sId)
|
||||
await db.insert(users).values({
|
||||
id: sId,
|
||||
name: faker.person.fullName(),
|
||||
email: faker.internet.email(),
|
||||
role: "student",
|
||||
image: `https://api.dicebear.com/7.x/avataaars/svg?seed=${sId}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 2. Create Knowledge Points
|
||||
console.log("Creating knowledge points...")
|
||||
const kpIds: string[] = []
|
||||
for (const subject of SUBJECTS) {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const kpId = createId()
|
||||
kpIds.push(kpId)
|
||||
await db.insert(knowledgePoints).values({
|
||||
id: kpId,
|
||||
name: `${subject} - ${faker.science.unit()}`,
|
||||
description: faker.lorem.sentence(),
|
||||
level: 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Create Questions
|
||||
console.log("Creating questions...")
|
||||
const questionIds: string[] = []
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const qId = createId()
|
||||
questionIds.push(qId)
|
||||
|
||||
const type = faker.helpers.arrayElement(["single_choice", "multiple_choice", "text", "judgment"])
|
||||
|
||||
await db.insert(questions).values({
|
||||
id: qId,
|
||||
content: {
|
||||
text: faker.lorem.paragraph(),
|
||||
options: type.includes("choice") ? [
|
||||
{ id: "A", text: faker.lorem.sentence(), isCorrect: true },
|
||||
{ id: "B", text: faker.lorem.sentence(), isCorrect: false },
|
||||
{ id: "C", text: faker.lorem.sentence(), isCorrect: false },
|
||||
{ id: "D", text: faker.lorem.sentence(), isCorrect: false },
|
||||
] : undefined
|
||||
},
|
||||
type: type as any,
|
||||
difficulty: faker.helpers.arrayElement(DIFFICULTY),
|
||||
authorId: teacherId,
|
||||
})
|
||||
}
|
||||
|
||||
// 4. Create Exams & Submissions
|
||||
console.log("Creating exams and submissions...")
|
||||
for (let i = 0; i < 15; i++) {
|
||||
const examId = createId()
|
||||
const subject = faker.helpers.arrayElement(SUBJECTS)
|
||||
const grade = faker.helpers.arrayElement(GRADES)
|
||||
const status = faker.helpers.arrayElement(["draft", "published", "archived"])
|
||||
|
||||
const scheduledAt = faker.date.soon({ days: 30 })
|
||||
|
||||
const meta = {
|
||||
subject,
|
||||
grade,
|
||||
difficulty: faker.helpers.arrayElement(DIFFICULTY),
|
||||
totalScore: 100,
|
||||
durationMin: faker.helpers.arrayElement([45, 60, 90, 120]),
|
||||
questionCount: faker.number.int({ min: 10, max: 30 }),
|
||||
tags: [faker.word.sample(), faker.word.sample()],
|
||||
scheduledAt: scheduledAt.toISOString()
|
||||
}
|
||||
|
||||
await db.insert(exams).values({
|
||||
id: examId,
|
||||
title: `${subject} ${faker.helpers.arrayElement(["Midterm", "Final", "Quiz", "Unit Test"])}`,
|
||||
description: JSON.stringify(meta),
|
||||
creatorId: teacherId,
|
||||
startTime: scheduledAt,
|
||||
status: status as any,
|
||||
})
|
||||
|
||||
// Link some questions to this exam (random 5 questions)
|
||||
const selectedQuestions = faker.helpers.arrayElements(questionIds, 5)
|
||||
await db.insert(examQuestions).values(
|
||||
selectedQuestions.map((qId, idx) => ({
|
||||
examId,
|
||||
questionId: qId,
|
||||
score: 20, // 5 * 20 = 100
|
||||
order: idx
|
||||
}))
|
||||
)
|
||||
|
||||
// Create submissions for published exams
|
||||
if (status === "published") {
|
||||
const submittingStudents = faker.helpers.arrayElements(studentIds, faker.number.int({ min: 1, max: 3 }))
|
||||
for (const studentId of submittingStudents) {
|
||||
const submissionId = createId()
|
||||
const submissionStatus = faker.helpers.arrayElement(["submitted", "graded"])
|
||||
|
||||
await db.insert(examSubmissions).values({
|
||||
id: submissionId,
|
||||
examId,
|
||||
studentId,
|
||||
score: submissionStatus === "graded" ? faker.number.int({ min: 60, max: 100 }) : null,
|
||||
status: submissionStatus,
|
||||
submittedAt: faker.date.recent(),
|
||||
})
|
||||
|
||||
// Generate answers for this submission
|
||||
for (const qId of selectedQuestions) {
|
||||
await db.insert(submissionAnswers).values({
|
||||
id: createId(),
|
||||
submissionId: submissionId,
|
||||
questionId: qId,
|
||||
answerContent: { answer: faker.lorem.sentence() }, // Mock answer
|
||||
score: submissionStatus === "graded" ? faker.number.int({ min: 0, max: 20 }) : null,
|
||||
feedback: submissionStatus === "graded" ? faker.lorem.sentence() : null,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Create a specific Primary School Chinese Exam (ๅฐๅญฆ่ฏญๆ)
|
||||
console.log("Creating Primary School Chinese Exam...")
|
||||
const chineseExamId = createId()
|
||||
const chineseQuestions = []
|
||||
|
||||
// 5a. Pinyin Questions
|
||||
const pinyinQ1 = createId()
|
||||
const pinyinQ2 = createId()
|
||||
chineseQuestions.push({ id: pinyinQ1, score: 5 }, { id: pinyinQ2, score: 5 })
|
||||
|
||||
await db.insert(questions).values([
|
||||
{
|
||||
id: pinyinQ1,
|
||||
content: { text: "็ๆผ้ณๅ่ฏ่ฏญ๏ผchลซn tiฤn ( )" },
|
||||
type: "text",
|
||||
difficulty: 1,
|
||||
authorId: teacherId,
|
||||
},
|
||||
{
|
||||
id: pinyinQ2,
|
||||
content: { text: "็ๆผ้ณๅ่ฏ่ฏญ๏ผhuฤ duว ( )" },
|
||||
type: "text",
|
||||
difficulty: 1,
|
||||
authorId: teacherId,
|
||||
}
|
||||
])
|
||||
|
||||
// 5b. Vocabulary Questions
|
||||
const vocabQ1 = createId()
|
||||
const vocabQ2 = createId()
|
||||
chineseQuestions.push({ id: vocabQ1, score: 5 }, { id: vocabQ2, score: 5 })
|
||||
|
||||
await db.insert(questions).values([
|
||||
{
|
||||
id: vocabQ1,
|
||||
content: {
|
||||
text: "้่ฏๅกซ็ฉบ๏ผไปๅคฉๅคฉๆฐ็๏ผ ๏ผใ",
|
||||
options: [
|
||||
{ id: "A", text: "็พๅฅฝ", isCorrect: false },
|
||||
{ id: "B", text: "ๆดๆ", isCorrect: true },
|
||||
{ id: "C", text: "ๅฟซไน", isCorrect: false }
|
||||
]
|
||||
},
|
||||
type: "single_choice",
|
||||
difficulty: 2,
|
||||
authorId: teacherId,
|
||||
},
|
||||
{
|
||||
id: vocabQ2,
|
||||
content: {
|
||||
text: "ไธๅ่ฏ่ฏญไธญ๏ผไนฆๅๆญฃ็กฎ็ๆฏ๏ผ ๏ผใ",
|
||||
options: [
|
||||
{ id: "A", text: "ๆผๆฌ", isCorrect: false },
|
||||
{ id: "B", text: "้ฃๆฌ", isCorrect: true },
|
||||
{ id: "C", text: "็ฅจๆฌ", isCorrect: false }
|
||||
]
|
||||
},
|
||||
type: "single_choice",
|
||||
difficulty: 2,
|
||||
authorId: teacherId,
|
||||
}
|
||||
])
|
||||
|
||||
// 5c. Reading Comprehension Questions
|
||||
const readingQ1 = createId()
|
||||
const readingQ2 = createId()
|
||||
chineseQuestions.push({ id: readingQ1, score: 10 }, { id: readingQ2, score: 10 })
|
||||
|
||||
await db.insert(questions).values([
|
||||
{
|
||||
id: readingQ1,
|
||||
content: {
|
||||
text: "้
่ฏป็ญๆใๅฐๅ
ๅญไนไนใ๏ผๅ็ญ้ฎ้ข๏ผ\n\nๅฐๅ
ๅญไนไน๏ผๆ้จๅฟๅผๅผ...\n\nๆไธญๆๅฐ็ๅจ็ฉๆฏ๏ผ",
|
||||
options: [
|
||||
{ id: "A", text: "ๅคง็ฐ็ผ", isCorrect: false },
|
||||
{ id: "B", text: "ๅฐๅ
ๅญ", isCorrect: true },
|
||||
{ id: "C", text: "ๅฐ่ฑ็ซ", isCorrect: false }
|
||||
]
|
||||
},
|
||||
type: "single_choice",
|
||||
difficulty: 3,
|
||||
authorId: teacherId,
|
||||
},
|
||||
{
|
||||
id: readingQ2,
|
||||
content: { text: "่ฏท็จไธๅฅ่ฏๅฝขๅฎนๅฐๅ
ๅญใ" },
|
||||
type: "text",
|
||||
difficulty: 3,
|
||||
authorId: teacherId,
|
||||
}
|
||||
])
|
||||
|
||||
// 5d. Construct Exam Structure
|
||||
const chineseExamStructure = [
|
||||
{
|
||||
id: createId(),
|
||||
type: "group",
|
||||
title: "็ฌฌไธ้จๅ๏ผๅบ็ก็ฅ่ฏ",
|
||||
children: [
|
||||
{
|
||||
id: createId(),
|
||||
type: "group",
|
||||
title: "ไธใ็ๆผ้ณๅ่ฏ่ฏญ",
|
||||
children: [
|
||||
{ id: createId(), type: "question", questionId: pinyinQ1, score: 5 },
|
||||
{ id: createId(), type: "question", questionId: pinyinQ2, score: 5 }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: "group",
|
||||
title: "ไบใ่ฏ่ฏญ็งฏ็ดฏ",
|
||||
children: [
|
||||
{ id: createId(), type: "question", questionId: vocabQ1, score: 5 },
|
||||
{ id: createId(), type: "question", questionId: vocabQ2, score: 5 }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: "group",
|
||||
title: "็ฌฌไบ้จๅ๏ผ้
่ฏป็่งฃ",
|
||||
children: [
|
||||
{
|
||||
id: createId(),
|
||||
type: "group",
|
||||
title: "ไธใ็ญๆ้
่ฏป",
|
||||
children: [
|
||||
{ id: createId(), type: "question", questionId: readingQ1, score: 10 },
|
||||
{ id: createId(), type: "question", questionId: readingQ2, score: 10 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
await db.insert(exams).values({
|
||||
id: chineseExamId,
|
||||
title: "ๅฐๅญฆ่ฏญๆไธๅนด็บงไธๅๆๆซ่่ฏ",
|
||||
description: JSON.stringify({
|
||||
subject: "Chinese",
|
||||
grade: "Grade 3",
|
||||
difficulty: 3,
|
||||
totalScore: 40,
|
||||
durationMin: 90,
|
||||
questionCount: 6,
|
||||
tags: ["ๆๆซ", "่ฏญๆ", "ไธๅนด็บง"]
|
||||
}),
|
||||
structure: chineseExamStructure,
|
||||
creatorId: teacherId,
|
||||
status: "published",
|
||||
startTime: new Date(),
|
||||
})
|
||||
|
||||
// Link questions to exam
|
||||
await db.insert(examQuestions).values(
|
||||
chineseQuestions.map((q, idx) => ({
|
||||
examId: chineseExamId,
|
||||
questionId: q.id,
|
||||
score: q.score,
|
||||
order: idx
|
||||
}))
|
||||
)
|
||||
|
||||
console.log("โ
Seed completed successfully!")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
seed().catch((err) => {
|
||||
console.error("โ Seed failed:", err)
|
||||
process.exit(1)
|
||||
})
|
||||
10
drizzle.config.ts
Normal file
10
drizzle.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { defineConfig } from "drizzle-kit";
|
||||
|
||||
export default defineConfig({
|
||||
schema: "./src/shared/db/schema.ts",
|
||||
out: "./drizzle",
|
||||
dialect: "mysql",
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL!,
|
||||
},
|
||||
});
|
||||
183
drizzle/0000_aberrant_cobalt_man.sql
Normal file
183
drizzle/0000_aberrant_cobalt_man.sql
Normal file
@@ -0,0 +1,183 @@
|
||||
CREATE TABLE `accounts` (
|
||||
`userId` varchar(128) NOT NULL,
|
||||
`type` varchar(255) NOT NULL,
|
||||
`provider` varchar(255) NOT NULL,
|
||||
`providerAccountId` varchar(255) NOT NULL,
|
||||
`refresh_token` text,
|
||||
`access_token` text,
|
||||
`expires_at` int,
|
||||
`token_type` varchar(255),
|
||||
`scope` varchar(255),
|
||||
`id_token` text,
|
||||
`session_state` varchar(255),
|
||||
CONSTRAINT `accounts_provider_providerAccountId_pk` PRIMARY KEY(`provider`,`providerAccountId`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `chapters` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`textbook_id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`order` int DEFAULT 0,
|
||||
`parent_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `chapters_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exam_questions` (
|
||||
`exam_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`score` int DEFAULT 0,
|
||||
`order` int DEFAULT 0,
|
||||
CONSTRAINT `exam_questions_exam_id_question_id_pk` PRIMARY KEY(`exam_id`,`question_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exam_submissions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`exam_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`score` int,
|
||||
`status` varchar(50) DEFAULT 'started',
|
||||
`submitted_at` timestamp,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `exam_submissions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exams` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`creator_id` varchar(128) NOT NULL,
|
||||
`start_time` timestamp,
|
||||
`end_time` timestamp,
|
||||
`status` varchar(50) DEFAULT 'draft',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `exams_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `knowledge_points` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`parent_id` varchar(128),
|
||||
`level` int DEFAULT 0,
|
||||
`order` int DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `knowledge_points_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `questions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`content` json NOT NULL,
|
||||
`type` enum('single_choice','multiple_choice','text','judgment','composite') NOT NULL,
|
||||
`difficulty` int DEFAULT 1,
|
||||
`parent_id` varchar(128),
|
||||
`author_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `questions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `questions_to_knowledge_points` (
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`knowledge_point_id` varchar(128) NOT NULL,
|
||||
CONSTRAINT `questions_to_knowledge_points_question_id_knowledge_point_id_pk` PRIMARY KEY(`question_id`,`knowledge_point_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `roles` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`description` varchar(255),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `roles_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `roles_name_unique` UNIQUE(`name`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `sessions` (
|
||||
`sessionToken` varchar(255) NOT NULL,
|
||||
`userId` varchar(128) NOT NULL,
|
||||
`expires` timestamp NOT NULL,
|
||||
CONSTRAINT `sessions_sessionToken` PRIMARY KEY(`sessionToken`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `submission_answers` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`submission_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`answer_content` json,
|
||||
`score` int,
|
||||
`feedback` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `submission_answers_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `textbooks` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`subject` varchar(100) NOT NULL,
|
||||
`grade` varchar(50),
|
||||
`publisher` varchar(100),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `textbooks_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `users` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255),
|
||||
`email` varchar(255) NOT NULL,
|
||||
`emailVerified` timestamp,
|
||||
`image` varchar(255),
|
||||
`role` varchar(50) DEFAULT 'student',
|
||||
`password` varchar(255),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `users_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `users_email_unique` UNIQUE(`email`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `users_to_roles` (
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`role_id` varchar(128) NOT NULL,
|
||||
CONSTRAINT `users_to_roles_user_id_role_id_pk` PRIMARY KEY(`user_id`,`role_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `verificationTokens` (
|
||||
`identifier` varchar(255) NOT NULL,
|
||||
`token` varchar(255) NOT NULL,
|
||||
`expires` timestamp NOT NULL,
|
||||
CONSTRAINT `verificationTokens_identifier_token_pk` PRIMARY KEY(`identifier`,`token`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `chapters` ADD CONSTRAINT `chapters_textbook_id_textbooks_id_fk` FOREIGN KEY (`textbook_id`) REFERENCES `textbooks`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD CONSTRAINT `exams_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions` ADD CONSTRAINT `questions_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `questions_to_knowledge_points_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_submission_id_exam_submissions_id_fk` FOREIGN KEY (`submission_id`) REFERENCES `exam_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `account_userId_idx` ON `accounts` (`userId`);--> statement-breakpoint
|
||||
CREATE INDEX `textbook_idx` ON `chapters` (`textbook_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `chapters` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `exam_student_idx` ON `exam_submissions` (`exam_id`,`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `knowledge_points` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `questions` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `author_id_idx` ON `questions` (`author_id`);--> statement-breakpoint
|
||||
CREATE INDEX `kp_idx` ON `questions_to_knowledge_points` (`knowledge_point_id`);--> statement-breakpoint
|
||||
CREATE INDEX `session_userId_idx` ON `sessions` (`userId`);--> statement-breakpoint
|
||||
CREATE INDEX `submission_idx` ON `submission_answers` (`submission_id`);--> statement-breakpoint
|
||||
CREATE INDEX `email_idx` ON `users` (`email`);--> statement-breakpoint
|
||||
CREATE INDEX `user_id_idx` ON `users_to_roles` (`user_id`);
|
||||
5
drizzle/0001_flawless_texas_twister.sql
Normal file
5
drizzle/0001_flawless_texas_twister.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE `exams` ADD `structure` json;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` DROP FOREIGN KEY `questions_to_knowledge_points_question_id_questions_id_fk`;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` DROP FOREIGN KEY `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk`;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_qid_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_kpid_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;
|
||||
1286
drizzle/meta/0000_snapshot.json
Normal file
1286
drizzle/meta/0000_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1293
drizzle/meta/0001_snapshot.json
Normal file
1293
drizzle/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
20
drizzle/meta/_journal.json
Normal file
20
drizzle/meta/_journal.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "mysql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1766460456274,
|
||||
"tag": "0000_aberrant_cobalt_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1767004087964,
|
||||
"tag": "0001_flawless_texas_twister",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
3924
package-lock.json
generated
3924
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
44
package.json
44
package.json
@@ -7,20 +7,60 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint",
|
||||
"typecheck": "tsc --noEmit"
|
||||
"typecheck": "tsc --noEmit",
|
||||
"db:seed": "npx tsx scripts/seed.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
"@dnd-kit/sortable": "^10.0.0",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
"@hookform/resolvers": "^5.2.2",
|
||||
"@paralleldrive/cuid2": "^3.0.4",
|
||||
"@radix-ui/react-alert-dialog": "^1.1.15",
|
||||
"@radix-ui/react-avatar": "^1.1.11",
|
||||
"@radix-ui/react-checkbox": "^1.3.3",
|
||||
"@radix-ui/react-collapsible": "^1.1.12",
|
||||
"@radix-ui/react-dialog": "^1.1.15",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||
"@radix-ui/react-scroll-area": "^1.2.10",
|
||||
"@radix-ui/react-select": "^2.2.6",
|
||||
"@radix-ui/react-separator": "^1.1.8",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"@t3-oss/env-nextjs": "^0.13.10",
|
||||
"@tanstack/react-query": "^5.90.12",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"lucide-react": "^0.562.0",
|
||||
"mysql2": "^3.16.0",
|
||||
"next": "16.0.10",
|
||||
"next-auth": "^5.0.0-beta.30",
|
||||
"next-themes": "^0.4.6",
|
||||
"nuqs": "^2.8.5",
|
||||
"react": "19.2.1",
|
||||
"react-dom": "19.2.1"
|
||||
"react-dom": "19.2.1",
|
||||
"react-hook-form": "^7.69.0",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"zod": "^4.2.1",
|
||||
"zustand": "^5.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^10.1.0",
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"dotenv": "^17.2.3",
|
||||
"drizzle-kit": "^0.31.8",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.0.10",
|
||||
"prettier": "^3.7.4",
|
||||
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
|
||||
236
scripts/seed.ts
Normal file
236
scripts/seed.ts
Normal file
@@ -0,0 +1,236 @@
|
||||
import "dotenv/config";
|
||||
import { db } from "../src/shared/db";
|
||||
import {
|
||||
users, roles, usersToRoles,
|
||||
questions, knowledgePoints, questionsToKnowledgePoints,
|
||||
exams, examQuestions, examSubmissions, submissionAnswers,
|
||||
textbooks, chapters
|
||||
} from "../src/shared/db/schema";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
/**
|
||||
* Enterprise-Grade Seed Script for Next_Edu
|
||||
*
|
||||
* Scenarios Covered:
|
||||
* 1. IAM: RBAC with multiple roles (Teacher & Grade Head).
|
||||
* 2. Knowledge Graph: Nested Knowledge Points (Math -> Algebra -> Linear Equations).
|
||||
* 3. Question Bank: Rich Text Content & Nested Questions (Reading Comprehension).
|
||||
* 4. Exams: JSON Structure for Sectioning.
|
||||
*/
|
||||
|
||||
async function seed() {
|
||||
console.log("๐ฑ Starting Database Seed...");
|
||||
const start = performance.now();
|
||||
|
||||
// --- 0. Cleanup (Optional: Truncate tables for fresh start) ---
|
||||
// Note: Order matters due to foreign keys if checks are enabled.
|
||||
// Ideally, use: SET FOREIGN_KEY_CHECKS = 0;
|
||||
try {
|
||||
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 0;`);
|
||||
const tables = [
|
||||
"submission_answers", "exam_submissions", "exam_questions", "exams",
|
||||
"questions_to_knowledge_points", "questions", "knowledge_points",
|
||||
"chapters", "textbooks",
|
||||
"users_to_roles", "roles", "users", "accounts", "sessions"
|
||||
];
|
||||
for (const table of tables) {
|
||||
await db.execute(sql.raw(`TRUNCATE TABLE \`${table}\`;`));
|
||||
}
|
||||
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 1;`);
|
||||
console.log("๐งน Cleaned up existing data.");
|
||||
} catch (e) {
|
||||
console.warn("โ ๏ธ Cleanup warning (might be fresh DB):", e);
|
||||
}
|
||||
|
||||
// --- 1. IAM & Roles ---
|
||||
console.log("๐ค Seeding IAM...");
|
||||
|
||||
// Roles
|
||||
const roleMap = {
|
||||
admin: "role_admin",
|
||||
teacher: "role_teacher",
|
||||
student: "role_student",
|
||||
grade_head: "role_grade_head"
|
||||
};
|
||||
|
||||
await db.insert(roles).values([
|
||||
{ id: roleMap.admin, name: "admin", description: "System Administrator" },
|
||||
{ id: roleMap.teacher, name: "teacher", description: "Academic Instructor" },
|
||||
{ id: roleMap.student, name: "student", description: "Learner" },
|
||||
{ id: roleMap.grade_head, name: "grade_head", description: "Head of Grade Year" }
|
||||
]);
|
||||
|
||||
// Users
|
||||
const usersData = [
|
||||
{
|
||||
id: "user_admin",
|
||||
name: "Admin User",
|
||||
email: "admin@next-edu.com",
|
||||
role: "admin", // Legacy field
|
||||
image: "https://api.dicebear.com/7.x/avataaars/svg?seed=Admin"
|
||||
},
|
||||
{
|
||||
id: "user_teacher_math",
|
||||
name: "Mr. Math",
|
||||
email: "math@next-edu.com",
|
||||
role: "teacher",
|
||||
image: "https://api.dicebear.com/7.x/avataaars/svg?seed=Math"
|
||||
},
|
||||
{
|
||||
id: "user_student_1",
|
||||
name: "Alice Student",
|
||||
email: "alice@next-edu.com",
|
||||
role: "student",
|
||||
image: "https://api.dicebear.com/7.x/avataaars/svg?seed=Alice"
|
||||
}
|
||||
];
|
||||
|
||||
await db.insert(users).values(usersData);
|
||||
|
||||
// Assign Roles (RBAC)
|
||||
await db.insert(usersToRoles).values([
|
||||
{ userId: "user_admin", roleId: roleMap.admin },
|
||||
{ userId: "user_teacher_math", roleId: roleMap.teacher },
|
||||
// Math teacher is also a Grade Head
|
||||
{ userId: "user_teacher_math", roleId: roleMap.grade_head },
|
||||
{ userId: "user_student_1", roleId: roleMap.student },
|
||||
]);
|
||||
|
||||
// --- 2. Knowledge Graph (Tree) ---
|
||||
console.log("๐ง Seeding Knowledge Graph...");
|
||||
|
||||
const kpMathId = createId();
|
||||
const kpAlgebraId = createId();
|
||||
const kpLinearId = createId();
|
||||
|
||||
await db.insert(knowledgePoints).values([
|
||||
{ id: kpMathId, name: "Mathematics", level: 0 },
|
||||
{ id: kpAlgebraId, name: "Algebra", parentId: kpMathId, level: 1 },
|
||||
{ id: kpLinearId, name: "Linear Equations", parentId: kpAlgebraId, level: 2 },
|
||||
]);
|
||||
|
||||
// --- 3. Question Bank (Rich Content) ---
|
||||
console.log("๐ Seeding Question Bank...");
|
||||
|
||||
// 3.1 Simple Single Choice
|
||||
const qSimpleId = createId();
|
||||
await db.insert(questions).values({
|
||||
id: qSimpleId,
|
||||
authorId: "user_teacher_math",
|
||||
type: "single_choice",
|
||||
difficulty: 1,
|
||||
content: {
|
||||
text: "What is 2 + 2?",
|
||||
options: [
|
||||
{ id: "A", text: "3", isCorrect: false },
|
||||
{ id: "B", text: "4", isCorrect: true },
|
||||
{ id: "C", text: "5", isCorrect: false }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
// Link to KP
|
||||
await db.insert(questionsToKnowledgePoints).values({
|
||||
questionId: qSimpleId,
|
||||
knowledgePointId: kpLinearId // Just for demo
|
||||
});
|
||||
|
||||
// 3.2 Composite Question (Reading Comprehension)
|
||||
const qParentId = createId();
|
||||
const qChild1Id = createId();
|
||||
const qChild2Id = createId();
|
||||
|
||||
// Parent (Passage)
|
||||
await db.insert(questions).values({
|
||||
id: qParentId,
|
||||
authorId: "user_teacher_math",
|
||||
type: "composite",
|
||||
difficulty: 3,
|
||||
content: {
|
||||
text: "Read the following passage about Algebra...\n(Long text here)...",
|
||||
assets: []
|
||||
}
|
||||
});
|
||||
|
||||
// Children
|
||||
await db.insert(questions).values([
|
||||
{
|
||||
id: qChild1Id,
|
||||
authorId: "user_teacher_math",
|
||||
parentId: qParentId, // <--- Key: Nested
|
||||
type: "single_choice",
|
||||
difficulty: 2,
|
||||
content: {
|
||||
text: "What is the main topic?",
|
||||
options: [
|
||||
{ id: "A", text: "Geometry", isCorrect: false },
|
||||
{ id: "B", text: "Algebra", isCorrect: true }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id: qChild2Id,
|
||||
authorId: "user_teacher_math",
|
||||
parentId: qParentId,
|
||||
type: "text",
|
||||
difficulty: 4,
|
||||
content: {
|
||||
text: "Explain the concept of variables.",
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
// --- 4. Exams (New Structure) ---
|
||||
console.log("๐ Seeding Exams...");
|
||||
|
||||
const examId = createId();
|
||||
const examStructure = [
|
||||
{
|
||||
type: "group",
|
||||
title: "Part 1: Basics",
|
||||
children: [
|
||||
{ type: "question", questionId: qSimpleId, score: 10 }
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "group",
|
||||
title: "Part 2: Reading",
|
||||
children: [
|
||||
// For composite questions, we usually add the parent, and the system fetches children
|
||||
{ type: "question", questionId: qParentId, score: 20 }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
await db.insert(exams).values({
|
||||
id: examId,
|
||||
title: "Algebra Mid-Term 2025",
|
||||
description: "Comprehensive assessment",
|
||||
creatorId: "user_teacher_math",
|
||||
status: "published",
|
||||
startTime: new Date(),
|
||||
structure: examStructure as any // Bypass strict typing for seed
|
||||
});
|
||||
|
||||
// Link questions physically (Source of Truth)
|
||||
await db.insert(examQuestions).values([
|
||||
{ examId, questionId: qSimpleId, score: 10, order: 0 },
|
||||
{ examId, questionId: qParentId, score: 20, order: 1 },
|
||||
// Note: Child questions are often implicitly included or explicitly added depending on logic.
|
||||
// For this seed, we assume linking Parent is enough for the relation,
|
||||
// but let's link children too for completeness if the query strategy requires it.
|
||||
{ examId, questionId: qChild1Id, score: 0, order: 2 },
|
||||
{ examId, questionId: qChild2Id, score: 0, order: 3 },
|
||||
]);
|
||||
|
||||
const end = performance.now();
|
||||
console.log(`โ
Seed completed in ${(end - start).toFixed(2)}ms`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
seed().catch((err) => {
|
||||
console.error("โ Seed failed:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
34
src/app/(auth)/error.tsx
Normal file
34
src/app/(auth)/error.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect } from "react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
export default function AuthError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.error(error)
|
||||
}, [error])
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center gap-4 p-4 text-center">
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-destructive/10">
|
||||
<AlertCircle className="h-8 w-8 text-destructive" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<h2 className="text-xl font-bold tracking-tight">Authentication Error</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
There was a problem signing you in. Please try again.
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => reset()} variant="default" size="sm">
|
||||
Try again
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
src/app/(auth)/layout.tsx
Normal file
5
src/app/(auth)/layout.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { AuthLayout } from "@/modules/auth/components/auth-layout"
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
return <AuthLayout>{children}</AuthLayout>
|
||||
}
|
||||
11
src/app/(auth)/login/page.tsx
Normal file
11
src/app/(auth)/login/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Metadata } from "next"
|
||||
import { LoginForm } from "@/modules/auth/components/login-form"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Login - Next_Edu",
|
||||
description: "Login to your account",
|
||||
}
|
||||
|
||||
export default function LoginPage() {
|
||||
return <LoginForm />
|
||||
}
|
||||
22
src/app/(auth)/not-found.tsx
Normal file
22
src/app/(auth)/not-found.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import Link from "next/link"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { FileQuestion } from "lucide-react"
|
||||
|
||||
export default function AuthNotFound() {
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center gap-4 p-4 text-center">
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-muted">
|
||||
<FileQuestion className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<h2 className="text-xl font-bold tracking-tight">Page Not Found</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
The authentication page you are looking for does not exist.
|
||||
</p>
|
||||
</div>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href="/login">Return to Login</Link>
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
11
src/app/(auth)/register/page.tsx
Normal file
11
src/app/(auth)/register/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Metadata } from "next"
|
||||
import { RegisterForm } from "@/modules/auth/components/register-form"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Register - Next_Edu",
|
||||
description: "Create an account",
|
||||
}
|
||||
|
||||
export default function RegisterPage() {
|
||||
return <RegisterForm />
|
||||
}
|
||||
5
src/app/(dashboard)/admin/dashboard/page.tsx
Normal file
5
src/app/(dashboard)/admin/dashboard/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { AdminDashboard } from "@/modules/dashboard/components/admin-view"
|
||||
|
||||
export default function AdminDashboardPage() {
|
||||
return <AdminDashboard />
|
||||
}
|
||||
72
src/app/(dashboard)/dashboard/page.tsx
Normal file
72
src/app/(dashboard)/dashboard/page.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import Link from "next/link"
|
||||
import { Shield, GraduationCap, Users, User } from "lucide-react"
|
||||
|
||||
// In a real app, this would be a server component that redirects based on session
|
||||
// But for this demo/dev environment, we keep the manual selection or add auto-redirect logic if we had auth state.
|
||||
|
||||
export default function DashboardPage() {
|
||||
// Mock Auth Logic (Optional: Uncomment to test auto-redirect)
|
||||
/*
|
||||
const router = useRouter();
|
||||
useEffect(() => {
|
||||
// const role = "teacher"; // Fetch from auth hook
|
||||
// if (role) router.push(`/${role}/dashboard`);
|
||||
}, []);
|
||||
*/
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[50vh] space-y-8">
|
||||
<div className="text-center space-y-2">
|
||||
<h1 className="text-3xl font-bold">Welcome to Next_Edu</h1>
|
||||
<p className="text-muted-foreground">Select your role to view the corresponding dashboard.</p>
|
||||
<p className="text-xs text-muted-foreground bg-muted p-2 rounded inline-block">
|
||||
[DEV MODE] In production, you would be redirected automatically based on your login session.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
<Link href="/admin/dashboard">
|
||||
<Button variant="outline" className="h-40 w-40 flex flex-col gap-4 hover:border-primary hover:bg-primary/5 transition-all">
|
||||
<Shield className="h-10 w-10 text-primary" />
|
||||
<div className="space-y-1">
|
||||
<span className="font-semibold text-lg block">Admin</span>
|
||||
<span className="text-xs text-muted-foreground font-normal">System Management</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/teacher/dashboard">
|
||||
<Button variant="outline" className="h-40 w-40 flex flex-col gap-4 hover:border-indigo-500 hover:bg-indigo-50 transition-all">
|
||||
<GraduationCap className="h-10 w-10 text-indigo-600" />
|
||||
<div className="space-y-1">
|
||||
<span className="font-semibold text-lg block">Teacher</span>
|
||||
<span className="text-xs text-muted-foreground font-normal">Class & Exams</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/student/dashboard">
|
||||
<Button variant="outline" className="h-40 w-40 flex flex-col gap-4 hover:border-emerald-500 hover:bg-emerald-50 transition-all">
|
||||
<Users className="h-10 w-10 text-emerald-600" />
|
||||
<div className="space-y-1">
|
||||
<span className="font-semibold text-lg block">Student</span>
|
||||
<span className="text-xs text-muted-foreground font-normal">My Learning</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/parent/dashboard">
|
||||
<Button variant="outline" className="h-40 w-40 flex flex-col gap-4 hover:border-amber-500 hover:bg-amber-50 transition-all">
|
||||
<User className="h-10 w-10 text-amber-600" />
|
||||
<div className="space-y-1">
|
||||
<span className="font-semibold text-lg block">Parent</span>
|
||||
<span className="text-xs text-muted-foreground font-normal">Family Overview</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
35
src/app/(dashboard)/error.tsx
Normal file
35
src/app/(dashboard)/error.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect } from "react"
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function Error({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}) {
|
||||
useEffect(() => {
|
||||
// Log the error to an error reporting service
|
||||
console.error(error)
|
||||
}, [error])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="Something went wrong!"
|
||||
description="We apologize for the inconvenience. An unexpected error occurred."
|
||||
action={{
|
||||
label: "Try Again",
|
||||
onClick: () => reset()
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
18
src/app/(dashboard)/layout.tsx
Normal file
18
src/app/(dashboard)/layout.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { AppSidebar } from "@/modules/layout/components/app-sidebar"
|
||||
import { SidebarProvider } from "@/modules/layout/components/sidebar-provider"
|
||||
import { SiteHeader } from "@/modules/layout/components/site-header"
|
||||
|
||||
export default function DashboardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SidebarProvider sidebar={<AppSidebar />}>
|
||||
<SiteHeader />
|
||||
<main className="flex-1 overflow-auto p-6">
|
||||
{children}
|
||||
</main>
|
||||
</SidebarProvider>
|
||||
)
|
||||
}
|
||||
23
src/app/(dashboard)/not-found.tsx
Normal file
23
src/app/(dashboard)/not-found.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import Link from "next/link"
|
||||
import { FileQuestion } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4">
|
||||
<EmptyState
|
||||
icon={FileQuestion}
|
||||
title="Page Not Found"
|
||||
description="The page you are looking for does not exist or has been moved."
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90 inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium transition-colors"
|
||||
>
|
||||
Return to Dashboard
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
8
src/app/(dashboard)/parent/dashboard/page.tsx
Normal file
8
src/app/(dashboard)/parent/dashboard/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function ParentDashboardPage() {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold">Parent Dashboard</h1>
|
||||
<p className="text-muted-foreground">Welcome, Parent!</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
src/app/(dashboard)/student/dashboard/page.tsx
Normal file
5
src/app/(dashboard)/student/dashboard/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { StudentDashboard } from "@/modules/dashboard/components/student-view"
|
||||
|
||||
export default function StudentDashboardPage() {
|
||||
return <StudentDashboard />
|
||||
}
|
||||
22
src/app/(dashboard)/teacher/classes/my/page.tsx
Normal file
22
src/app/(dashboard)/teacher/classes/my/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Users } from "lucide-react"
|
||||
|
||||
export default function MyClassesPage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Classes</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Overview of your classes.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No classes found"
|
||||
description="You are not assigned to any classes yet."
|
||||
icon={Users}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
src/app/(dashboard)/teacher/classes/page.tsx
Normal file
5
src/app/(dashboard)/teacher/classes/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
export default function ClassesPage() {
|
||||
redirect("/teacher/classes/my")
|
||||
}
|
||||
22
src/app/(dashboard)/teacher/classes/schedule/page.tsx
Normal file
22
src/app/(dashboard)/teacher/classes/schedule/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Calendar } from "lucide-react"
|
||||
|
||||
export default function SchedulePage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Schedule</h2>
|
||||
<p className="text-muted-foreground">
|
||||
View class schedule.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No schedule available"
|
||||
description="Your class schedule has not been set up yet."
|
||||
icon={Calendar}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
src/app/(dashboard)/teacher/classes/students/page.tsx
Normal file
22
src/app/(dashboard)/teacher/classes/students/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { User } from "lucide-react"
|
||||
|
||||
export default function StudentsPage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Students</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage student list.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No students found"
|
||||
description="There are no students in your classes yet."
|
||||
icon={User}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
28
src/app/(dashboard)/teacher/dashboard/page.tsx
Normal file
28
src/app/(dashboard)/teacher/dashboard/page.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { TeacherStats } from "@/modules/dashboard/components/teacher-stats";
|
||||
import { TeacherSchedule } from "@/modules/dashboard/components/teacher-schedule";
|
||||
import { RecentSubmissions } from "@/modules/dashboard/components/recent-submissions";
|
||||
import { TeacherQuickActions } from "@/modules/dashboard/components/teacher-quick-actions";
|
||||
|
||||
export default function TeacherDashboardPage() {
|
||||
return (
|
||||
<div className="flex-1 space-y-4">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<h2 className="text-3xl font-bold tracking-tight">Teacher Dashboard</h2>
|
||||
<div className="flex items-center space-x-2">
|
||||
<TeacherQuickActions />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Overview Stats */}
|
||||
<TeacherStats />
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
||||
{/* Left Column: Schedule (3/7 width) */}
|
||||
<TeacherSchedule />
|
||||
|
||||
{/* Right Column: Recent Activity (4/7 width) */}
|
||||
<RecentSubmissions />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
76
src/app/(dashboard)/teacher/exams/[id]/build/page.tsx
Normal file
76
src/app/(dashboard)/teacher/exams/[id]/build/page.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { ExamAssembly } from "@/modules/exams/components/exam-assembly"
|
||||
import { getExamById } from "@/modules/exams/data-access"
|
||||
import { getQuestions } from "@/modules/questions/data-access"
|
||||
import type { Question } from "@/modules/questions/types"
|
||||
import type { ExamNode } from "@/modules/exams/components/assembly/selected-question-list"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
|
||||
export default async function BuildExamPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
|
||||
const exam = await getExamById(id)
|
||||
if (!exam) return notFound()
|
||||
|
||||
// Fetch all available questions (for selection pool)
|
||||
// In a real app, this might be paginated or filtered by exam subject/grade
|
||||
const { data: questionsData } = await getQuestions({ pageSize: 100 })
|
||||
|
||||
const questionOptions: Question[] = questionsData.map((q) => ({
|
||||
id: q.id,
|
||||
content: q.content as any,
|
||||
type: q.type as any,
|
||||
difficulty: q.difficulty ?? 1,
|
||||
createdAt: new Date(q.createdAt),
|
||||
updatedAt: new Date(q.updatedAt),
|
||||
author: q.author ? {
|
||||
id: q.author.id,
|
||||
name: q.author.name || "Unknown",
|
||||
image: q.author.image || null
|
||||
} : null,
|
||||
knowledgePoints: (q.questionsToKnowledgePoints || []).map((kp) => ({
|
||||
id: kp.knowledgePoint.id,
|
||||
name: kp.knowledgePoint.name
|
||||
}))
|
||||
}))
|
||||
|
||||
const initialSelected = (exam.questions || []).map(q => ({
|
||||
id: q.id,
|
||||
score: q.score || 0
|
||||
}))
|
||||
|
||||
// Prepare initialStructure on server side to avoid hydration mismatch with random IDs
|
||||
let initialStructure: ExamNode[] = exam.structure as ExamNode[] || []
|
||||
|
||||
if (initialStructure.length === 0 && initialSelected.length > 0) {
|
||||
initialStructure = initialSelected.map(s => ({
|
||||
id: createId(), // Generate stable ID on server
|
||||
type: 'question',
|
||||
questionId: s.id,
|
||||
score: s.score
|
||||
}))
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Build Exam</h2>
|
||||
<p className="text-muted-foreground">Add questions and adjust scores.</p>
|
||||
</div>
|
||||
</div>
|
||||
<ExamAssembly
|
||||
examId={exam.id}
|
||||
title={exam.title}
|
||||
subject={exam.subject}
|
||||
grade={exam.grade}
|
||||
difficulty={exam.difficulty}
|
||||
totalScore={exam.totalScore}
|
||||
durationMin={exam.durationMin}
|
||||
initialSelected={initialSelected}
|
||||
initialStructure={initialStructure}
|
||||
questionOptions={questionOptions}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
25
src/app/(dashboard)/teacher/exams/all/loading.tsx
Normal file
25
src/app/(dashboard)/teacher/exams/all/loading.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="rounded-md border p-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-[95%]" />
|
||||
<Skeleton className="h-4 w-[90%]" />
|
||||
<Skeleton className="h-4 w-[85%]" />
|
||||
<Skeleton className="h-4 w-[80%]" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
47
src/app/(dashboard)/teacher/exams/all/page.tsx
Normal file
47
src/app/(dashboard)/teacher/exams/all/page.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Suspense } from "react"
|
||||
import Link from "next/link"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { ExamDataTable } from "@/modules/exams/components/exam-data-table"
|
||||
import { examColumns } from "@/modules/exams/components/exam-columns"
|
||||
import { ExamFilters } from "@/modules/exams/components/exam-filters"
|
||||
import { getExams } from "@/modules/exams/data-access"
|
||||
|
||||
export default async function AllExamsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||
}) {
|
||||
const params = await searchParams
|
||||
|
||||
const exams = await getExams({
|
||||
q: params.q as string,
|
||||
status: params.status as string,
|
||||
difficulty: params.difficulty as string,
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex flex-col justify-between space-y-4 md:flex-row md:items-center md:space-y-0">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">All Exams</h2>
|
||||
<p className="text-muted-foreground">View and manage all your exams.</p>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button asChild>
|
||||
<Link href="/teacher/exams/create">Create Exam</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<Suspense fallback={<div className="h-10 w-full animate-pulse rounded-md bg-muted" />}>
|
||||
<ExamFilters />
|
||||
</Suspense>
|
||||
|
||||
<div className="rounded-md border bg-card">
|
||||
<ExamDataTable columns={examColumns} data={exams} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
17
src/app/(dashboard)/teacher/exams/create/loading.tsx
Normal file
17
src/app/(dashboard)/teacher/exams/create/loading.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-[240px] w-full" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
15
src/app/(dashboard)/teacher/exams/create/page.tsx
Normal file
15
src/app/(dashboard)/teacher/exams/create/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ExamForm } from "@/modules/exams/components/exam-form"
|
||||
|
||||
export default function CreateExamPage() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Create Exam</h2>
|
||||
<p className="text-muted-foreground">Design a new exam for your students.</p>
|
||||
</div>
|
||||
</div>
|
||||
<ExamForm />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { GradingView } from "@/modules/exams/components/grading-view"
|
||||
import { getSubmissionDetails } from "@/modules/exams/data-access"
|
||||
import { formatDate } from "@/shared/lib/utils"
|
||||
|
||||
export default async function SubmissionGradingPage({ params }: { params: Promise<{ submissionId: string }> }) {
|
||||
const { submissionId } = await params
|
||||
const submission = await getSubmissionDetails(submissionId)
|
||||
|
||||
if (!submission) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-4 p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{submission.examTitle}</h2>
|
||||
<div className="flex items-center gap-4 text-sm text-muted-foreground mt-1">
|
||||
<span>Student: <span className="font-medium text-foreground">{submission.studentName}</span></span>
|
||||
<span>โข</span>
|
||||
<span>Submitted: {submission.submittedAt ? formatDate(submission.submittedAt) : "-"}</span>
|
||||
<span>โข</span>
|
||||
<span className="capitalize">Status: {submission.status}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GradingView
|
||||
submissionId={submission.id}
|
||||
studentName={submission.studentName}
|
||||
examTitle={submission.examTitle}
|
||||
submittedAt={submission.submittedAt}
|
||||
status={submission.status || "started"}
|
||||
totalScore={submission.totalScore}
|
||||
answers={submission.answers}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
21
src/app/(dashboard)/teacher/exams/grading/loading.tsx
Normal file
21
src/app/(dashboard)/teacher/exams/grading/loading.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<div className="rounded-md border p-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-[95%]" />
|
||||
<Skeleton className="h-4 w-[90%]" />
|
||||
<Skeleton className="h-4 w-[85%]" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
22
src/app/(dashboard)/teacher/exams/grading/page.tsx
Normal file
22
src/app/(dashboard)/teacher/exams/grading/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { SubmissionDataTable } from "@/modules/exams/components/submission-data-table"
|
||||
import { submissionColumns } from "@/modules/exams/components/submission-columns"
|
||||
import { getExamSubmissions } from "@/modules/exams/data-access"
|
||||
|
||||
export default async function ExamGradingPage() {
|
||||
const submissions = await getExamSubmissions()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grading</h2>
|
||||
<p className="text-muted-foreground">Grade student exam submissions.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border bg-card">
|
||||
<SubmissionDataTable columns={submissionColumns} data={submissions} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
src/app/(dashboard)/teacher/exams/page.tsx
Normal file
5
src/app/(dashboard)/teacher/exams/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
export default function ExamsPage() {
|
||||
redirect("/teacher/exams/all")
|
||||
}
|
||||
26
src/app/(dashboard)/teacher/homework/assignments/page.tsx
Normal file
26
src/app/(dashboard)/teacher/homework/assignments/page.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { PenTool } from "lucide-react"
|
||||
|
||||
export default function AssignmentsPage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Assignments</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage homework assignments.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No assignments"
|
||||
description="You haven't created any assignments yet."
|
||||
icon={PenTool}
|
||||
action={{
|
||||
label: "Create Assignment",
|
||||
href: "#"
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
src/app/(dashboard)/teacher/homework/page.tsx
Normal file
5
src/app/(dashboard)/teacher/homework/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
export default function HomeworkPage() {
|
||||
redirect("/teacher/homework/assignments")
|
||||
}
|
||||
22
src/app/(dashboard)/teacher/homework/submissions/page.tsx
Normal file
22
src/app/(dashboard)/teacher/homework/submissions/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Inbox } from "lucide-react"
|
||||
|
||||
export default function SubmissionsPage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Submissions</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Review student homework submissions.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No submissions"
|
||||
description="There are no homework submissions to review."
|
||||
icon={Inbox}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
74
src/app/(dashboard)/teacher/questions/page.tsx
Normal file
74
src/app/(dashboard)/teacher/questions/page.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Suspense } from "react"
|
||||
import { Plus } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { QuestionDataTable } from "@/modules/questions/components/question-data-table"
|
||||
import { columns } from "@/modules/questions/components/question-columns"
|
||||
import { QuestionFilters } from "@/modules/questions/components/question-filters"
|
||||
import { CreateQuestionButton } from "@/modules/questions/components/create-question-button"
|
||||
import { MOCK_QUESTIONS } from "@/modules/questions/mock-data"
|
||||
import { Question } from "@/modules/questions/types"
|
||||
|
||||
// Simulate backend delay and filtering
|
||||
async function getQuestions(searchParams: { [key: string]: string | string[] | undefined }) {
|
||||
// In a real app, you would call your DB or API here
|
||||
// await new Promise((resolve) => setTimeout(resolve, 500)) // Simulate network latency
|
||||
|
||||
let filtered = [...MOCK_QUESTIONS]
|
||||
|
||||
const q = searchParams.q as string
|
||||
const type = searchParams.type as string
|
||||
const difficulty = searchParams.difficulty as string
|
||||
|
||||
if (q) {
|
||||
filtered = filtered.filter((item) =>
|
||||
(typeof item.content === 'string' && item.content.toLowerCase().includes(q.toLowerCase())) ||
|
||||
(typeof item.content === 'object' && JSON.stringify(item.content).toLowerCase().includes(q.toLowerCase()))
|
||||
)
|
||||
}
|
||||
|
||||
if (type && type !== "all") {
|
||||
filtered = filtered.filter((item) => item.type === type)
|
||||
}
|
||||
|
||||
if (difficulty && difficulty !== "all") {
|
||||
filtered = filtered.filter((item) => item.difficulty === parseInt(difficulty))
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
export default async function QuestionBankPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||
}) {
|
||||
const params = await searchParams
|
||||
const questions = await getQuestions(params)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex flex-col justify-between space-y-4 md:flex-row md:items-center md:space-y-0">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Question Bank</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your question repository for exams and assignments.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<CreateQuestionButton />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<Suspense fallback={<div className="h-10 w-full animate-pulse rounded-md bg-muted" />}>
|
||||
<QuestionFilters />
|
||||
</Suspense>
|
||||
|
||||
<div className="rounded-md border bg-card">
|
||||
<QuestionDataTable columns={columns} data={questions} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
66
src/app/(dashboard)/teacher/textbooks/[id]/loading.tsx
Normal file
66
src/app/(dashboard)/teacher/textbooks/[id]/loading.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton";
|
||||
import { Separator } from "@/shared/components/ui/separator";
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="space-y-6 max-w-5xl mx-auto">
|
||||
{/* Header Skeleton */}
|
||||
<div className="flex items-center gap-4">
|
||||
<Skeleton className="h-10 w-10 rounded-md" /> {/* Back Button */}
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-5 w-16" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</div>
|
||||
<Skeleton className="h-8 w-64" />
|
||||
</div>
|
||||
<Skeleton className="h-10 w-32" /> {/* Edit Button */}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
|
||||
{/* Main Content Skeleton */}
|
||||
<div className="md:col-span-2 space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<Skeleton className="h-6 w-40" />
|
||||
<Skeleton className="h-8 w-24" />
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg border bg-card p-6 space-y-4">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="flex items-center gap-4">
|
||||
<Skeleton className="h-6 w-6 rounded-md" />
|
||||
<Skeleton className="h-6 w-full rounded-md" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sidebar Skeleton */}
|
||||
<div className="space-y-6">
|
||||
<div className="rounded-lg border bg-card p-6 space-y-4">
|
||||
<Skeleton className="h-6 w-32 mb-4" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-16" />
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-20" />
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-3 w-12" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-3 w-12" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
80
src/app/(dashboard)/teacher/textbooks/[id]/page.tsx
Normal file
80
src/app/(dashboard)/teacher/textbooks/[id]/page.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { ArrowLeft, Edit } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByChapterId } from "@/modules/textbooks/data-access";
|
||||
import { TextbookContentLayout } from "@/modules/textbooks/components/textbook-content-layout";
|
||||
import { TextbookSettingsDialog } from "@/modules/textbooks/components/textbook-settings-dialog";
|
||||
|
||||
export default async function TextbookDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
|
||||
const [textbook, chapters] = await Promise.all([
|
||||
getTextbookById(id),
|
||||
getChaptersByTextbookId(id),
|
||||
]);
|
||||
|
||||
if (!textbook) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
// Fetch all KPs for these chapters. In a real app, this might be optimized to fetch only needed or use a different query strategy.
|
||||
// For now, we simulate fetching KPs for all chapters to pass down, or we could fetch on demand.
|
||||
// Given the layout loads everything client-side for interactivity, let's fetch all KPs associated with any chapter in this textbook.
|
||||
// We'll need to extend the data access for this specific query pattern or loop.
|
||||
// For simplicity in this mock, let's assume getKnowledgePointsByChapterId can handle fetching all KPs for a textbook if we had such a function,
|
||||
// or we iterate. Let's create a helper to get all KPs for the textbook's chapters.
|
||||
|
||||
// Actually, let's update data-access to support getting KPs by Textbook ID directly or just fetch all for mock.
|
||||
// Since we don't have getKnowledgePointsByTextbookId, we will map over chapters.
|
||||
|
||||
const allKnowledgePoints = (await Promise.all(
|
||||
chapters.map(c => getKnowledgePointsByChapterId(c.id))
|
||||
)).flat();
|
||||
|
||||
// Also need to get KPs for children chapters if any
|
||||
const childrenKPs = (await Promise.all(
|
||||
chapters.flatMap(c => c.children || []).map(child => getKnowledgePointsByChapterId(child.id))
|
||||
)).flat();
|
||||
|
||||
const knowledgePoints = [...allKnowledgePoints, ...childrenKPs];
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-[calc(100vh-4rem)] overflow-hidden">
|
||||
{/* Header / Nav (Fixed height) */}
|
||||
<div className="flex items-center gap-4 py-4 border-b shrink-0 bg-background z-10">
|
||||
<Button variant="ghost" size="icon" asChild>
|
||||
<Link href="/teacher/textbooks">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<Badge variant="outline">{textbook.subject}</Badge>
|
||||
<span className="text-xs text-muted-foreground uppercase tracking-wider font-medium">
|
||||
{textbook.grade}
|
||||
</span>
|
||||
</div>
|
||||
<h1 className="text-xl font-bold tracking-tight line-clamp-1">{textbook.title}</h1>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<TextbookSettingsDialog textbook={textbook} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Content Layout (Flex grow) */}
|
||||
<div className="flex-1 overflow-hidden pt-6">
|
||||
<TextbookContentLayout
|
||||
chapters={chapters}
|
||||
knowledgePoints={knowledgePoints}
|
||||
textbookId={id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
48
src/app/(dashboard)/teacher/textbooks/loading.tsx
Normal file
48
src/app/(dashboard)/teacher/textbooks/loading.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton";
|
||||
import { Card, CardContent, CardFooter, CardHeader } from "@/shared/components/ui/card";
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header Skeleton */}
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-96" />
|
||||
</div>
|
||||
<Skeleton className="h-10 w-32" />
|
||||
</div>
|
||||
|
||||
{/* Toolbar Skeleton */}
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between bg-card p-4 rounded-lg border shadow-sm">
|
||||
<Skeleton className="h-10 w-full md:w-96" />
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Skeleton className="h-10 w-[140px]" />
|
||||
<Skeleton className="h-10 w-[140px]" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Grid Content Skeleton */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Card key={i} className="h-full overflow-hidden">
|
||||
<div className="aspect-[4/3] w-full bg-muted/30 p-6 flex items-center justify-center">
|
||||
<Skeleton className="h-24 w-20 rounded-sm" />
|
||||
</div>
|
||||
<CardHeader className="p-4 pb-2 space-y-2">
|
||||
<Skeleton className="h-5 w-16" />
|
||||
<Skeleton className="h-6 w-full" />
|
||||
</CardHeader>
|
||||
<CardContent className="p-4 pt-0 space-y-2">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
</CardContent>
|
||||
<CardFooter className="p-4 pt-0 mt-auto">
|
||||
<Skeleton className="h-6 w-full rounded-md" />
|
||||
</CardFooter>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
78
src/app/(dashboard)/teacher/textbooks/page.tsx
Normal file
78
src/app/(dashboard)/teacher/textbooks/page.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Search, Filter } from "lucide-react";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Input } from "@/shared/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/shared/components/ui/select";
|
||||
import { TextbookCard } from "@/modules/textbooks/components/textbook-card";
|
||||
import { TextbookFormDialog } from "@/modules/textbooks/components/textbook-form-dialog";
|
||||
import { getTextbooks } from "@/modules/textbooks/data-access";
|
||||
|
||||
export default async function TextbooksPage() {
|
||||
// In a real app, we would parse searchParams here
|
||||
const textbooks = await getTextbooks();
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Page Header */}
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Textbooks</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your digital curriculum resources and chapters.
|
||||
</p>
|
||||
</div>
|
||||
<TextbookFormDialog />
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between bg-card p-4 rounded-lg border shadow-sm">
|
||||
<div className="relative w-full md:w-96">
|
||||
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search textbooks..."
|
||||
className="pl-9 bg-background"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Select>
|
||||
<SelectTrigger className="w-[140px] bg-background">
|
||||
<Filter className="mr-2 h-4 w-4 text-muted-foreground" />
|
||||
<SelectValue placeholder="Subject" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Subjects</SelectItem>
|
||||
<SelectItem value="math">Mathematics</SelectItem>
|
||||
<SelectItem value="physics">Physics</SelectItem>
|
||||
<SelectItem value="history">History</SelectItem>
|
||||
<SelectItem value="english">English</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select>
|
||||
<SelectTrigger className="w-[140px] bg-background">
|
||||
<SelectValue placeholder="Grade" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Grades</SelectItem>
|
||||
<SelectItem value="10">Grade 10</SelectItem>
|
||||
<SelectItem value="11">Grade 11</SelectItem>
|
||||
<SelectItem value="12">Grade 12</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Grid Content */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{textbooks.map((textbook) => (
|
||||
<TextbookCard key={textbook.id} textbook={textbook} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +1,177 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@plugin "tailwindcss-animate";
|
||||
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
/* Neutral: Zinc - Clean, Professional, International Style */
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 240 10% 3.9%;
|
||||
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 240 10% 3.9%;
|
||||
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 240 10% 3.9%;
|
||||
|
||||
/* Brand: Deep Indigo */
|
||||
--primary: 240 5.9% 10%;
|
||||
--primary-foreground: 0 0% 98%;
|
||||
|
||||
--secondary: 240 4.8% 95.9%;
|
||||
--secondary-foreground: 240 5.9% 10%;
|
||||
|
||||
--muted: 240 4.8% 95.9%;
|
||||
--muted-foreground: 240 3.8% 46.1%;
|
||||
|
||||
--accent: 240 4.8% 95.9%;
|
||||
--accent-foreground: 240 5.9% 10%;
|
||||
|
||||
/* Destructive: Subtle Red */
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
|
||||
/* Borders & UI */
|
||||
--border: 240 5.9% 90%;
|
||||
--input: 240 5.9% 90%;
|
||||
--ring: 240 5.9% 10%;
|
||||
|
||||
--radius: 0.5rem;
|
||||
|
||||
/* Chart / Data Visualization Colors */
|
||||
--chart-1: 12 76% 61%;
|
||||
--chart-2: 173 58% 39%;
|
||||
--chart-3: 197 37% 24%;
|
||||
--chart-4: 43 74% 66%;
|
||||
--chart-5: 27 87% 67%;
|
||||
|
||||
/* Sidebar Specific */
|
||||
--sidebar-background: 0 0% 98%;
|
||||
--sidebar-foreground: 240 5.3% 26.1%;
|
||||
--sidebar-primary: 240 5.9% 10%;
|
||||
--sidebar-primary-foreground: 0 0% 98%;
|
||||
--sidebar-accent: 240 4.8% 95.9%;
|
||||
--sidebar-accent-foreground: 240 5.9% 10%;
|
||||
--sidebar-border: 220 13% 91%;
|
||||
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||
}
|
||||
|
||||
.dark {
|
||||
/* Dark Mode: Deep Zinc Base */
|
||||
--background: 240 10% 3.9%;
|
||||
--foreground: 0 0% 98%;
|
||||
|
||||
--card: 240 10% 3.9%;
|
||||
--card-foreground: 0 0% 98%;
|
||||
|
||||
--popover: 240 10% 3.9%;
|
||||
--popover-foreground: 0 0% 98%;
|
||||
|
||||
/* Brand Dark: Adjusted for contrast */
|
||||
--primary: 0 0% 98%;
|
||||
--primary-foreground: 240 5.9% 10%;
|
||||
|
||||
--secondary: 240 3.7% 15.9%;
|
||||
--secondary-foreground: 0 0% 98%;
|
||||
|
||||
--muted: 240 3.7% 15.9%;
|
||||
--muted-foreground: 240 5% 64.9%;
|
||||
|
||||
--accent: 240 3.7% 15.9%;
|
||||
--accent-foreground: 0 0% 98%;
|
||||
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
|
||||
--border: 240 3.7% 15.9%;
|
||||
--input: 240 3.7% 15.9%;
|
||||
--ring: 240 4.9% 83.9%;
|
||||
|
||||
--chart-1: 220 70% 50%;
|
||||
--chart-2: 160 60% 45%;
|
||||
--chart-3: 30 80% 55%;
|
||||
--chart-4: 280 65% 60%;
|
||||
--chart-5: 340 75% 55%;
|
||||
|
||||
--sidebar-background: 240 5.9% 10%;
|
||||
--sidebar-foreground: 240 4.8% 95.9%;
|
||||
--sidebar-primary: 224.3 76.3% 48%;
|
||||
--sidebar-primary-foreground: 0 0% 100%;
|
||||
--sidebar-accent: 240 3.7% 15.9%;
|
||||
--sidebar-accent-foreground: 240 4.8% 95.9%;
|
||||
--sidebar-border: 240 3.7% 15.9%;
|
||||
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
--color-background: hsl(var(--background));
|
||||
--color-foreground: hsl(var(--foreground));
|
||||
|
||||
--color-card: hsl(var(--card));
|
||||
--color-card-foreground: hsl(var(--card-foreground));
|
||||
|
||||
--color-popover: hsl(var(--popover));
|
||||
--color-popover-foreground: hsl(var(--popover-foreground));
|
||||
|
||||
--color-primary: hsl(var(--primary));
|
||||
--color-primary-foreground: hsl(var(--primary-foreground));
|
||||
|
||||
--color-secondary: hsl(var(--secondary));
|
||||
--color-secondary-foreground: hsl(var(--secondary-foreground));
|
||||
|
||||
--color-muted: hsl(var(--muted));
|
||||
--color-muted-foreground: hsl(var(--muted-foreground));
|
||||
|
||||
--color-accent: hsl(var(--accent));
|
||||
--color-accent-foreground: hsl(var(--accent-foreground));
|
||||
|
||||
--color-destructive: hsl(var(--destructive));
|
||||
--color-destructive-foreground: hsl(var(--destructive-foreground));
|
||||
|
||||
--color-border: hsl(var(--border));
|
||||
--color-input: hsl(var(--input));
|
||||
--color-ring: hsl(var(--ring));
|
||||
|
||||
--color-chart-1: hsl(var(--chart-1));
|
||||
--color-chart-2: hsl(var(--chart-2));
|
||||
--color-chart-3: hsl(var(--chart-3));
|
||||
--color-chart-4: hsl(var(--chart-4));
|
||||
--color-chart-5: hsl(var(--chart-5));
|
||||
|
||||
--color-sidebar: hsl(var(--sidebar-background));
|
||||
--color-sidebar-foreground: hsl(var(--sidebar-foreground));
|
||||
--color-sidebar-primary: hsl(var(--sidebar-primary));
|
||||
--color-sidebar-primary-foreground: hsl(var(--sidebar-primary-foreground));
|
||||
--color-sidebar-accent: hsl(var(--sidebar-accent));
|
||||
--color-sidebar-accent-foreground: hsl(var(--sidebar-accent-foreground));
|
||||
--color-sidebar-border: hsl(var(--sidebar-border));
|
||||
--color-sidebar-ring: hsl(var(--sidebar-ring));
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
--radius-lg: var(--radius);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
|
||||
--animate-accordion-down: accordion-down 0.2s ease-out;
|
||||
--animate-accordion-up: accordion-up 0.2s ease-out;
|
||||
|
||||
@keyframes accordion-down {
|
||||
from { height: 0; }
|
||||
to { height: var(--radix-accordion-content-height); }
|
||||
}
|
||||
@keyframes accordion-up {
|
||||
from { height: var(--radix-accordion-content-height); }
|
||||
to { height: 0; }
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
/* Base Styles */
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
font-feature-settings: "rlig" 1, "calt" 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import { ThemeProvider } from "@/shared/components/theme-provider";
|
||||
import { Toaster } from "@/shared/components/ui/sonner";
|
||||
import { NuqsAdapter } from 'nuqs/adapters/next/app'
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
title: "Next_Edu - K12 ๆบๆ
งๆๅก็ณป็ป",
|
||||
description: "Enterprise Grade K12 Education Management System",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
@@ -23,11 +15,21 @@ export default function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
className={`antialiased`}
|
||||
>
|
||||
{children}
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="system"
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
<NuqsAdapter>
|
||||
{children}
|
||||
</NuqsAdapter>
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,66 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||
To get started, edit the page.tsx file.
|
||||
This is Update.
|
||||
</h1>
|
||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
23
src/env.mjs
Normal file
23
src/env.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createEnv } from "@t3-oss/env-nextjs";
|
||||
import { z } from "zod";
|
||||
|
||||
export const env = createEnv({
|
||||
server: {
|
||||
DATABASE_URL: z.string().url(),
|
||||
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
||||
NEXTAUTH_SECRET: z.string().min(1).optional(),
|
||||
NEXTAUTH_URL: z.string().url().optional(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_APP_URL: z.string().url().optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
DATABASE_URL: process.env.DATABASE_URL,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
|
||||
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
|
||||
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
|
||||
},
|
||||
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
|
||||
emptyStringAsUndefined: true,
|
||||
});
|
||||
33
src/modules/auth/components/auth-layout.tsx
Normal file
33
src/modules/auth/components/auth-layout.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import Link from "next/link"
|
||||
import { GraduationCap } from "lucide-react"
|
||||
|
||||
interface AuthLayoutProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export function AuthLayout({ children }: AuthLayoutProps) {
|
||||
return (
|
||||
<div className="container relative h-screen flex-col items-center justify-center grid lg:max-w-none lg:grid-cols-2 lg:px-0">
|
||||
<div className="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex">
|
||||
<div className="absolute inset-0 bg-zinc-900" />
|
||||
<div className="relative z-20 flex items-center text-lg font-medium">
|
||||
<GraduationCap className="mr-2 h-6 w-6" />
|
||||
Next_Edu
|
||||
</div>
|
||||
<div className="relative z-20 mt-auto">
|
||||
<blockquote className="space-y-2">
|
||||
<p className="text-lg">
|
||||
“This platform has completely transformed how we deliver education to our students. The attention to detail and performance is unmatched.”
|
||||
</p>
|
||||
<footer className="text-sm">Sofia Davis</footer>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div className="lg:p-8">
|
||||
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
103
src/modules/auth/components/login-form.tsx
Normal file
103
src/modules/auth/components/login-form.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import Link from "next/link"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import { Loader2, Github } from "lucide-react"
|
||||
|
||||
interface LoginFormProps extends React.HTMLAttributes<HTMLDivElement> {}
|
||||
|
||||
export function LoginForm({ className, ...props }: LoginFormProps) {
|
||||
const [isLoading, setIsLoading] = React.useState<boolean>(false)
|
||||
|
||||
async function onSubmit(event: React.SyntheticEvent) {
|
||||
event.preventDefault()
|
||||
setIsLoading(true)
|
||||
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn("grid gap-6", className)} {...props}>
|
||||
<div className="flex flex-col space-y-2 text-center">
|
||||
<h1 className="text-2xl font-semibold tracking-tight">
|
||||
Welcome back
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Enter your email to sign in to your account
|
||||
</p>
|
||||
</div>
|
||||
<form onSubmit={onSubmit}>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
placeholder="name@example.com"
|
||||
type="email"
|
||||
autoCapitalize="none"
|
||||
autoComplete="email"
|
||||
autoCorrect="off"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label htmlFor="password">Password</Label>
|
||||
<Link
|
||||
href="/forgot-password"
|
||||
className="text-sm font-medium text-muted-foreground hover:underline"
|
||||
>
|
||||
Forgot password?
|
||||
</Link>
|
||||
</div>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<Button disabled={isLoading}>
|
||||
{isLoading && (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Sign In with Email
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
<div className="relative">
|
||||
<div className="absolute inset-0 flex items-center">
|
||||
<span className="w-full border-t" />
|
||||
</div>
|
||||
<div className="relative flex justify-center text-xs uppercase">
|
||||
<span className="bg-background px-2 text-muted-foreground">
|
||||
Or continue with
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" type="button" disabled={isLoading}>
|
||||
{isLoading ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Github className="mr-2 h-4 w-4" />
|
||||
)}{" "}
|
||||
GitHub
|
||||
</Button>
|
||||
<p className="px-8 text-center text-sm text-muted-foreground">
|
||||
Don't have an account?{" "}
|
||||
<Link
|
||||
href="/register"
|
||||
className="underline underline-offset-4 hover:text-primary"
|
||||
>
|
||||
Sign up
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
107
src/modules/auth/components/register-form.tsx
Normal file
107
src/modules/auth/components/register-form.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import Link from "next/link"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import { Loader2, Github } from "lucide-react"
|
||||
|
||||
interface RegisterFormProps extends React.HTMLAttributes<HTMLDivElement> {}
|
||||
|
||||
export function RegisterForm({ className, ...props }: RegisterFormProps) {
|
||||
const [isLoading, setIsLoading] = React.useState<boolean>(false)
|
||||
|
||||
async function onSubmit(event: React.SyntheticEvent) {
|
||||
event.preventDefault()
|
||||
setIsLoading(true)
|
||||
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn("grid gap-6", className)} {...props}>
|
||||
<div className="flex flex-col space-y-2 text-center">
|
||||
<h1 className="text-2xl font-semibold tracking-tight">
|
||||
Create an account
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Enter your email below to create your account
|
||||
</p>
|
||||
</div>
|
||||
<form onSubmit={onSubmit}>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="name">Full Name</Label>
|
||||
<Input
|
||||
id="name"
|
||||
placeholder="John Doe"
|
||||
type="text"
|
||||
autoCapitalize="words"
|
||||
autoComplete="name"
|
||||
autoCorrect="off"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
placeholder="name@example.com"
|
||||
type="email"
|
||||
autoCapitalize="none"
|
||||
autoComplete="email"
|
||||
autoCorrect="off"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="password">Password</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<Button disabled={isLoading}>
|
||||
{isLoading && (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Create Account
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
<div className="relative">
|
||||
<div className="absolute inset-0 flex items-center">
|
||||
<span className="w-full border-t" />
|
||||
</div>
|
||||
<div className="relative flex justify-center text-xs uppercase">
|
||||
<span className="bg-background px-2 text-muted-foreground">
|
||||
Or continue with
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" type="button" disabled={isLoading}>
|
||||
{isLoading ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Github className="mr-2 h-4 w-4" />
|
||||
)}{" "}
|
||||
GitHub
|
||||
</Button>
|
||||
<p className="px-8 text-center text-sm text-muted-foreground">
|
||||
Already have an account?{" "}
|
||||
<Link
|
||||
href="/login"
|
||||
className="underline underline-offset-4 hover:text-primary"
|
||||
>
|
||||
Sign in
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
25
src/modules/dashboard/components/admin-view.tsx
Normal file
25
src/modules/dashboard/components/admin-view.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
|
||||
export function AdminDashboard() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Admin Dashboard</h1>
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
<Card>
|
||||
<CardHeader><CardTitle>System Status</CardTitle></CardHeader>
|
||||
<CardContent className="text-green-600 font-bold">Operational</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Total Users</CardTitle></CardHeader>
|
||||
<CardContent>2,450</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Active Sessions</CardTitle></CardHeader>
|
||||
<CardContent>142</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
105
src/modules/dashboard/components/recent-submissions.tsx
Normal file
105
src/modules/dashboard/components/recent-submissions.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/shared/components/ui/avatar";
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state";
|
||||
import { Inbox } from "lucide-react";
|
||||
|
||||
interface SubmissionItem {
|
||||
id: string;
|
||||
studentName: string;
|
||||
studentAvatar?: string;
|
||||
assignment: string;
|
||||
submittedAt: string;
|
||||
status: "submitted" | "late";
|
||||
}
|
||||
|
||||
const MOCK_SUBMISSIONS: SubmissionItem[] = [
|
||||
{
|
||||
id: "1",
|
||||
studentName: "Alice Johnson",
|
||||
assignment: "React Component Composition",
|
||||
submittedAt: "10 minutes ago",
|
||||
status: "submitted",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
studentName: "Bob Smith",
|
||||
assignment: "Design System Analysis",
|
||||
submittedAt: "1 hour ago",
|
||||
status: "submitted",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
studentName: "Charlie Brown",
|
||||
assignment: "React Component Composition",
|
||||
submittedAt: "2 hours ago",
|
||||
status: "late",
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
studentName: "Diana Prince",
|
||||
assignment: "CSS Grid Layout",
|
||||
submittedAt: "Yesterday",
|
||||
status: "submitted",
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
studentName: "Evan Wright",
|
||||
assignment: "Design System Analysis",
|
||||
submittedAt: "Yesterday",
|
||||
status: "submitted",
|
||||
},
|
||||
];
|
||||
|
||||
export function RecentSubmissions() {
|
||||
const hasSubmissions = MOCK_SUBMISSIONS.length > 0;
|
||||
|
||||
return (
|
||||
<Card className="col-span-4 lg:col-span-4">
|
||||
<CardHeader>
|
||||
<CardTitle>Recent Submissions</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!hasSubmissions ? (
|
||||
<EmptyState
|
||||
icon={Inbox}
|
||||
title="No New Submissions"
|
||||
description="All caught up! There are no new submissions to review."
|
||||
className="border-none h-[300px]"
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{MOCK_SUBMISSIONS.map((item) => (
|
||||
<div key={item.id} className="flex items-center justify-between group">
|
||||
<div className="flex items-center space-x-4">
|
||||
<Avatar className="h-9 w-9">
|
||||
<AvatarImage src={item.studentAvatar} alt={item.studentName} />
|
||||
<AvatarFallback>{item.studentName.charAt(0)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium leading-none">
|
||||
{item.studentName}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Submitted <span className="font-medium text-foreground">{item.assignment}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{/* Using static date for demo to prevent hydration mismatch */}
|
||||
{item.submittedAt}
|
||||
</div>
|
||||
{item.status === "late" && (
|
||||
<span className="inline-flex items-center rounded-full border border-destructive px-2 py-0.5 text-xs font-semibold text-destructive transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2">
|
||||
Late
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
21
src/modules/dashboard/components/student-view.tsx
Normal file
21
src/modules/dashboard/components/student-view.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
"use client"
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
|
||||
export function StudentDashboard() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Student Dashboard</h1>
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
<Card>
|
||||
<CardHeader><CardTitle>My Courses</CardTitle></CardHeader>
|
||||
<CardContent>Enrolled in 5 courses</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Assignments</CardTitle></CardHeader>
|
||||
<CardContent>2 due this week</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
21
src/modules/dashboard/components/teacher-quick-actions.tsx
Normal file
21
src/modules/dashboard/components/teacher-quick-actions.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { PlusCircle, CheckSquare, MessageSquare } from "lucide-react";
|
||||
|
||||
export function TeacherQuickActions() {
|
||||
return (
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button size="sm">
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
Create Assignment
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
<CheckSquare className="mr-2 h-4 w-4" />
|
||||
Grade All
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
<MessageSquare className="mr-2 h-4 w-4" />
|
||||
Message Class
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
81
src/modules/dashboard/components/teacher-schedule.tsx
Normal file
81
src/modules/dashboard/components/teacher-schedule.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { Clock, MapPin, CalendarX } from "lucide-react";
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state";
|
||||
|
||||
interface ScheduleItem {
|
||||
id: string;
|
||||
course: string;
|
||||
time: string;
|
||||
location: string;
|
||||
type: "Lecture" | "Workshop" | "Lab";
|
||||
}
|
||||
|
||||
// MOCK_SCHEDULE can be empty to test empty state
|
||||
const MOCK_SCHEDULE: ScheduleItem[] = [
|
||||
{
|
||||
id: "1",
|
||||
course: "Advanced Web Development",
|
||||
time: "09:00 AM - 10:30 AM",
|
||||
location: "Room 304",
|
||||
type: "Lecture",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
course: "UI/UX Design Principles",
|
||||
time: "11:00 AM - 12:30 PM",
|
||||
location: "Design Studio A",
|
||||
type: "Workshop",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
course: "Frontend Frameworks",
|
||||
time: "02:00 PM - 03:30 PM",
|
||||
location: "Online (Zoom)",
|
||||
type: "Lecture",
|
||||
},
|
||||
];
|
||||
|
||||
export function TeacherSchedule() {
|
||||
const hasSchedule = MOCK_SCHEDULE.length > 0;
|
||||
|
||||
return (
|
||||
<Card className="col-span-3">
|
||||
<CardHeader>
|
||||
<CardTitle>Today's Schedule</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!hasSchedule ? (
|
||||
<EmptyState
|
||||
icon={CalendarX}
|
||||
title="No Classes Today"
|
||||
description="You have no classes scheduled for today. Enjoy your free time!"
|
||||
className="border-none h-[300px]"
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{MOCK_SCHEDULE.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="flex items-center justify-between border-b pb-4 last:border-0 last:pb-0"
|
||||
>
|
||||
<div className="space-y-1">
|
||||
<p className="font-medium leading-none">{item.course}</p>
|
||||
<div className="flex items-center text-sm text-muted-foreground">
|
||||
<Clock className="mr-1 h-3 w-3" />
|
||||
<span className="mr-3">{item.time}</span>
|
||||
<MapPin className="mr-1 h-3 w-3" />
|
||||
<span>{item.location}</span>
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant={item.type === "Lecture" ? "default" : "secondary"}>
|
||||
{item.type}
|
||||
</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
83
src/modules/dashboard/components/teacher-stats.tsx
Normal file
83
src/modules/dashboard/components/teacher-stats.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card";
|
||||
import { Users, BookOpen, FileCheck, Calendar } from "lucide-react";
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton";
|
||||
|
||||
interface StatItem {
|
||||
title: string;
|
||||
value: string;
|
||||
description: string;
|
||||
icon: React.ElementType;
|
||||
}
|
||||
|
||||
const MOCK_STATS: StatItem[] = [
|
||||
{
|
||||
title: "Total Students",
|
||||
value: "1,248",
|
||||
description: "+12% from last semester",
|
||||
icon: Users,
|
||||
},
|
||||
{
|
||||
title: "Active Courses",
|
||||
value: "4",
|
||||
description: "2 lectures, 2 workshops",
|
||||
icon: BookOpen,
|
||||
},
|
||||
{
|
||||
title: "To Grade",
|
||||
value: "28",
|
||||
description: "5 submissions pending review",
|
||||
icon: FileCheck,
|
||||
},
|
||||
{
|
||||
title: "Upcoming Classes",
|
||||
value: "3",
|
||||
description: "Today's schedule",
|
||||
icon: Calendar,
|
||||
},
|
||||
];
|
||||
|
||||
interface TeacherStatsProps {
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export function TeacherStats({ isLoading = false }: TeacherStatsProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<Skeleton className="h-4 w-[100px]" />
|
||||
<Skeleton className="h-4 w-4 rounded-full" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-8 w-[60px] mb-2" />
|
||||
<Skeleton className="h-3 w-[140px]" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{MOCK_STATS.map((stat, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">
|
||||
{stat.title}
|
||||
</CardTitle>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{stat.value}</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{stat.description}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
25
src/modules/dashboard/components/teacher-view.tsx
Normal file
25
src/modules/dashboard/components/teacher-view.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import { TeacherQuickActions } from "@/modules/dashboard/components/teacher-quick-actions";
|
||||
import { TeacherStats } from "@/modules/dashboard/components/teacher-stats";
|
||||
import { TeacherSchedule } from "@/modules/dashboard/components/teacher-schedule";
|
||||
import { RecentSubmissions } from "@/modules/dashboard/components/recent-submissions";
|
||||
|
||||
// This component is now exclusively for the Teacher Role View
|
||||
export function TeacherDashboard() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Teacher Dashboard</h1>
|
||||
<TeacherQuickActions />
|
||||
</div>
|
||||
|
||||
<TeacherStats />
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
||||
<TeacherSchedule />
|
||||
<RecentSubmissions />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
244
src/modules/exams/actions.ts
Normal file
244
src/modules/exams/actions.ts
Normal file
@@ -0,0 +1,244 @@
|
||||
"use server"
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { ActionState } from "@/shared/types/action-state"
|
||||
import { z } from "zod"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
import { db } from "@/shared/db"
|
||||
import { exams, examQuestions, submissionAnswers, examSubmissions } from "@/shared/db/schema"
|
||||
import { eq } from "drizzle-orm"
|
||||
|
||||
const ExamCreateSchema = z.object({
|
||||
title: z.string().min(1),
|
||||
subject: z.string().min(1),
|
||||
grade: z.string().min(1),
|
||||
difficulty: z.coerce.number().int().min(1).max(5),
|
||||
totalScore: z.coerce.number().int().min(1),
|
||||
durationMin: z.coerce.number().int().min(1),
|
||||
scheduledAt: z.string().optional().nullable(),
|
||||
questions: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
score: z.coerce.number().int().min(0),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
|
||||
export async function createExamAction(
|
||||
prevState: ActionState<string> | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState<string>> {
|
||||
const rawQuestions = formData.get("questionsJson") as string | null
|
||||
|
||||
const parsed = ExamCreateSchema.safeParse({
|
||||
title: formData.get("title"),
|
||||
subject: formData.get("subject"),
|
||||
grade: formData.get("grade"),
|
||||
difficulty: formData.get("difficulty"),
|
||||
totalScore: formData.get("totalScore"),
|
||||
durationMin: formData.get("durationMin"),
|
||||
scheduledAt: formData.get("scheduledAt"),
|
||||
questions: rawQuestions ? JSON.parse(rawQuestions) : [],
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Invalid form data",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
}
|
||||
}
|
||||
|
||||
const input = parsed.data
|
||||
|
||||
const examId = createId()
|
||||
const scheduled = input.scheduledAt || undefined
|
||||
|
||||
const meta = {
|
||||
subject: input.subject,
|
||||
grade: input.grade,
|
||||
difficulty: input.difficulty,
|
||||
totalScore: input.totalScore,
|
||||
durationMin: input.durationMin,
|
||||
scheduledAt: scheduled ?? undefined,
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await getCurrentUser()
|
||||
await db.insert(exams).values({
|
||||
id: examId,
|
||||
title: input.title,
|
||||
description: JSON.stringify(meta),
|
||||
creatorId: user?.id ?? "user_teacher_123",
|
||||
startTime: scheduled ? new Date(scheduled) : null,
|
||||
status: "draft",
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Failed to create exam:", error)
|
||||
return {
|
||||
success: false,
|
||||
message: "Database error: Failed to create exam",
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/teacher/exams/all")
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Exam created successfully.",
|
||||
data: examId,
|
||||
}
|
||||
}
|
||||
|
||||
const ExamUpdateSchema = z.object({
|
||||
examId: z.string().min(1),
|
||||
questions: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
score: z.coerce.number().int().min(0),
|
||||
})
|
||||
)
|
||||
.default([]),
|
||||
structure: z.any().optional(), // Accept structure JSON
|
||||
status: z.enum(["draft", "published", "archived"]).optional(),
|
||||
})
|
||||
|
||||
export async function updateExamAction(
|
||||
prevState: ActionState<string> | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState<string>> {
|
||||
const rawQuestions = formData.get("questionsJson") as string | null
|
||||
const rawStructure = formData.get("structureJson") as string | null
|
||||
|
||||
const parsed = ExamUpdateSchema.safeParse({
|
||||
examId: formData.get("examId"),
|
||||
questions: rawQuestions ? JSON.parse(rawQuestions) : [],
|
||||
structure: rawStructure ? JSON.parse(rawStructure) : undefined,
|
||||
status: formData.get("status") ?? undefined,
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Invalid update data",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
}
|
||||
}
|
||||
|
||||
const { examId, questions, structure, status } = parsed.data
|
||||
|
||||
try {
|
||||
await db.delete(examQuestions).where(eq(examQuestions.examId, examId))
|
||||
if (questions.length > 0) {
|
||||
await db.insert(examQuestions).values(
|
||||
questions.map((q, idx) => ({
|
||||
examId,
|
||||
questionId: q.id,
|
||||
score: q.score ?? 0,
|
||||
order: idx,
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
// Prepare update object
|
||||
const updateData: any = {}
|
||||
if (status) updateData.status = status
|
||||
if (structure) updateData.structure = structure
|
||||
|
||||
if (Object.keys(updateData).length > 0) {
|
||||
await db.update(exams).set(updateData).where(eq(exams.id, examId))
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to update exam:", error)
|
||||
return {
|
||||
success: false,
|
||||
message: "Database error: Failed to update exam",
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/teacher/exams/all")
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Exam updated",
|
||||
data: examId,
|
||||
}
|
||||
}
|
||||
|
||||
const GradingSchema = z.object({
|
||||
submissionId: z.string().min(1),
|
||||
answers: z.array(z.object({
|
||||
id: z.string(), // answer id
|
||||
score: z.coerce.number().min(0),
|
||||
feedback: z.string().optional()
|
||||
}))
|
||||
})
|
||||
|
||||
export async function gradeSubmissionAction(
|
||||
prevState: ActionState<string> | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState<string>> {
|
||||
const rawAnswers = formData.get("answersJson") as string | null
|
||||
const parsed = GradingSchema.safeParse({
|
||||
submissionId: formData.get("submissionId"),
|
||||
answers: rawAnswers ? JSON.parse(rawAnswers) : []
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Invalid grading data",
|
||||
errors: parsed.error.flatten().fieldErrors
|
||||
}
|
||||
}
|
||||
|
||||
const { submissionId, answers } = parsed.data
|
||||
|
||||
try {
|
||||
let totalScore = 0
|
||||
|
||||
// Update each answer
|
||||
for (const ans of answers) {
|
||||
await db.update(submissionAnswers)
|
||||
.set({
|
||||
score: ans.score,
|
||||
feedback: ans.feedback,
|
||||
updatedAt: new Date()
|
||||
})
|
||||
.where(eq(submissionAnswers.id, ans.id))
|
||||
|
||||
totalScore += ans.score
|
||||
}
|
||||
|
||||
// Update submission total score and status
|
||||
await db.update(examSubmissions)
|
||||
.set({
|
||||
score: totalScore,
|
||||
status: "graded",
|
||||
updatedAt: new Date()
|
||||
})
|
||||
.where(eq(examSubmissions.id, submissionId))
|
||||
|
||||
} catch (error) {
|
||||
console.error("Grading failed:", error)
|
||||
return {
|
||||
success: false,
|
||||
message: "Database error during grading"
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath(`/teacher/exams/grading`)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Grading saved successfully"
|
||||
}
|
||||
}
|
||||
|
||||
async function getCurrentUser() {
|
||||
return { id: "user_teacher_123", role: "teacher" }
|
||||
}
|
||||
65
src/modules/exams/components/assembly/question-bank-list.tsx
Normal file
65
src/modules/exams/components/assembly/question-bank-list.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
"use client"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Card } from "@/shared/components/ui/card"
|
||||
import { Plus } from "lucide-react"
|
||||
import type { Question } from "@/modules/questions/types"
|
||||
|
||||
type QuestionBankListProps = {
|
||||
questions: Question[]
|
||||
onAdd: (question: Question) => void
|
||||
isAdded: (id: string) => boolean
|
||||
}
|
||||
|
||||
export function QuestionBankList({ questions, onAdd, isAdded }: QuestionBankListProps) {
|
||||
if (questions.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
No questions found matching your filters.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{questions.map((q) => {
|
||||
const added = isAdded(q.id)
|
||||
const content = q.content as { text?: string }
|
||||
return (
|
||||
<Card key={q.id} className="p-3 flex gap-3 hover:bg-muted/50 transition-colors">
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="text-[10px] uppercase">
|
||||
{q.type.replace("_", " ")}
|
||||
</Badge>
|
||||
<Badge variant="secondary" className="text-[10px]">
|
||||
Lvl {q.difficulty}
|
||||
</Badge>
|
||||
{q.knowledgePoints?.slice(0, 1).map((kp) => (
|
||||
<Badge key={kp.id} variant="outline" className="text-[10px] truncate max-w-[100px]">
|
||||
{kp.name}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-sm line-clamp-2 text-muted-foreground">
|
||||
{content.text || "No content preview"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
size="sm"
|
||||
variant={added ? "secondary" : "default"}
|
||||
disabled={added}
|
||||
onClick={() => onAdd(q)}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
181
src/modules/exams/components/assembly/selected-question-list.tsx
Normal file
181
src/modules/exams/components/assembly/selected-question-list.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
"use client"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { ArrowUp, ArrowDown, Trash2 } from "lucide-react"
|
||||
import type { Question } from "@/modules/questions/types"
|
||||
|
||||
export type ExamNode = {
|
||||
id: string
|
||||
type: 'group' | 'question'
|
||||
title?: string // For group
|
||||
questionId?: string // For question
|
||||
score?: number
|
||||
children?: ExamNode[] // For group
|
||||
question?: Question // Populated for rendering
|
||||
}
|
||||
|
||||
type SelectedQuestionListProps = {
|
||||
items: ExamNode[]
|
||||
onRemove: (id: string, parentId?: string) => void
|
||||
onMove: (id: string, direction: 'up' | 'down', parentId?: string) => void
|
||||
onScoreChange: (id: string, score: number) => void
|
||||
onGroupTitleChange: (id: string, title: string) => void
|
||||
onAddGroup: () => void
|
||||
}
|
||||
|
||||
export function SelectedQuestionList({
|
||||
items,
|
||||
onRemove,
|
||||
onMove,
|
||||
onScoreChange,
|
||||
onGroupTitleChange,
|
||||
onAddGroup
|
||||
}: SelectedQuestionListProps) {
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<div className="border border-dashed rounded-lg p-8 text-center text-muted-foreground text-sm flex flex-col gap-4">
|
||||
<p>No questions selected. Add questions from the bank or create a group.</p>
|
||||
<Button variant="outline" onClick={onAddGroup}>Create Section</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{items.map((node, idx) => {
|
||||
if (node.type === 'group') {
|
||||
return (
|
||||
<div key={node.id} className="rounded-lg border bg-muted/10 p-4 space-y-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<Input
|
||||
value={node.title || "Untitled Section"}
|
||||
onChange={(e) => onGroupTitleChange(node.id, e.target.value)}
|
||||
className="font-semibold h-9 bg-transparent border-transparent hover:border-input focus:bg-background"
|
||||
/>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => onMove(node.id, 'up')} disabled={idx === 0}>
|
||||
<ArrowUp className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => onMove(node.id, 'down')} disabled={idx === items.length - 1}>
|
||||
<ArrowDown className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-destructive" onClick={() => onRemove(node.id)}>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pl-4 border-l-2 border-muted space-y-3">
|
||||
{node.children?.length === 0 ? (
|
||||
<div className="text-xs text-muted-foreground italic py-2">Drag questions here or add from bank</div>
|
||||
) : (
|
||||
node.children?.map((child, cIdx) => (
|
||||
<QuestionItem
|
||||
key={child.id}
|
||||
item={child}
|
||||
index={cIdx}
|
||||
total={node.children?.length || 0}
|
||||
onRemove={() => onRemove(child.id, node.id)}
|
||||
onMove={(dir) => onMove(child.id, dir, node.id)}
|
||||
onScoreChange={(score) => onScoreChange(child.id, score)}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<QuestionItem
|
||||
key={node.id}
|
||||
item={node}
|
||||
index={idx}
|
||||
total={items.length}
|
||||
onRemove={() => onRemove(node.id)}
|
||||
onMove={(dir) => onMove(node.id, dir)}
|
||||
onScoreChange={(score) => onScoreChange(node.id, score)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
<div className="flex justify-center pt-2">
|
||||
<Button variant="outline" size="sm" onClick={onAddGroup} className="w-full border-dashed">
|
||||
+ Add Section
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function QuestionItem({ item, index, total, onRemove, onMove, onScoreChange }: {
|
||||
item: ExamNode
|
||||
index: number
|
||||
total: number
|
||||
onRemove: () => void
|
||||
onMove: (dir: 'up' | 'down') => void
|
||||
onScoreChange: (score: number) => void
|
||||
}) {
|
||||
const content = item.question?.content as { text?: string }
|
||||
return (
|
||||
<div className="group flex flex-col gap-3 rounded-md border p-3 bg-card hover:border-primary/50 transition-colors">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex gap-2">
|
||||
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-muted text-xs font-medium">
|
||||
{index + 1}
|
||||
</span>
|
||||
<p className="text-sm line-clamp-2 pt-0.5">
|
||||
{content?.text || "Question content"}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 text-muted-foreground hover:text-destructive"
|
||||
onClick={onRemove}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pl-8">
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6"
|
||||
disabled={index === 0}
|
||||
onClick={() => onMove('up')}
|
||||
>
|
||||
<ArrowUp className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6"
|
||||
disabled={index === total - 1}
|
||||
onClick={() => onMove('down')}
|
||||
>
|
||||
<ArrowDown className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor={`score-${item.id}`} className="text-xs text-muted-foreground">
|
||||
Score
|
||||
</Label>
|
||||
<Input
|
||||
id={`score-${item.id}`}
|
||||
type="number"
|
||||
min={0}
|
||||
className="h-7 w-16 text-right"
|
||||
value={item.score}
|
||||
onChange={(e) => onScoreChange(parseInt(e.target.value) || 0)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
570
src/modules/exams/components/assembly/structure-editor.tsx
Normal file
570
src/modules/exams/components/assembly/structure-editor.tsx
Normal file
@@ -0,0 +1,570 @@
|
||||
"use client"
|
||||
|
||||
import React, { useMemo, useState } from "react"
|
||||
import {
|
||||
DndContext,
|
||||
pointerWithin,
|
||||
rectIntersection,
|
||||
getFirstCollision,
|
||||
CollisionDetection,
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
useSensor,
|
||||
useSensors,
|
||||
DragOverlay,
|
||||
defaultDropAnimationSideEffects,
|
||||
DragStartEvent,
|
||||
DragOverEvent,
|
||||
DragEndEvent,
|
||||
DropAnimation,
|
||||
MeasuringStrategy,
|
||||
} from "@dnd-kit/core"
|
||||
import {
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
sortableKeyboardCoordinates,
|
||||
verticalListSortingStrategy,
|
||||
useSortable,
|
||||
} from "@dnd-kit/sortable"
|
||||
import { CSS } from "@dnd-kit/utilities"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/shared/components/ui/collapsible"
|
||||
import { Trash2, GripVertical, ChevronDown, ChevronRight, Calculator } from "lucide-react"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import type { ExamNode } from "./selected-question-list"
|
||||
import type { Question } from "@/modules/questions/types"
|
||||
|
||||
// --- Types ---
|
||||
|
||||
type StructureEditorProps = {
|
||||
items: ExamNode[]
|
||||
onChange: (items: ExamNode[]) => void
|
||||
onScoreChange: (id: string, score: number) => void
|
||||
onGroupTitleChange: (id: string, title: string) => void
|
||||
onRemove: (id: string) => void
|
||||
onAddGroup: () => void
|
||||
}
|
||||
|
||||
// --- Components ---
|
||||
|
||||
function SortableItem({
|
||||
id,
|
||||
item,
|
||||
onRemove,
|
||||
onScoreChange
|
||||
}: {
|
||||
id: string
|
||||
item: ExamNode
|
||||
onRemove: () => void
|
||||
onScoreChange: (val: number) => void
|
||||
}) {
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
setNodeRef,
|
||||
transform,
|
||||
transition,
|
||||
isDragging,
|
||||
} = useSortable({ id })
|
||||
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0.5 : 1,
|
||||
}
|
||||
|
||||
const content = item.question?.content as { text?: string }
|
||||
|
||||
return (
|
||||
<div ref={setNodeRef} style={style} className={cn("group flex flex-col gap-3 rounded-md border p-3 bg-card hover:border-primary/50 transition-colors", isDragging && "ring-2 ring-primary")}>
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex gap-2 items-start flex-1">
|
||||
<button {...attributes} {...listeners} className="mt-1 cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground">
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</button>
|
||||
<p className="text-sm line-clamp-2 pt-0.5 select-none">
|
||||
{content?.text || "Question content"}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 text-muted-foreground hover:text-destructive shrink-0"
|
||||
onClick={onRemove}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end pl-8">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor={`score-${item.id}`} className="text-xs text-muted-foreground">
|
||||
Score
|
||||
</Label>
|
||||
<Input
|
||||
id={`score-${item.id}`}
|
||||
type="number"
|
||||
min={0}
|
||||
className="h-7 w-16 text-right"
|
||||
value={item.score}
|
||||
onChange={(e) => onScoreChange(parseInt(e.target.value) || 0)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SortableGroup({
|
||||
id,
|
||||
item,
|
||||
children,
|
||||
onRemove,
|
||||
onTitleChange
|
||||
}: {
|
||||
id: string
|
||||
item: ExamNode
|
||||
children: React.ReactNode
|
||||
onRemove: () => void
|
||||
onTitleChange: (val: string) => void
|
||||
}) {
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
setNodeRef,
|
||||
transform,
|
||||
transition,
|
||||
isDragging,
|
||||
} = useSortable({ id })
|
||||
|
||||
const [isOpen, setIsOpen] = useState(true)
|
||||
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0.5 : 1,
|
||||
}
|
||||
|
||||
const totalScore = useMemo(() => {
|
||||
const calc = (nodes: ExamNode[]): number => {
|
||||
return nodes.reduce((acc, node) => {
|
||||
if (node.type === 'question') return acc + (node.score || 0)
|
||||
if (node.type === 'group') return acc + calc(node.children || [])
|
||||
return acc
|
||||
}, 0)
|
||||
}
|
||||
return calc(item.children || [])
|
||||
}, [item])
|
||||
|
||||
return (
|
||||
<Collapsible open={isOpen} onOpenChange={setIsOpen} ref={setNodeRef} style={style} className={cn("rounded-lg border bg-muted/10 p-3 space-y-2", isDragging && "ring-2 ring-primary")}>
|
||||
<div className="flex items-center gap-3">
|
||||
<button {...attributes} {...listeners} className="cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground">
|
||||
<GripVertical className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="p-0 h-6 w-6 hover:bg-transparent">
|
||||
{isOpen ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<Input
|
||||
value={item.title || ""}
|
||||
onChange={(e) => onTitleChange(e.target.value)}
|
||||
placeholder="Section Title"
|
||||
className="font-semibold h-9 bg-transparent border-transparent hover:border-input focus:bg-background flex-1"
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-1 text-muted-foreground text-xs bg-background/50 px-2 py-1 rounded">
|
||||
<Calculator className="h-3 w-3" />
|
||||
<span>{totalScore} pts</span>
|
||||
</div>
|
||||
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-destructive" onClick={onRemove}>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<CollapsibleContent className="pl-4 border-l-2 border-muted space-y-3 min-h-[50px] animate-in slide-in-from-top-2 fade-in duration-200">
|
||||
{children}
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
)
|
||||
}
|
||||
|
||||
function StructureRenderer({ nodes, ...props }: {
|
||||
nodes: ExamNode[]
|
||||
onRemove: (id: string) => void
|
||||
onScoreChange: (id: string, score: number) => void
|
||||
onGroupTitleChange: (id: string, title: string) => void
|
||||
}) {
|
||||
return (
|
||||
<SortableContext items={nodes.map(n => n.id)} strategy={verticalListSortingStrategy}>
|
||||
{nodes.map(node => (
|
||||
<React.Fragment key={node.id}>
|
||||
{node.type === 'group' ? (
|
||||
<SortableGroup
|
||||
id={node.id}
|
||||
item={node}
|
||||
onRemove={() => props.onRemove(node.id)}
|
||||
onTitleChange={(val) => props.onGroupTitleChange(node.id, val)}
|
||||
>
|
||||
<StructureRenderer
|
||||
nodes={node.children || []}
|
||||
onRemove={props.onRemove}
|
||||
onScoreChange={props.onScoreChange}
|
||||
onGroupTitleChange={props.onGroupTitleChange}
|
||||
/>
|
||||
{(!node.children || node.children.length === 0) && (
|
||||
<div className="text-xs text-muted-foreground italic py-2 text-center border-2 border-dashed border-muted/50 rounded">
|
||||
Drag items here
|
||||
</div>
|
||||
)}
|
||||
</SortableGroup>
|
||||
) : (
|
||||
<SortableItem
|
||||
id={node.id}
|
||||
item={node}
|
||||
onRemove={() => props.onRemove(node.id)}
|
||||
onScoreChange={(val) => props.onScoreChange(node.id, val)}
|
||||
/>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</SortableContext>
|
||||
)
|
||||
}
|
||||
|
||||
// --- Main Component ---
|
||||
|
||||
const dropAnimation: DropAnimation = {
|
||||
sideEffects: defaultDropAnimationSideEffects({
|
||||
styles: {
|
||||
active: {
|
||||
opacity: '0.5',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
export function StructureEditor({ items, onChange, onScoreChange, onGroupTitleChange, onRemove, onAddGroup }: StructureEditorProps) {
|
||||
const [activeId, setActiveId] = useState<string | null>(null)
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
useSensor(KeyboardSensor, {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
})
|
||||
)
|
||||
|
||||
// Recursively find item
|
||||
const findItem = (id: string, nodes: ExamNode[] = items): ExamNode | null => {
|
||||
for (const node of nodes) {
|
||||
if (node.id === id) return node
|
||||
if (node.children) {
|
||||
const found = findItem(id, node.children)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const activeItem = activeId ? findItem(activeId) : null
|
||||
|
||||
// DND Handlers
|
||||
|
||||
function handleDragStart(event: DragStartEvent) {
|
||||
setActiveId(event.active.id as string)
|
||||
}
|
||||
|
||||
// Custom collision detection for nested sortables
|
||||
const customCollisionDetection: CollisionDetection = (args) => {
|
||||
// 1. First check pointer within for precise container detection
|
||||
const pointerCollisions = pointerWithin(args)
|
||||
|
||||
// If we have pointer collisions, prioritize the most specific one (usually the smallest/innermost container)
|
||||
if (pointerCollisions.length > 0) {
|
||||
return pointerCollisions
|
||||
}
|
||||
|
||||
// 2. Fallback to rect intersection for smoother sortable reordering when not directly over a container
|
||||
return rectIntersection(args)
|
||||
}
|
||||
|
||||
function handleDragOver(event: DragOverEvent) {
|
||||
const { active, over } = event
|
||||
if (!over) return
|
||||
|
||||
const activeId = active.id as string
|
||||
const overId = over.id as string
|
||||
|
||||
if (activeId === overId) return
|
||||
|
||||
// Find if we are moving over a Group container
|
||||
// "overId" could be a SortableItem (Question) OR a SortableGroup (Group)
|
||||
|
||||
const activeNode = findItem(activeId)
|
||||
const overNode = findItem(overId)
|
||||
|
||||
if (!activeNode || !overNode) return
|
||||
|
||||
// CRITICAL FIX: Prevent dragging a node onto its own descendant
|
||||
// This happens when dragging a group and hovering over its own children.
|
||||
// If we proceed, we would remove the group (and its children) and then fail to find the child to insert next to.
|
||||
const isDescendantOfActive = (childId: string): boolean => {
|
||||
const check = (node: ExamNode): boolean => {
|
||||
if (!node.children) return false
|
||||
return node.children.some(c => c.id === childId || check(c))
|
||||
}
|
||||
return check(activeNode)
|
||||
}
|
||||
|
||||
if (isDescendantOfActive(overId)) return
|
||||
|
||||
// Find which list the `over` item belongs to
|
||||
const findContainerId = (id: string, list: ExamNode[], parentId: string = 'root'): string | undefined => {
|
||||
if (list.some(i => i.id === id)) return parentId
|
||||
for (const node of list) {
|
||||
if (node.children) {
|
||||
const res = findContainerId(id, node.children, node.id)
|
||||
if (res) return res
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const activeContainerId = findContainerId(activeId, items)
|
||||
const overContainerId = findContainerId(overId, items)
|
||||
|
||||
// Scenario 1: Moving item into a Group by hovering over the Group itself
|
||||
// If overNode is a Group, we might want to move INTO it
|
||||
if (overNode.type === 'group') {
|
||||
// Logic: If active item is NOT in this group already
|
||||
// AND we are not trying to move a group into its own descendant (circular check)
|
||||
|
||||
const isDescendant = (parent: ExamNode, childId: string): boolean => {
|
||||
if (!parent.children) return false
|
||||
for (const c of parent.children) {
|
||||
if (c.id === childId) return true
|
||||
if (isDescendant(c, childId)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// If moving a group, check if overNode is a descendant of activeNode
|
||||
if (activeNode.type === 'group' && isDescendant(activeNode, overNode.id)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (activeContainerId !== overNode.id) {
|
||||
// ... implementation continues ...
|
||||
|
||||
const newItems = JSON.parse(JSON.stringify(items)) as ExamNode[]
|
||||
|
||||
// Remove active from old location
|
||||
const removeRecursive = (list: ExamNode[]): ExamNode | null => {
|
||||
const idx = list.findIndex(i => i.id === activeId)
|
||||
if (idx !== -1) return list.splice(idx, 1)[0]
|
||||
for (const node of list) {
|
||||
if (node.children) {
|
||||
const res = removeRecursive(node.children)
|
||||
if (res) return res
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const movedItem = removeRecursive(newItems)
|
||||
if (!movedItem) return
|
||||
|
||||
// Insert into new Group (overNode)
|
||||
// We need to find the overNode in the NEW structure (since we cloned it)
|
||||
const findGroupAndInsert = (list: ExamNode[]) => {
|
||||
for (const node of list) {
|
||||
if (node.id === overId) {
|
||||
if (!node.children) node.children = []
|
||||
node.children.push(movedItem)
|
||||
return true
|
||||
}
|
||||
if (node.children) {
|
||||
if (findGroupAndInsert(node.children)) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
findGroupAndInsert(newItems)
|
||||
onChange(newItems)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Scenario 2: Moving between different lists (e.g. from Root to Group A, or Group A to Group B)
|
||||
if (activeContainerId !== overContainerId) {
|
||||
// Standard Sortable Move
|
||||
const newItems = JSON.parse(JSON.stringify(items)) as ExamNode[]
|
||||
|
||||
const removeRecursive = (list: ExamNode[]): ExamNode | null => {
|
||||
const idx = list.findIndex(i => i.id === activeId)
|
||||
if (idx !== -1) return list.splice(idx, 1)[0]
|
||||
for (const node of list) {
|
||||
if (node.children) {
|
||||
const res = removeRecursive(node.children)
|
||||
if (res) return res
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const movedItem = removeRecursive(newItems)
|
||||
if (!movedItem) return
|
||||
|
||||
// Insert into destination list at specific index
|
||||
// We need to find the destination list array and the index of `overId`
|
||||
const insertRecursive = (list: ExamNode[]): boolean => {
|
||||
const idx = list.findIndex(i => i.id === overId)
|
||||
if (idx !== -1) {
|
||||
// Insert before or after based on direction?
|
||||
// Usually dnd-kit handles order if we are in same container, but cross-container we need to pick a spot.
|
||||
// We'll insert at the index of `overId`.
|
||||
|
||||
// However, if we insert AT the index, dnd-kit might get confused if we are dragging DOWN vs UP.
|
||||
// But since we are changing containers, just inserting at the target index is usually fine.
|
||||
// The issue "swapping positions is not smooth" might be because we insert *at* index, displacing the target.
|
||||
// Let's try to determine if we are "below" or "above" the target?
|
||||
// For cross-container, simpler is better. Inserting at index is standard.
|
||||
|
||||
list.splice(idx, 0, movedItem)
|
||||
return true
|
||||
}
|
||||
for (const node of list) {
|
||||
if (node.children) {
|
||||
if (insertRecursive(node.children)) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
insertRecursive(newItems)
|
||||
onChange(newItems)
|
||||
}
|
||||
}
|
||||
|
||||
function handleDragEnd(event: DragEndEvent) {
|
||||
const { active, over } = event
|
||||
setActiveId(null)
|
||||
|
||||
if (!over) return
|
||||
|
||||
const activeId = active.id as string
|
||||
const overId = over.id as string
|
||||
|
||||
if (activeId === overId) return
|
||||
|
||||
// Re-find positions in the potentially updated state
|
||||
// Note: Since we mutate in DragOver, the item might already be in the new container.
|
||||
// So activeContainerId might equal overContainerId now!
|
||||
|
||||
const findContainerId = (id: string, list: ExamNode[], parentId: string = 'root'): string | undefined => {
|
||||
if (list.some(i => i.id === id)) return parentId
|
||||
for (const node of list) {
|
||||
if (node.children) {
|
||||
const res = findContainerId(id, node.children, node.id)
|
||||
if (res) return res
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const activeContainerId = findContainerId(activeId, items)
|
||||
const overContainerId = findContainerId(overId, items)
|
||||
|
||||
if (activeContainerId === overContainerId) {
|
||||
// Same container reorder
|
||||
const newItems = JSON.parse(JSON.stringify(items)) as ExamNode[]
|
||||
|
||||
const getMutableList = (groupId?: string): ExamNode[] => {
|
||||
if (groupId === 'root') return newItems
|
||||
// Need recursive find
|
||||
const findGroup = (list: ExamNode[]): ExamNode | null => {
|
||||
for (const node of list) {
|
||||
if (node.id === groupId) return node
|
||||
if (node.children) {
|
||||
const res = findGroup(node.children)
|
||||
if (res) return res
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
return findGroup(newItems)?.children || []
|
||||
}
|
||||
|
||||
const list = getMutableList(activeContainerId)
|
||||
const oldIndex = list.findIndex(i => i.id === activeId)
|
||||
const newIndex = list.findIndex(i => i.id === overId)
|
||||
|
||||
if (oldIndex !== -1 && newIndex !== -1 && oldIndex !== newIndex) {
|
||||
const moved = arrayMove(list, oldIndex, newIndex)
|
||||
|
||||
// Update the list reference in parent
|
||||
if (activeContainerId === 'root') {
|
||||
onChange(moved)
|
||||
} else {
|
||||
// list is already a reference to children array if we did it right?
|
||||
// getMutableList returned `group.children`. Modifying `list` directly via arrayMove returns NEW array.
|
||||
// So we need to re-assign.
|
||||
const group = findItem(activeContainerId!, newItems)
|
||||
if (group) group.children = moved
|
||||
onChange(newItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={customCollisionDetection}
|
||||
onDragStart={handleDragStart}
|
||||
onDragOver={handleDragOver}
|
||||
onDragEnd={handleDragEnd}
|
||||
measuring={{ droppable: { strategy: MeasuringStrategy.Always } }}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<StructureRenderer
|
||||
nodes={items}
|
||||
onRemove={onRemove}
|
||||
onScoreChange={onScoreChange}
|
||||
onGroupTitleChange={onGroupTitleChange}
|
||||
/>
|
||||
|
||||
<div className="flex justify-center pt-2">
|
||||
<Button variant="outline" size="sm" onClick={onAddGroup} className="w-full border-dashed">
|
||||
+ Add Section
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DragOverlay dropAnimation={dropAnimation}>
|
||||
{activeItem ? (
|
||||
activeItem.type === 'group' ? (
|
||||
<div className="rounded-lg border bg-background p-4 shadow-lg opacity-80 w-[300px]">
|
||||
<div className="flex items-center gap-3">
|
||||
<GripVertical className="h-5 w-5" />
|
||||
<span className="font-semibold">{activeItem.title || "Section"}</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-md border bg-background p-3 shadow-lg opacity-80 w-[300px] flex items-center gap-3">
|
||||
<GripVertical className="h-4 w-4" />
|
||||
<p className="text-sm line-clamp-1">{(activeItem.question?.content as any)?.text || "Question"}</p>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</DragOverlay>
|
||||
</DndContext>
|
||||
)
|
||||
}
|
||||
170
src/modules/exams/components/exam-actions.tsx
Normal file
170
src/modules/exams/components/exam-actions.tsx
Normal file
@@ -0,0 +1,170 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { MoreHorizontal, Eye, Pencil, Trash, Archive, UploadCloud, Undo2, Copy } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/shared/components/ui/dropdown-menu"
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/shared/components/ui/alert-dialog"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/shared/components/ui/dialog"
|
||||
|
||||
import { Exam } from "../types"
|
||||
|
||||
interface ExamActionsProps {
|
||||
exam: Exam
|
||||
}
|
||||
|
||||
export function ExamActions({ exam }: ExamActionsProps) {
|
||||
const router = useRouter()
|
||||
const [showViewDialog, setShowViewDialog] = useState(false)
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
|
||||
const copyId = () => {
|
||||
navigator.clipboard.writeText(exam.id)
|
||||
toast.success("Exam ID copied to clipboard")
|
||||
}
|
||||
|
||||
const publishExam = async () => {
|
||||
toast.success("Exam published")
|
||||
}
|
||||
|
||||
const unpublishExam = async () => {
|
||||
toast.success("Exam moved to draft")
|
||||
}
|
||||
|
||||
const archiveExam = async () => {
|
||||
toast.success("Exam archived")
|
||||
}
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
await new Promise((r) => setTimeout(r, 800))
|
||||
toast.success("Exam deleted successfully")
|
||||
setShowDeleteDialog(false)
|
||||
} catch (e) {
|
||||
toast.error("Failed to delete exam")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem onClick={copyId}>
|
||||
<Copy className="mr-2 h-4 w-4" /> Copy ID
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => setShowViewDialog(true)}>
|
||||
<Eye className="mr-2 h-4 w-4" /> View
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<Pencil className="mr-2 h-4 w-4" /> Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => router.push(`/teacher/exams/${exam.id}/build`)}>
|
||||
<MoreHorizontal className="mr-2 h-4 w-4" /> Build
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={publishExam}>
|
||||
<UploadCloud className="mr-2 h-4 w-4" /> Publish
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={unpublishExam}>
|
||||
<Undo2 className="mr-2 h-4 w-4" /> Move to Draft
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={archiveExam}>
|
||||
<Archive className="mr-2 h-4 w-4" /> Archive
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
>
|
||||
<Trash className="mr-2 h-4 w-4" /> Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<Dialog open={showViewDialog} onOpenChange={setShowViewDialog}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Exam Details</DialogTitle>
|
||||
<DialogDescription>ID: {exam.id}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<span className="font-medium">Title:</span>
|
||||
<span className="col-span-3">{exam.title}</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<span className="font-medium">Subject:</span>
|
||||
<span className="col-span-3">{exam.subject}</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<span className="font-medium">Grade:</span>
|
||||
<span className="col-span-3">{exam.grade}</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<span className="font-medium">Total Score:</span>
|
||||
<span className="col-span-3">{exam.totalScore}</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<span className="font-medium">Duration:</span>
|
||||
<span className="col-span-3">{exam.durationMin} min</span>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete exam?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action cannot be undone. This will permanently delete the exam.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
handleDelete()
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
343
src/modules/exams/components/exam-assembly.tsx
Normal file
343
src/modules/exams/components/exam-assembly.tsx
Normal file
@@ -0,0 +1,343 @@
|
||||
"use client"
|
||||
|
||||
import { useMemo, useState } from "react"
|
||||
import { useFormStatus } from "react-dom"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { toast } from "sonner"
|
||||
import { Search } from "lucide-react"
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/shared/components/ui/select"
|
||||
import { ScrollArea } from "@/shared/components/ui/scroll-area"
|
||||
import { Separator } from "@/shared/components/ui/separator"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import type { Question } from "@/modules/questions/types"
|
||||
import { updateExamAction } from "@/modules/exams/actions"
|
||||
import { StructureEditor } from "./assembly/structure-editor"
|
||||
import { QuestionBankList } from "./assembly/question-bank-list"
|
||||
import type { ExamNode } from "./assembly/selected-question-list"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
|
||||
type ExamAssemblyProps = {
|
||||
examId: string
|
||||
title: string
|
||||
subject: string
|
||||
grade: string
|
||||
difficulty: number
|
||||
totalScore: number
|
||||
durationMin: number
|
||||
initialSelected?: Array<{ id: string; score: number }>
|
||||
initialStructure?: ExamNode[] // New prop
|
||||
questionOptions: Question[]
|
||||
}
|
||||
|
||||
function SubmitButton({ label }: { label: string }) {
|
||||
const { pending } = useFormStatus()
|
||||
return (
|
||||
<Button type="submit" disabled={pending} className="w-full">
|
||||
{pending ? "Saving..." : label}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export function ExamAssembly(props: ExamAssemblyProps) {
|
||||
const router = useRouter()
|
||||
const [search, setSearch] = useState("")
|
||||
const [typeFilter, setTypeFilter] = useState<string>("all")
|
||||
const [difficultyFilter, setDifficultyFilter] = useState<string>("all")
|
||||
|
||||
// Initialize structure state
|
||||
const [structure, setStructure] = useState<ExamNode[]>(() => {
|
||||
// Hydrate structure with full question objects
|
||||
const hydrate = (nodes: ExamNode[]): ExamNode[] => {
|
||||
return nodes.map(node => {
|
||||
if (node.type === 'question') {
|
||||
const q = props.questionOptions.find(opt => opt.id === node.questionId)
|
||||
return { ...node, question: q }
|
||||
}
|
||||
if (node.type === 'group') {
|
||||
return { ...node, children: hydrate(node.children || []) }
|
||||
}
|
||||
return node
|
||||
})
|
||||
}
|
||||
|
||||
// Use initialStructure if provided (Server generated or DB stored)
|
||||
if (props.initialStructure && props.initialStructure.length > 0) {
|
||||
return hydrate(props.initialStructure)
|
||||
}
|
||||
|
||||
// Fallback logic removed as Server Component handles initial migration
|
||||
return []
|
||||
})
|
||||
|
||||
const filteredQuestions = useMemo(() => {
|
||||
let list: Question[] = [...props.questionOptions]
|
||||
|
||||
if (search) {
|
||||
const lower = search.toLowerCase()
|
||||
list = list.filter(q => {
|
||||
const content = q.content as { text?: string }
|
||||
return content.text?.toLowerCase().includes(lower)
|
||||
})
|
||||
}
|
||||
|
||||
if (typeFilter !== "all") {
|
||||
list = list.filter((q) => q.type === (typeFilter as Question["type"]))
|
||||
}
|
||||
if (difficultyFilter !== "all") {
|
||||
const d = parseInt(difficultyFilter)
|
||||
list = list.filter((q) => q.difficulty === d)
|
||||
}
|
||||
return list
|
||||
}, [search, typeFilter, difficultyFilter, props.questionOptions])
|
||||
|
||||
// Recursively calculate total score
|
||||
const assignedTotal = useMemo(() => {
|
||||
const calc = (nodes: ExamNode[]): number => {
|
||||
return nodes.reduce((sum, node) => {
|
||||
if (node.type === 'question') return sum + (node.score || 0)
|
||||
if (node.type === 'group') return sum + calc(node.children || [])
|
||||
return sum
|
||||
}, 0)
|
||||
}
|
||||
return calc(structure)
|
||||
}, [structure])
|
||||
|
||||
const progress = Math.min(100, Math.max(0, (assignedTotal / props.totalScore) * 100))
|
||||
|
||||
const handleAdd = (question: Question) => {
|
||||
setStructure(prev => [
|
||||
...prev,
|
||||
{
|
||||
id: createId(),
|
||||
type: 'question',
|
||||
questionId: question.id,
|
||||
score: 10,
|
||||
question
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
const handleAddGroup = () => {
|
||||
setStructure(prev => [
|
||||
...prev,
|
||||
{
|
||||
id: createId(),
|
||||
type: 'group',
|
||||
title: 'New Section',
|
||||
children: []
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
const handleRemove = (id: string) => {
|
||||
const removeRecursive = (nodes: ExamNode[]): ExamNode[] => {
|
||||
return nodes.filter(n => n.id !== id).map(n => {
|
||||
if (n.type === 'group') {
|
||||
return { ...n, children: removeRecursive(n.children || []) }
|
||||
}
|
||||
return n
|
||||
})
|
||||
}
|
||||
setStructure(prev => removeRecursive(prev))
|
||||
}
|
||||
|
||||
const handleScoreChange = (id: string, score: number) => {
|
||||
const updateRecursive = (nodes: ExamNode[]): ExamNode[] => {
|
||||
return nodes.map(n => {
|
||||
if (n.id === id) return { ...n, score }
|
||||
if (n.type === 'group') return { ...n, children: updateRecursive(n.children || []) }
|
||||
return n
|
||||
})
|
||||
}
|
||||
setStructure(prev => updateRecursive(prev))
|
||||
}
|
||||
|
||||
const handleGroupTitleChange = (id: string, title: string) => {
|
||||
const updateRecursive = (nodes: ExamNode[]): ExamNode[] => {
|
||||
return nodes.map(n => {
|
||||
if (n.id === id) return { ...n, title }
|
||||
if (n.type === 'group') return { ...n, children: updateRecursive(n.children || []) }
|
||||
return n
|
||||
})
|
||||
}
|
||||
setStructure(prev => updateRecursive(prev))
|
||||
}
|
||||
|
||||
// Helper to extract flat list for DB examQuestions table
|
||||
const getFlatQuestions = () => {
|
||||
const list: Array<{ id: string; score: number }> = []
|
||||
const traverse = (nodes: ExamNode[]) => {
|
||||
nodes.forEach(n => {
|
||||
if (n.type === 'question' && n.questionId) {
|
||||
list.push({ id: n.questionId, score: n.score || 0 })
|
||||
}
|
||||
if (n.type === 'group') {
|
||||
traverse(n.children || [])
|
||||
}
|
||||
})
|
||||
}
|
||||
traverse(structure)
|
||||
return list
|
||||
}
|
||||
|
||||
// Helper to strip runtime question objects for DB structure storage
|
||||
const getCleanStructure = () => {
|
||||
const clean = (nodes: ExamNode[]): any[] => {
|
||||
return nodes.map(n => {
|
||||
const { question, ...rest } = n
|
||||
if (n.type === 'group') {
|
||||
return { ...rest, children: clean(n.children || []) }
|
||||
}
|
||||
return rest
|
||||
})
|
||||
}
|
||||
return clean(structure)
|
||||
}
|
||||
|
||||
const handleSave = async (formData: FormData) => {
|
||||
formData.set("examId", props.examId)
|
||||
formData.set("questionsJson", JSON.stringify(getFlatQuestions()))
|
||||
formData.set("structureJson", JSON.stringify(getCleanStructure()))
|
||||
|
||||
const result = await updateExamAction(null, formData)
|
||||
if (result.success) {
|
||||
toast.success("Saved draft")
|
||||
} else {
|
||||
toast.error(result.message || "Save failed")
|
||||
}
|
||||
}
|
||||
|
||||
const handlePublish = async (formData: FormData) => {
|
||||
formData.set("examId", props.examId)
|
||||
formData.set("questionsJson", JSON.stringify(getFlatQuestions()))
|
||||
formData.set("structureJson", JSON.stringify(getCleanStructure()))
|
||||
formData.set("status", "published")
|
||||
|
||||
const result = await updateExamAction(null, formData)
|
||||
if (result.success) {
|
||||
toast.success("Published exam")
|
||||
router.push("/teacher/exams/all")
|
||||
} else {
|
||||
toast.error(result.message || "Publish failed")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid h-[calc(100vh-12rem)] gap-6 lg:grid-cols-5">
|
||||
{/* Left: Preview (3 cols) */}
|
||||
<Card className="lg:col-span-3 flex flex-col overflow-hidden border-2 border-primary/10">
|
||||
<CardHeader className="bg-muted/30 pb-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle>Exam Structure</CardTitle>
|
||||
<div className="flex items-center gap-4 text-sm">
|
||||
<div className="flex flex-col items-end">
|
||||
<span className="font-medium">{assignedTotal} / {props.totalScore}</span>
|
||||
<span className="text-xs text-muted-foreground">Total Score</span>
|
||||
</div>
|
||||
<div className="h-2 w-24 rounded-full bg-secondary">
|
||||
<div
|
||||
className={`h-full rounded-full transition-all ${
|
||||
assignedTotal > props.totalScore ? "bg-destructive" : "bg-primary"
|
||||
}`}
|
||||
style={{ width: `${progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<ScrollArea className="flex-1 p-4">
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-3 gap-4 text-sm text-muted-foreground bg-muted/20 p-3 rounded-md">
|
||||
<div><span className="font-medium text-foreground">{props.subject}</span></div>
|
||||
<div><span className="font-medium text-foreground">{props.grade}</span></div>
|
||||
<div>Duration: <span className="font-medium text-foreground">{props.durationMin} min</span></div>
|
||||
</div>
|
||||
|
||||
<StructureEditor
|
||||
items={structure}
|
||||
onChange={setStructure}
|
||||
onScoreChange={handleScoreChange}
|
||||
onGroupTitleChange={handleGroupTitleChange}
|
||||
onRemove={handleRemove}
|
||||
onAddGroup={handleAddGroup}
|
||||
/>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<div className="border-t p-4 bg-muted/30 flex gap-3 justify-end">
|
||||
<form action={handleSave} className="flex-1">
|
||||
<SubmitButton label="Save Draft" />
|
||||
</form>
|
||||
<form action={handlePublish} className="flex-1">
|
||||
<SubmitButton label="Publish Exam" />
|
||||
</form>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Right: Question Bank (2 cols) */}
|
||||
<Card className="lg:col-span-2 flex flex-col overflow-hidden">
|
||||
<CardHeader className="pb-3 space-y-3">
|
||||
<CardTitle className="text-base">Question Bank</CardTitle>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search questions..."
|
||||
className="pl-8"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Select value={typeFilter} onValueChange={setTypeFilter}>
|
||||
<SelectTrigger className="flex-1 h-8 text-xs"><SelectValue placeholder="Type" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Types</SelectItem>
|
||||
<SelectItem value="single_choice">Single Choice</SelectItem>
|
||||
<SelectItem value="multiple_choice">Multiple Choice</SelectItem>
|
||||
<SelectItem value="judgment">True/False</SelectItem>
|
||||
<SelectItem value="text">Short Answer</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select value={difficultyFilter} onValueChange={setDifficultyFilter}>
|
||||
<SelectTrigger className="w-[80px] h-8 text-xs"><SelectValue placeholder="Diff" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
<SelectItem value="1">Lvl 1</SelectItem>
|
||||
<SelectItem value="2">Lvl 2</SelectItem>
|
||||
<SelectItem value="3">Lvl 3</SelectItem>
|
||||
<SelectItem value="4">Lvl 4</SelectItem>
|
||||
<SelectItem value="5">Lvl 5</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<Separator />
|
||||
|
||||
<ScrollArea className="flex-1 p-4 bg-muted/10">
|
||||
<QuestionBankList
|
||||
questions={filteredQuestions}
|
||||
onAdd={handleAdd}
|
||||
isAdded={(id) => {
|
||||
// Check if question is added anywhere in the structure
|
||||
const isAddedRecursive = (nodes: ExamNode[]): boolean => {
|
||||
return nodes.some(n => {
|
||||
if (n.type === 'question' && n.questionId === id) return true
|
||||
if (n.type === 'group' && n.children) return isAddedRecursive(n.children)
|
||||
return false
|
||||
})
|
||||
}
|
||||
return isAddedRecursive(structure)
|
||||
}}
|
||||
/>
|
||||
</ScrollArea>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
137
src/modules/exams/components/exam-columns.tsx
Normal file
137
src/modules/exams/components/exam-columns.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
"use client"
|
||||
|
||||
import { ColumnDef } from "@tanstack/react-table"
|
||||
import { Checkbox } from "@/shared/components/ui/checkbox"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { cn, formatDate } from "@/shared/lib/utils"
|
||||
import { Exam } from "../types"
|
||||
import { ExamActions } from "./exam-actions"
|
||||
|
||||
export const examColumns: ColumnDef<Exam>[] = [
|
||||
{
|
||||
id: "select",
|
||||
header: ({ table }) => (
|
||||
<Checkbox
|
||||
checked={table.getIsAllPageRowsSelected()}
|
||||
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
||||
aria-label="Select all"
|
||||
/>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||
aria-label="Select row"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
size: 36,
|
||||
},
|
||||
{
|
||||
accessorKey: "title",
|
||||
header: "Title",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">{row.original.title}</span>
|
||||
{row.original.tags && row.original.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{row.original.tags.slice(0, 2).map((t) => (
|
||||
<Badge key={t} variant="outline" className="text-xs">
|
||||
{t}
|
||||
</Badge>
|
||||
))}
|
||||
{row.original.tags.length > 2 && (
|
||||
<Badge variant="outline" className="text-xs">+{row.original.tags.length - 2}</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "subject",
|
||||
header: "Subject",
|
||||
},
|
||||
{
|
||||
accessorKey: "grade",
|
||||
header: "Grade",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs">{row.original.grade}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: "Status",
|
||||
cell: ({ row }) => {
|
||||
const status = row.original.status
|
||||
const variant = status === "published" ? "secondary" : status === "archived" ? "destructive" : "outline"
|
||||
return (
|
||||
<Badge variant={variant as any} className="capitalize">
|
||||
{status}
|
||||
</Badge>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "difficulty",
|
||||
header: "Difficulty",
|
||||
cell: ({ row }) => {
|
||||
const diff = row.original.difficulty
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
<span
|
||||
className={cn(
|
||||
"font-medium",
|
||||
diff <= 2 ? "text-green-600" : diff === 3 ? "text-yellow-600" : "text-red-600"
|
||||
)}
|
||||
>
|
||||
{diff === 1
|
||||
? "Easy"
|
||||
: diff === 2
|
||||
? "Easy-Med"
|
||||
: diff === 3
|
||||
? "Medium"
|
||||
: diff === 4
|
||||
? "Med-Hard"
|
||||
: "Hard"}
|
||||
</span>
|
||||
<span className="ml-1 text-xs text-muted-foreground">({diff})</span>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "durationMin",
|
||||
header: "Duration",
|
||||
cell: ({ row }) => <span className="text-muted-foreground text-xs">{row.original.durationMin} min</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "totalScore",
|
||||
header: "Total",
|
||||
cell: ({ row }) => <span className="text-muted-foreground text-xs">{row.original.totalScore}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "scheduledAt",
|
||||
header: "Scheduled",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">
|
||||
{row.original.scheduledAt ? formatDate(row.original.scheduledAt) : "-"}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "createdAt",
|
||||
header: "Created",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">
|
||||
{formatDate(row.original.createdAt)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => <ExamActions exam={row.original} />,
|
||||
},
|
||||
]
|
||||
|
||||
110
src/modules/exams/components/exam-data-table.tsx
Normal file
110
src/modules/exams/components/exam-data-table.tsx
Normal file
@@ -0,0 +1,110 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import {
|
||||
ColumnDef,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
getPaginationRowModel,
|
||||
SortingState,
|
||||
getSortedRowModel,
|
||||
getFilteredRowModel,
|
||||
RowSelectionState,
|
||||
} from "@tanstack/react-table"
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/shared/components/ui/table"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react"
|
||||
|
||||
interface DataTableProps<TData, TValue> {
|
||||
columns: ColumnDef<TData, TValue>[]
|
||||
data: TData[]
|
||||
}
|
||||
|
||||
export function ExamDataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>) {
|
||||
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||
const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({})
|
||||
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getPaginationRowModel: getPaginationRowModel(),
|
||||
onSortingChange: setSorting,
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
onRowSelectionChange: setRowSelection,
|
||||
getFilteredRowModel: getFilteredRowModel(),
|
||||
state: {
|
||||
sorting,
|
||||
rowSelection,
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(header.column.columnDef.header, header.getContext())}
|
||||
</TableHead>
|
||||
)
|
||||
})}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} data-state={row.getIsSelected() && "selected"}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||
No results.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
<div className="flex items-center justify-end space-x-2 py-4">
|
||||
<div className="flex-1 text-sm text-muted-foreground">
|
||||
{table.getFilteredSelectedRowModel().rows.length} of {table.getFilteredRowModel().rows.length} row(s)
|
||||
selected.
|
||||
</div>
|
||||
<div className="space-x-2">
|
||||
<Button variant="outline" size="sm" onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
Previous
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>
|
||||
Next
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
76
src/modules/exams/components/exam-filters.tsx
Normal file
76
src/modules/exams/components/exam-filters.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
"use client"
|
||||
|
||||
import { useQueryState, parseAsString } from "nuqs"
|
||||
import { Search, X } from "lucide-react"
|
||||
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/shared/components/ui/select"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
|
||||
export function ExamFilters() {
|
||||
const [search, setSearch] = useQueryState("q", parseAsString.withOptions({ shallow: false }))
|
||||
const [status, setStatus] = useQueryState("status", parseAsString.withOptions({ shallow: false }))
|
||||
const [difficulty, setDifficulty] = useQueryState("difficulty", parseAsString.withOptions({ shallow: false }))
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative w-full md:w-[260px]">
|
||||
<Search className="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search exams..."
|
||||
className="pl-7"
|
||||
value={search || ""}
|
||||
onChange={(e) => setSearch(e.target.value || null)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Select value={status || "all"} onValueChange={(val) => setStatus(val === "all" ? null : val)}>
|
||||
<SelectTrigger className="w-[160px]">
|
||||
<SelectValue placeholder="Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Any Status</SelectItem>
|
||||
<SelectItem value="draft">Draft</SelectItem>
|
||||
<SelectItem value="published">Published</SelectItem>
|
||||
<SelectItem value="archived">Archived</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select value={difficulty || "all"} onValueChange={(val) => setDifficulty(val === "all" ? null : val)}>
|
||||
<SelectTrigger className="w-[160px]">
|
||||
<SelectValue placeholder="Difficulty" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Any Difficulty</SelectItem>
|
||||
<SelectItem value="1">Easy (1)</SelectItem>
|
||||
<SelectItem value="2">Easy-Med (2)</SelectItem>
|
||||
<SelectItem value="3">Medium (3)</SelectItem>
|
||||
<SelectItem value="4">Med-Hard (4)</SelectItem>
|
||||
<SelectItem value="5">Hard (5)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{(search || (status && status !== "all") || (difficulty && difficulty !== "all")) && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setSearch(null)
|
||||
setStatus(null)
|
||||
setDifficulty(null)
|
||||
}}
|
||||
className="h-8 px-2 lg:px-3"
|
||||
>
|
||||
Reset
|
||||
<X className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
99
src/modules/exams/components/exam-form.tsx
Normal file
99
src/modules/exams/components/exam-form.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useFormStatus } from "react-dom"
|
||||
import { toast } from "sonner"
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/shared/components/ui/card"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/shared/components/ui/select"
|
||||
import { createExamAction } from "../actions"
|
||||
|
||||
function SubmitButton() {
|
||||
const { pending } = useFormStatus()
|
||||
return (
|
||||
<Button type="submit" disabled={pending}>
|
||||
{pending ? "Creating..." : "Create Exam"}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export function ExamForm() {
|
||||
const router = useRouter()
|
||||
const [difficulty, setDifficulty] = useState<string>("3")
|
||||
|
||||
const handleSubmit = async (formData: FormData) => {
|
||||
const result = await createExamAction(null, formData)
|
||||
if (result.success) {
|
||||
toast.success(result.message)
|
||||
if (result.data) {
|
||||
router.push(`/teacher/exams/${result.data}/build`)
|
||||
}
|
||||
} else {
|
||||
toast.error(result.message)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Exam Creator</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form action={handleSubmit} className="space-y-6">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="title">Title</Label>
|
||||
<Input id="title" name="title" placeholder="e.g. Algebra Midterm" required />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="subject">Subject</Label>
|
||||
<Input id="subject" name="subject" placeholder="e.g. Mathematics" required />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="grade">Grade</Label>
|
||||
<Input id="grade" name="grade" placeholder="e.g. Grade 10" required />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>Difficulty</Label>
|
||||
<Select value={difficulty} onValueChange={(val) => setDifficulty(val)} name="difficulty">
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select difficulty" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1">Easy (1)</SelectItem>
|
||||
<SelectItem value="2">Easy-Med (2)</SelectItem>
|
||||
<SelectItem value="3">Medium (3)</SelectItem>
|
||||
<SelectItem value="4">Med-Hard (4)</SelectItem>
|
||||
<SelectItem value="5">Hard (5)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input type="hidden" name="difficulty" value={difficulty} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="totalScore">Total Score</Label>
|
||||
<Input id="totalScore" name="totalScore" type="number" min={1} placeholder="e.g. 100" required />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="durationMin">Duration (min)</Label>
|
||||
<Input id="durationMin" name="durationMin" type="number" min={10} placeholder="e.g. 90" required />
|
||||
</div>
|
||||
<div className="grid gap-2 md:col-span-2">
|
||||
<Label htmlFor="scheduledAt">Scheduled At (optional)</Label>
|
||||
<Input id="scheduledAt" name="scheduledAt" type="datetime-local" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<CardFooter className="justify-end">
|
||||
<SubmitButton />
|
||||
</CardFooter>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
177
src/modules/exams/components/grading-view.tsx
Normal file
177
src/modules/exams/components/grading-view.tsx
Normal file
@@ -0,0 +1,177 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { toast } from "sonner"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { Textarea } from "@/shared/components/ui/textarea"
|
||||
import { ScrollArea } from "@/shared/components/ui/scroll-area"
|
||||
import { Separator } from "@/shared/components/ui/separator"
|
||||
import { gradeSubmissionAction } from "../actions"
|
||||
|
||||
type Answer = {
|
||||
id: string
|
||||
questionId: string
|
||||
questionContent: any
|
||||
questionType: string
|
||||
maxScore: number
|
||||
studentAnswer: any
|
||||
score: number | null
|
||||
feedback: string | null
|
||||
order: number
|
||||
}
|
||||
|
||||
type GradingViewProps = {
|
||||
submissionId: string
|
||||
studentName: string
|
||||
examTitle: string
|
||||
submittedAt: string | null
|
||||
status: string
|
||||
totalScore: number | null
|
||||
answers: Answer[]
|
||||
}
|
||||
|
||||
export function GradingView({
|
||||
submissionId,
|
||||
studentName,
|
||||
examTitle,
|
||||
submittedAt,
|
||||
status,
|
||||
totalScore,
|
||||
answers: initialAnswers
|
||||
}: GradingViewProps) {
|
||||
const router = useRouter()
|
||||
const [answers, setAnswers] = useState(initialAnswers)
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
|
||||
const handleScoreChange = (id: string, val: string) => {
|
||||
const score = val === "" ? 0 : parseInt(val)
|
||||
setAnswers(prev => prev.map(a => a.id === id ? { ...a, score } : a))
|
||||
}
|
||||
|
||||
const handleFeedbackChange = (id: string, val: string) => {
|
||||
setAnswers(prev => prev.map(a => a.id === id ? { ...a, feedback: val } : a))
|
||||
}
|
||||
|
||||
const currentTotal = answers.reduce((sum, a) => sum + (a.score || 0), 0)
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSubmitting(true)
|
||||
const payload = answers.map(a => ({
|
||||
id: a.id,
|
||||
score: a.score || 0,
|
||||
feedback: a.feedback
|
||||
}))
|
||||
|
||||
const formData = new FormData()
|
||||
formData.set("submissionId", submissionId)
|
||||
formData.set("answersJson", JSON.stringify(payload))
|
||||
|
||||
const result = await gradeSubmissionAction(null, formData)
|
||||
|
||||
if (result.success) {
|
||||
toast.success("Grading saved")
|
||||
router.push("/teacher/exams/grading")
|
||||
} else {
|
||||
toast.error(result.message || "Failed to save")
|
||||
}
|
||||
setIsSubmitting(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid h-[calc(100vh-8rem)] grid-cols-1 gap-6 lg:grid-cols-3">
|
||||
{/* Left: Questions & Answers */}
|
||||
<div className="lg:col-span-2 flex flex-col h-full overflow-hidden rounded-md border bg-card">
|
||||
<div className="border-b p-4">
|
||||
<h3 className="font-semibold">Student Response</h3>
|
||||
</div>
|
||||
<ScrollArea className="flex-1 p-4">
|
||||
<div className="space-y-8">
|
||||
{answers.map((ans, index) => (
|
||||
<div key={ans.id} className="space-y-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="space-y-1">
|
||||
<span className="text-sm font-medium text-muted-foreground">Question {index + 1}</span>
|
||||
<div className="text-sm">{ans.questionContent?.text}</div>
|
||||
{/* Render options if multiple choice, etc. - Simplified for now */}
|
||||
</div>
|
||||
<Badge variant="outline">Max: {ans.maxScore}</Badge>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md bg-muted/50 p-4">
|
||||
<Label className="mb-2 block text-xs text-muted-foreground">Student Answer</Label>
|
||||
<p className="text-sm font-medium">
|
||||
{typeof ans.studentAnswer?.answer === 'string'
|
||||
? ans.studentAnswer.answer
|
||||
: JSON.stringify(ans.studentAnswer)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
{/* Right: Grading Panel */}
|
||||
<div className="flex flex-col h-full overflow-hidden rounded-md border bg-card">
|
||||
<div className="border-b p-4">
|
||||
<h3 className="font-semibold">Grading</h3>
|
||||
<div className="mt-2 flex items-center justify-between text-sm">
|
||||
<span className="text-muted-foreground">Total Score</span>
|
||||
<span className="font-bold text-lg text-primary">{currentTotal}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="flex-1 p-4">
|
||||
<div className="space-y-6">
|
||||
{answers.map((ans, index) => (
|
||||
<Card key={ans.id} className="border-l-4 border-l-primary/20">
|
||||
<CardHeader className="py-3 px-4">
|
||||
<CardTitle className="text-sm font-medium flex justify-between">
|
||||
Q{index + 1}
|
||||
<span className="text-xs text-muted-foreground">Max: {ans.maxScore}</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="py-3 px-4 space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`score-${ans.id}`}>Score</Label>
|
||||
<Input
|
||||
id={`score-${ans.id}`}
|
||||
type="number"
|
||||
min={0}
|
||||
max={ans.maxScore}
|
||||
value={ans.score ?? ""}
|
||||
onChange={(e) => handleScoreChange(ans.id, e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`fb-${ans.id}`}>Feedback</Label>
|
||||
<Textarea
|
||||
id={`fb-${ans.id}`}
|
||||
placeholder="Optional feedback..."
|
||||
className="min-h-[60px] resize-none"
|
||||
value={ans.feedback ?? ""}
|
||||
onChange={(e) => handleFeedbackChange(ans.id, e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<div className="border-t p-4 bg-muted/20">
|
||||
<Button className="w-full" onClick={handleSubmit} disabled={isSubmitting}>
|
||||
{isSubmitting ? "Saving..." : "Submit Grades"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
63
src/modules/exams/components/submission-columns.tsx
Normal file
63
src/modules/exams/components/submission-columns.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
"use client"
|
||||
|
||||
import { ColumnDef } from "@tanstack/react-table"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Eye, CheckSquare } from "lucide-react"
|
||||
import { ExamSubmission } from "../types"
|
||||
import Link from "next/link"
|
||||
import { formatDate } from "@/shared/lib/utils"
|
||||
|
||||
export const submissionColumns: ColumnDef<ExamSubmission>[] = [
|
||||
{
|
||||
accessorKey: "studentName",
|
||||
header: "Student",
|
||||
},
|
||||
{
|
||||
accessorKey: "examTitle",
|
||||
header: "Exam",
|
||||
},
|
||||
{
|
||||
accessorKey: "submittedAt",
|
||||
header: "Submitted",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">
|
||||
{formatDate(row.original.submittedAt)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: "Status",
|
||||
cell: ({ row }) => {
|
||||
const status = row.original.status
|
||||
const variant = status === "graded" ? "secondary" : "outline"
|
||||
return <Badge variant={variant as any} className="capitalize">{status}</Badge>
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "score",
|
||||
header: "Score",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs">{row.original.score ?? "-"}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="ghost" size="sm" asChild>
|
||||
<Link href={`/teacher/exams/grading/${row.original.id}`}>
|
||||
<Eye className="h-4 w-4 mr-1" /> View
|
||||
</Link>
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link href={`/teacher/exams/grading/${row.original.id}`}>
|
||||
<CheckSquare className="h-4 w-4 mr-1" /> Grade
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
94
src/modules/exams/components/submission-data-table.tsx
Normal file
94
src/modules/exams/components/submission-data-table.tsx
Normal file
@@ -0,0 +1,94 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import {
|
||||
ColumnDef,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
getPaginationRowModel,
|
||||
SortingState,
|
||||
getSortedRowModel,
|
||||
} from "@tanstack/react-table"
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/shared/components/ui/table"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react"
|
||||
|
||||
interface DataTableProps<TData, TValue> {
|
||||
columns: ColumnDef<TData, TValue>[]
|
||||
data: TData[]
|
||||
}
|
||||
|
||||
export function SubmissionDataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>) {
|
||||
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getPaginationRowModel: getPaginationRowModel(),
|
||||
onSortingChange: setSorting,
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
state: {
|
||||
sorting,
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} className="group">
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||
No submissions.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
<div className="flex items-center justify-end space-x-2 py-4">
|
||||
<div className="space-x-2">
|
||||
<Button variant="outline" size="sm" onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
Previous
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>
|
||||
Next
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
182
src/modules/exams/data-access.ts
Normal file
182
src/modules/exams/data-access.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
import { db } from "@/shared/db"
|
||||
import { exams, examQuestions, examSubmissions, submissionAnswers, users } from "@/shared/db/schema"
|
||||
import { eq, desc, like, and, or } from "drizzle-orm"
|
||||
import { cache } from "react"
|
||||
|
||||
import type { ExamStatus } from "./types"
|
||||
|
||||
export type GetExamsParams = {
|
||||
q?: string
|
||||
status?: string
|
||||
difficulty?: string
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
|
||||
export const getExams = cache(async (params: GetExamsParams) => {
|
||||
const conditions = []
|
||||
|
||||
if (params.q) {
|
||||
const search = `%${params.q}%`
|
||||
conditions.push(or(like(exams.title, search), like(exams.description, search)))
|
||||
}
|
||||
|
||||
if (params.status && params.status !== "all") {
|
||||
conditions.push(eq(exams.status, params.status as any))
|
||||
}
|
||||
|
||||
// Note: Difficulty is stored in JSON description field in current schema,
|
||||
// so we might need to filter in memory or adjust schema.
|
||||
// For now, let's fetch and filter in memory if difficulty is needed,
|
||||
// or just ignore strict DB filtering for JSON fields to keep it simple.
|
||||
|
||||
const data = await db.query.exams.findMany({
|
||||
where: conditions.length ? and(...conditions) : undefined,
|
||||
orderBy: [desc(exams.createdAt)],
|
||||
})
|
||||
|
||||
// Transform and Filter (especially for JSON fields)
|
||||
let result = data.map((exam) => {
|
||||
let meta: any = {}
|
||||
try {
|
||||
meta = JSON.parse(exam.description || "{}")
|
||||
} catch { }
|
||||
|
||||
return {
|
||||
id: exam.id,
|
||||
title: exam.title,
|
||||
status: (exam.status as ExamStatus) || "draft",
|
||||
subject: meta.subject || "General",
|
||||
grade: meta.grade || "General",
|
||||
difficulty: meta.difficulty || 1,
|
||||
totalScore: meta.totalScore || 100,
|
||||
durationMin: meta.durationMin || 60,
|
||||
questionCount: meta.questionCount || 0,
|
||||
scheduledAt: exam.startTime?.toISOString(),
|
||||
createdAt: exam.createdAt.toISOString(),
|
||||
tags: meta.tags || [],
|
||||
}
|
||||
})
|
||||
|
||||
if (params.difficulty && params.difficulty !== "all") {
|
||||
const d = parseInt(params.difficulty)
|
||||
result = result.filter((e) => e.difficulty === d)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
export const getExamById = cache(async (id: string) => {
|
||||
const exam = await db.query.exams.findFirst({
|
||||
where: eq(exams.id, id),
|
||||
with: {
|
||||
questions: {
|
||||
orderBy: (examQuestions, { asc }) => [asc(examQuestions.order)],
|
||||
with: {
|
||||
question: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!exam) return null
|
||||
|
||||
let meta: any = {}
|
||||
try {
|
||||
meta = JSON.parse(exam.description || "{}")
|
||||
} catch { }
|
||||
|
||||
return {
|
||||
id: exam.id,
|
||||
title: exam.title,
|
||||
status: (exam.status as ExamStatus) || "draft",
|
||||
subject: meta.subject || "General",
|
||||
grade: meta.grade || "General",
|
||||
difficulty: meta.difficulty || 1,
|
||||
totalScore: meta.totalScore || 100,
|
||||
durationMin: meta.durationMin || 60,
|
||||
scheduledAt: exam.startTime?.toISOString(),
|
||||
createdAt: exam.createdAt.toISOString(),
|
||||
tags: meta.tags || [],
|
||||
structure: exam.structure as any, // Return structure
|
||||
questions: exam.questions.map(eq => ({
|
||||
id: eq.questionId,
|
||||
score: eq.score,
|
||||
order: eq.order,
|
||||
// ... include question details if needed
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
export const getExamSubmissions = cache(async () => {
|
||||
const data = await db.query.examSubmissions.findMany({
|
||||
orderBy: [desc(examSubmissions.submittedAt)],
|
||||
with: {
|
||||
exam: true,
|
||||
student: true
|
||||
}
|
||||
})
|
||||
|
||||
return data.map(sub => ({
|
||||
id: sub.id,
|
||||
examId: sub.examId,
|
||||
examTitle: sub.exam.title,
|
||||
studentName: sub.student.name || "Unknown",
|
||||
submittedAt: sub.submittedAt ? sub.submittedAt.toISOString() : new Date().toISOString(),
|
||||
score: sub.score || undefined,
|
||||
status: sub.status as "pending" | "graded",
|
||||
}))
|
||||
})
|
||||
|
||||
export const getSubmissionDetails = cache(async (submissionId: string) => {
|
||||
const submission = await db.query.examSubmissions.findFirst({
|
||||
where: eq(examSubmissions.id, submissionId),
|
||||
with: {
|
||||
student: true,
|
||||
exam: true,
|
||||
}
|
||||
})
|
||||
|
||||
if (!submission) return null
|
||||
|
||||
// Fetch answers
|
||||
const answers = await db.query.submissionAnswers.findMany({
|
||||
where: eq(submissionAnswers.submissionId, submissionId),
|
||||
with: {
|
||||
question: true
|
||||
}
|
||||
})
|
||||
|
||||
// Fetch exam questions structure (to know max score and order)
|
||||
const examQ = await db.query.examQuestions.findMany({
|
||||
where: eq(examQuestions.examId, submission.examId),
|
||||
orderBy: [desc(examQuestions.order)],
|
||||
})
|
||||
|
||||
// Map answers with question details
|
||||
const answersWithDetails = answers.map(ans => {
|
||||
const eqRel = examQ.find(q => q.questionId === ans.questionId)
|
||||
return {
|
||||
id: ans.id,
|
||||
questionId: ans.questionId,
|
||||
questionContent: ans.question.content,
|
||||
questionType: ans.question.type,
|
||||
maxScore: eqRel?.score || 0,
|
||||
studentAnswer: ans.answerContent,
|
||||
score: ans.score,
|
||||
feedback: ans.feedback,
|
||||
order: eqRel?.order || 0
|
||||
}
|
||||
}).sort((a, b) => a.order - b.order)
|
||||
|
||||
return {
|
||||
id: submission.id,
|
||||
studentName: submission.student.name || "Unknown",
|
||||
examTitle: submission.exam.title,
|
||||
submittedAt: submission.submittedAt ? submission.submittedAt.toISOString() : null,
|
||||
status: submission.status,
|
||||
totalScore: submission.score,
|
||||
answers: answersWithDetails
|
||||
}
|
||||
})
|
||||
102
src/modules/exams/mock-data.ts
Normal file
102
src/modules/exams/mock-data.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { Exam, ExamSubmission } from "./types"
|
||||
|
||||
export let MOCK_EXAMS: Exam[] = [
|
||||
{
|
||||
id: "exam_001",
|
||||
title: "Algebra Midterm",
|
||||
subject: "Mathematics",
|
||||
grade: "Grade 10",
|
||||
status: "draft",
|
||||
difficulty: 3,
|
||||
totalScore: 100,
|
||||
durationMin: 90,
|
||||
questionCount: 25,
|
||||
scheduledAt: undefined,
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: ["Algebra", "Functions"],
|
||||
},
|
||||
{
|
||||
id: "exam_002",
|
||||
title: "Physics Mechanics Quiz",
|
||||
subject: "Physics",
|
||||
grade: "Grade 11",
|
||||
status: "published",
|
||||
difficulty: 4,
|
||||
totalScore: 50,
|
||||
durationMin: 45,
|
||||
questionCount: 15,
|
||||
scheduledAt: new Date(Date.now() + 86400000).toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: ["Mechanics", "Kinematics"],
|
||||
},
|
||||
{
|
||||
id: "exam_003",
|
||||
title: "English Reading Comprehension",
|
||||
subject: "English",
|
||||
grade: "Grade 12",
|
||||
status: "published",
|
||||
difficulty: 2,
|
||||
totalScore: 80,
|
||||
durationMin: 60,
|
||||
questionCount: 20,
|
||||
scheduledAt: new Date(Date.now() + 2 * 86400000).toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: ["Reading", "Vocabulary"],
|
||||
},
|
||||
{
|
||||
id: "exam_004",
|
||||
title: "Chemistry Final",
|
||||
subject: "Chemistry",
|
||||
grade: "Grade 12",
|
||||
status: "archived",
|
||||
difficulty: 5,
|
||||
totalScore: 120,
|
||||
durationMin: 120,
|
||||
questionCount: 40,
|
||||
scheduledAt: new Date(Date.now() - 30 * 86400000).toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: ["Organic", "Inorganic"],
|
||||
},
|
||||
{
|
||||
id: "exam_005",
|
||||
title: "Geometry Chapter Test",
|
||||
subject: "Mathematics",
|
||||
grade: "Grade 9",
|
||||
status: "published",
|
||||
difficulty: 3,
|
||||
totalScore: 60,
|
||||
durationMin: 50,
|
||||
questionCount: 18,
|
||||
scheduledAt: new Date(Date.now() + 3 * 86400000).toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: ["Geometry", "Triangles"],
|
||||
},
|
||||
]
|
||||
|
||||
export const MOCK_SUBMISSIONS: ExamSubmission[] = [
|
||||
{
|
||||
id: "sub_001",
|
||||
examId: "exam_002",
|
||||
examTitle: "Physics Mechanics Quiz",
|
||||
studentName: "Alice Zhang",
|
||||
submittedAt: new Date().toISOString(),
|
||||
status: "pending",
|
||||
},
|
||||
{
|
||||
id: "sub_002",
|
||||
examId: "exam_003",
|
||||
examTitle: "English Reading Comprehension",
|
||||
studentName: "Bob Li",
|
||||
submittedAt: new Date().toISOString(),
|
||||
score: 72,
|
||||
status: "graded",
|
||||
},
|
||||
]
|
||||
|
||||
export function addMockExam(exam: Exam) {
|
||||
MOCK_EXAMS = [exam, ...MOCK_EXAMS]
|
||||
}
|
||||
|
||||
export function updateMockExam(id: string, updates: Partial<Exam>) {
|
||||
MOCK_EXAMS = MOCK_EXAMS.map((e) => (e.id === id ? { ...e, ...updates } : e))
|
||||
}
|
||||
32
src/modules/exams/types.ts
Normal file
32
src/modules/exams/types.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export type ExamStatus = "draft" | "published" | "archived"
|
||||
|
||||
export type ExamDifficulty = 1 | 2 | 3 | 4 | 5
|
||||
|
||||
export interface Exam {
|
||||
id: string
|
||||
title: string
|
||||