feat: 新增备课模块并修复全模块 P0/P1/P2 缺陷
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
主要变更: - 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布 - 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item) - 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验 - 新增 teacher/lesson-plans 页面 (列表/新建/编辑) - 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot - 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts - 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false) - 重构多模块 data-access/actions/组件, 修复权限校验与类型规范 - 同步架构文档 004/005 反映新增模块、导出、依赖关系 - 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { requirePermission, PermissionDeniedError } from "@/shared/lib/auth-guard";
|
||||
import { Permissions } from "@/shared/types/permissions";
|
||||
import type { ActionState } from "@/shared/types/action-state";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import {
|
||||
createTextbook,
|
||||
@@ -15,15 +16,20 @@ import {
|
||||
deleteTextbook,
|
||||
reorderChapters
|
||||
} from "./data-access";
|
||||
import type { CreateTextbookInput, UpdateTextbookInput } from "./types";
|
||||
import {
|
||||
CreateTextbookSchema,
|
||||
UpdateTextbookSchema,
|
||||
CreateChapterSchema,
|
||||
UpdateChapterContentSchema,
|
||||
CreateKnowledgePointSchema,
|
||||
UpdateKnowledgePointSchema,
|
||||
} from "./schema";
|
||||
|
||||
const getStringValue = (formData: FormData, key: string): string => {
|
||||
const value = formData.get(key)
|
||||
return typeof value === "string" ? value : ""
|
||||
}
|
||||
|
||||
// ... existing code ...
|
||||
|
||||
export async function reorderChaptersAction(
|
||||
chapterId: string,
|
||||
newIndex: number,
|
||||
@@ -43,36 +49,28 @@ export async function reorderChaptersAction(
|
||||
}
|
||||
}
|
||||
|
||||
export type ActionState = {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
errors?: Record<string, string[]>;
|
||||
};
|
||||
|
||||
// ... existing createTextbookAction ...
|
||||
|
||||
export async function createTextbookAction(
|
||||
prevState: ActionState | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState> {
|
||||
// ... implementation same as before
|
||||
const rawData: CreateTextbookInput = {
|
||||
const parsed = CreateTextbookSchema.safeParse({
|
||||
title: getStringValue(formData, "title"),
|
||||
subject: getStringValue(formData, "subject"),
|
||||
grade: getStringValue(formData, "grade"),
|
||||
publisher: getStringValue(formData, "publisher"),
|
||||
};
|
||||
});
|
||||
|
||||
if (!rawData.title || !rawData.subject || !rawData.grade) {
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Please fill in all required fields.",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_CREATE);
|
||||
await createTextbook(rawData);
|
||||
await createTextbook(parsed.data);
|
||||
revalidatePath("/teacher/textbooks");
|
||||
return {
|
||||
success: true,
|
||||
@@ -94,24 +92,25 @@ export async function updateTextbookAction(
|
||||
prevState: ActionState | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState> {
|
||||
const rawData: UpdateTextbookInput = {
|
||||
const parsed = UpdateTextbookSchema.safeParse({
|
||||
id: textbookId,
|
||||
title: getStringValue(formData, "title"),
|
||||
subject: getStringValue(formData, "subject"),
|
||||
grade: getStringValue(formData, "grade"),
|
||||
publisher: getStringValue(formData, "publisher"),
|
||||
};
|
||||
});
|
||||
|
||||
if (!rawData.title || !rawData.subject || !rawData.grade) {
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Please fill in all required fields.",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_UPDATE);
|
||||
await updateTextbook(rawData);
|
||||
await updateTextbook(parsed.data);
|
||||
revalidatePath(`/teacher/textbooks/${textbookId}`);
|
||||
return {
|
||||
success: true,
|
||||
@@ -153,21 +152,27 @@ export async function deleteTextbookAction(
|
||||
export async function createChapterAction(
|
||||
textbookId: string,
|
||||
parentId: string | undefined,
|
||||
prevState: ActionState | null,
|
||||
prevState: ActionState | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState> {
|
||||
const title = getStringValue(formData, "title");
|
||||
|
||||
if (!title) return { success: false, message: "Title is required" };
|
||||
const parsed = CreateChapterSchema.safeParse({
|
||||
textbookId,
|
||||
title: getStringValue(formData, "title"),
|
||||
parentId,
|
||||
order: 0,
|
||||
});
|
||||
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Title is required",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_CREATE);
|
||||
await createChapter({
|
||||
textbookId,
|
||||
title,
|
||||
parentId,
|
||||
order: 0 // Default order
|
||||
});
|
||||
await createChapter(parsed.data);
|
||||
revalidatePath(`/teacher/textbooks/${textbookId}`);
|
||||
return { success: true, message: "Chapter created successfully" };
|
||||
} catch (e) {
|
||||
@@ -183,9 +188,22 @@ export async function updateChapterContentAction(
|
||||
content: string,
|
||||
textbookId: string
|
||||
): Promise<ActionState> {
|
||||
const parsed = UpdateChapterContentSchema.safeParse({
|
||||
chapterId,
|
||||
content,
|
||||
});
|
||||
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Invalid chapter content data",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_UPDATE);
|
||||
await updateChapterContent({ chapterId, content });
|
||||
await updateChapterContent(parsed.data);
|
||||
revalidatePath(`/teacher/textbooks/${textbookId}`);
|
||||
return { success: true, message: "Content updated successfully" };
|
||||
} catch (e) {
|
||||
@@ -219,15 +237,24 @@ export async function createKnowledgePointAction(
|
||||
prevState: ActionState | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState> {
|
||||
const name = getStringValue(formData, "name");
|
||||
const description = getStringValue(formData, "description");
|
||||
const anchorText = getStringValue(formData, "anchorText");
|
||||
const parsed = CreateKnowledgePointSchema.safeParse({
|
||||
name: getStringValue(formData, "name"),
|
||||
description: getStringValue(formData, "description") || undefined,
|
||||
anchorText: getStringValue(formData, "anchorText") || undefined,
|
||||
chapterId,
|
||||
});
|
||||
|
||||
if (!name) return { success: false, message: "Name is required" };
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Name is required",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_CREATE);
|
||||
await createKnowledgePoint({ name, description, anchorText, chapterId });
|
||||
await createKnowledgePoint(parsed.data);
|
||||
revalidatePath(`/teacher/textbooks/${textbookId}`);
|
||||
return { success: true, message: "Knowledge point created successfully" };
|
||||
} catch (e) {
|
||||
@@ -261,15 +288,24 @@ export async function updateKnowledgePointAction(
|
||||
prevState: ActionState | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState> {
|
||||
const name = getStringValue(formData, "name");
|
||||
const description = getStringValue(formData, "description");
|
||||
const anchorText = getStringValue(formData, "anchorText");
|
||||
const parsed = UpdateKnowledgePointSchema.safeParse({
|
||||
id: kpId,
|
||||
name: getStringValue(formData, "name"),
|
||||
description: getStringValue(formData, "description") || undefined,
|
||||
anchorText: getStringValue(formData, "anchorText") || undefined,
|
||||
});
|
||||
|
||||
if (!name) return { success: false, message: "Name is required" };
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Name is required",
|
||||
errors: parsed.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await requirePermission(Permissions.TEXTBOOK_UPDATE);
|
||||
await updateKnowledgePoint({ id: kpId, name, description, anchorText });
|
||||
await updateKnowledgePoint(parsed.data);
|
||||
revalidatePath(`/teacher/textbooks/${textbookId}`);
|
||||
return { success: true, message: "Knowledge point updated successfully" };
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user