Enhance Next.js configuration and dependencies for improved functionality and localization support. Added support for internationalization with next-intl, updated global styles, and integrated new fonts. Removed default home page and updated README with project details and setup instructions.
This commit is contained in:
1 parent
2911dea00b
commit
44f4fa98e2
320 files changed
+31666
-220
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { registrationStatusSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { parseJsonBody } from "@/lib/api/crud";
|
||||
import type { RegistrationLeadRow } from "@/app/api/admin/registrations/route";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// PATCH /api/admin/registrations/[id] — change lead status (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = registrationStatusSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await query<RegistrationLeadRow>(
|
||||
`UPDATE registration_leads SET status = $1 WHERE id = $2 RETURNING *`,
|
||||
[parsed.data.status, id],
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("لید ثبتنام یافت نشد", 404);
|
||||
return NextResponse.json({ ok: true, data: res.rows[0] });
|
||||
} catch (err) {
|
||||
console.error("admin update registration error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/registrations/[id] — delete a lead (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(
|
||||
`DELETE FROM registration_leads WHERE id = $1 RETURNING id`,
|
||||
[id],
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("لید ثبتنام یافت نشد", 404);
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete registration error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { listAdminRegistrations } from "@/lib/data/admin/registrations";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export interface RegistrationLeadRow {
|
||||
id: string;
|
||||
course_id: string | null;
|
||||
course_slug: string | null;
|
||||
full_name: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
message: string | null;
|
||||
source: string;
|
||||
status: "new" | "contacted" | "enrolled" | "rejected";
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
// GET /api/admin/registrations — list registration leads (admin only)
|
||||
// Query: ?search=<text>&status=new|contacted|enrolled|rejected
|
||||
export async function GET(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
try {
|
||||
const { searchParams } = request.nextUrl;
|
||||
const data = await listAdminRegistrations({
|
||||
search: searchParams.get("search") ?? undefined,
|
||||
status: searchParams.get("status") ?? undefined,
|
||||
});
|
||||
return NextResponse.json({ ok: true, data });
|
||||
} catch (err) {
|
||||
console.error("admin list registrations error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user