new-action
Scaffold a new Server Action with auth, Zod validation, Prisma mutation, revalidation, and ActionResult types
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Scaffold a new Server Action with auth, Zod validation, Prisma mutation, revalidation, and ActionResult types
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Create a Prisma database migration: edit schema, run migrate dev, generate client, and verify types
Generate Vitest tests for a server action or component, following project conventions with Prisma mocks
Scaffold a new MUI component with Digital Playbook theme, proper client/server boundary, and project conventions
| name | new-action |
| description | Scaffold a new Server Action with auth, Zod validation, Prisma mutation, revalidation, and ActionResult types |
| disable-model-invocation | true |
Scaffolds a Server Action following the project's established pattern.
Accepts a name and optional description (e.g., /new-action updatePlayerStatus "Update a player's active/inactive status").
lib/actions/<name>.ts (or add to an existing file if it fits)prisma/schema.prisma to understand the relevant models and relationslib/utils/validation.ts for existing Zod schemas to reuselib/utils/validation.ts with proper constraintsbun run type-check to verify"use server";
import { z } from "zod";
import { prisma } from "@/lib/db/prisma";
import { requireUserId, requireTeamAdmin } from "@/lib/auth/session";
import { revalidatePath } from "next/cache";
export type ActionResult<T> =
| { success: true; data: T }
| { success: false; error: string; details?: unknown };
// Import or define Zod schema from lib/utils/validation.ts
const inputSchema = z.object({
// Define fields with proper constraints
});
export async function actionName(
input: z.infer<typeof inputSchema>
): Promise<ActionResult<ReturnType>> {
try {
// 1. Authenticate
const userId = await requireUserId();
// 2. Validate input
const validated = inputSchema.parse(input);
// 3. Authorize (check team/league role as needed)
await requireTeamAdmin(validated.teamId);
// 4. Perform mutation
const result = await prisma.model.create({
data: { ...validated },
});
// 5. Revalidate affected paths
revalidatePath("/affected-path");
return { success: true, data: result };
} catch (error) {
if (error instanceof z.ZodError) {
return { success: false, error: "Invalid input", details: error.flatten() };
}
return { success: false, error: "An unexpected error occurred" };
}
}
requireUserId() as the first operationrevalidatePath() after mutations