Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
31 changes: 31 additions & 0 deletions src/app/api/auth/forgot-password/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { NextResponse } from 'next/server';
import { getUserByEmail } from '@/lib/db/queries';

export async function POST(request: Request) {
try {
const body = await request.json();
const email = String(body?.email || '').trim().toLowerCase();

if (!email) {
return NextResponse.json(
{ success: false, message: '请输入邮箱地址' },
{ status: 400 }
);
}

const users = await getUserByEmail(email);

return NextResponse.json({
success: true,
message: users.length > 0
? '已受理重置请求,请联系管理员重置密码'
: '如果该邮箱已注册,我们会处理重置请求',
});
} catch (error) {
console.error('Forgot password error:', error);
return NextResponse.json(
{ success: false, message: '重置请求提交失败' },
{ status: 500 }
);
}
}
12 changes: 5 additions & 7 deletions src/app/api/interviews/schedule/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { NextResponse } from 'next/server';
import { updateInterview, getInterviewsByStudentId, updateStudent, getStudentById, createActivityLog } from '@/lib/db/queries';
import { eq } from 'drizzle-orm';
import { schema, db } from '@/lib/db';
import { createInterview, updateInterview, getInterviewsByStudentId, updateStudent, getStudentById, createActivityLog } from '@/lib/db/queries';

/**
* @swagger
Expand Down Expand Up @@ -79,12 +77,12 @@ export async function POST(request: Request) {
}

// 构建更新数据
const updateData: Partial<typeof schema.interviews.$inferInsert> = {
const updateData = {
time: time || '',
date: date ? new Date(date) : undefined,
interviewers: interviewers || [],
location: location || '',
stage: 'pending_interview',
stage: 'pending_interview' as const,
updatedAt: new Date(),
};

Expand All @@ -107,7 +105,7 @@ export async function POST(request: Request) {
}
const student = studentInfo[0];

await db.insert(schema.interviews).values({
await createInterview({
studentId,
name: student.name || '',
major: student.major || '',
Expand All @@ -118,7 +116,7 @@ export async function POST(request: Request) {
email: student.email || '',
phone: student.phone || '',
className: student.className || '',
skills: student.skills || [],
skills: (student as any).skills || [],
experiences: student.experiences || [],
time: time || '',
date: date ? new Date(date) : undefined,
Expand Down
6 changes: 2 additions & 4 deletions src/app/api/resumes/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { NextResponse } from 'next/server';
import { getStudents, getStudentById, createStudent, createActivityLog, getUserById } from '@/lib/db/queries';
import { getStudents, createStudent, createActivityLog, getUserById } from '@/lib/db/queries';
import { getCurrentUser } from '@/lib/auth';
import { eq, like, and, or, desc } from 'drizzle-orm';
import { schema } from '@/lib/db';
import { writeFile, mkdir, unlink } from 'fs/promises';
import { writeFile, mkdir } from 'fs/promises';
import { join } from 'path';

// 简历 PDF 上传目录
Expand Down
10 changes: 9 additions & 1 deletion src/app/components/layout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ function SidebarWrapper() {
);
}

function HeaderWrapper() {
return (
<Suspense fallback={<div className="h-16 bg-white dark:bg-slate-900 border-b border-slate-200 dark:border-slate-800" />}>
<AppHeader />
</Suspense>
);
}

export function MainLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();

Expand All @@ -32,7 +40,7 @@ export function MainLayout({ children }: { children: React.ReactNode }) {
<SidebarWrapper />
</div>
<div className="flex-1 flex flex-col min-w-0 relative">
<AppHeader />
<HeaderWrapper />
<main className="flex-1 overflow-auto p-4 md:p-6 scroll-smooth">
<div className="max-w-7xl mx-auto space-y-4 md:space-y-6">
{children}
Expand Down
48 changes: 36 additions & 12 deletions src/app/components/resume-bank.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useMemo } from 'react';
import { toast } from 'sonner';
import { useSearchParams } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { Student } from '@/types';
import { DEPARTMENTS, STATUS_MAP, SortOptionId } from '@/config/constants';

Expand All @@ -13,11 +13,12 @@ import { UploadResumeDialog } from './resume/UploadResumeDialog';
import { SyncMailDialog } from './resume/SyncMailDialog';

export function ResumeBank() {
const router = useRouter();
const [students, setStudents] = useState<Student[]>([]);
const [loading, setLoading] = useState(true);
const [isUploadOpen, setIsUploadOpen] = useState(false);
const [selectedStudent, setSelectedStudent] = useState<Student | null>(null);
const [filterDept, setFilterDept] = useState(DEPARTMENTS[0]);
const [filterDept, setFilterDept] = useState<string>(DEPARTMENTS[0]);
const [sortBy, setSortBy] = useState<SortOptionId>('ai');
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
const [searchQuery, setSearchQuery] = useState('');
Expand All @@ -34,7 +35,13 @@ export function ResumeBank() {
const [isSyncMailOpen, setIsSyncMailOpen] = useState(false);

const searchParams = useSearchParams();
const { currentUser } = useAppStore();
const { currentUser, logout } = useAppStore();

const handleUnauthorized = (message: string = '登录已失效,请重新登录') => {
toast.error(message);
logout();
router.push('/login');
};

// Handle URL candidateId parameter
useEffect(() => {
Expand Down Expand Up @@ -83,7 +90,14 @@ export function ResumeBank() {
break;
case 'status':
// Custom order for status: pending > interviewing > passed > rejected
const statusOrder = { pending: 3, interviewing: 2, passed: 1, rejected: 0 };
const statusOrder: Record<Student['status'], number> = {
pending: 5,
to_be_scheduled: 4,
pending_interview: 3,
interviewing: 2,
passed: 1,
rejected: 0,
};
const statusA = statusOrder[a.status] || 0;
const statusB = statusOrder[b.status] || 0;
diff = statusA - statusB;
Expand All @@ -104,21 +118,27 @@ export function ResumeBank() {
fetch('/api/departments')
]);

if (resumesRes.ok) {
const result = await resumesRes.json();
// 处理分页格式的响应
const resumesData = Array.isArray(result) ? result : (result.data || []);
setStudents(resumesData);
} else {
throw new Error('Failed to fetch resumes');
if (resumesRes.status === 401) {
const result = await resumesRes.json().catch(() => ({}));
handleUnauthorized(result.message || '请先登录');
return;
}

if (!resumesRes.ok) {
const result = await resumesRes.json().catch(() => ({}));
throw new Error(result.message || '获取简历失败');
}

const result = await resumesRes.json();
const resumesData = Array.isArray(result) ? result : (result.data || []);
setStudents(resumesData);

if (deptsRes.ok) {
const deptsData = await deptsRes.json();
setDepartments(['全部部门', ...deptsData]);
}
} catch (error) {
toast.error('获取数据失败');
toast.error(error instanceof Error ? error.message : '获取数据失败');
console.error('Error fetching data:', error);
} finally {
setLoading(false);
Expand Down Expand Up @@ -156,6 +176,10 @@ export function ResumeBank() {
});

const data = await res.json();
if (res.status === 401) {
handleUnauthorized(data.message || '登录已失效,请重新登录');
return;
}
if (data.success) {
toast.success(`状态已更新为:${STATUS_MAP[newStatus].label}`);
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function SettingsPage({ role }: SettingsPageProps) {

const fetchSettings = async () => {
try {
const [pl, a, n, r, k, g, e] = await Promise.all([
const [pl, a, n, r, k, e, g] = await Promise.all([
fetch('/api/settings/platform').then(res => res.json()),
fetch('/api/settings/ai').then(res => res.json()),
fetch('/api/settings/notifications').then(res => res.json()),
Expand Down Expand Up @@ -184,14 +184,11 @@ export function SettingsPage({ role }: SettingsPageProps) {

setApiKeys(k || []);
setGithub(g || { clientId: '', clientSecret: '', organization: '', personalAccessToken: '' });
// 调试日志
console.log('Email-sending API 返回:', e);
// SMTP 配置:加载所有保存的配置
setEmailSending({
host: g?.host || '',
port: g?.port || '',
user: g?.user || '',
pass: g?.pass || ''
host: e?.host || '',
port: e?.port || '',
user: e?.user || '',
pass: e?.pass || ''
});

} catch (error) {
Expand Down
5 changes: 1 addition & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { Toaster } from "sonner";
import { MainLayout } from "./components/layout/MainLayout";
import { Providers } from "./providers";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "码绘工作室 - 人才管理系统",
description: "内部专用的招新管理平台",
Expand All @@ -22,7 +19,7 @@ export default function RootLayout({
}>) {
return (
<html lang="zh-CN" suppressHydrationWarning>
<body className={inter.className}>
<body className="font-sans">
<Providers>
<MainLayout>
{children}
Expand Down
Loading