diff --git a/src/actions/users.ts b/src/actions/users.ts index 47b396df9..caec9bc46 100644 --- a/src/actions/users.ts +++ b/src/actions/users.ts @@ -363,7 +363,7 @@ export async function addUser(data: { providerGroup: validatedData.providerGroup || null, tags: validatedData.tags, rpm: validatedData.rpm, - dailyQuota: validatedData.dailyQuota, + dailyQuota: validatedData.dailyQuota ?? undefined, limit5hUsd: validatedData.limit5hUsd ?? undefined, limitWeeklyUsd: validatedData.limitWeeklyUsd ?? undefined, limitMonthlyUsd: validatedData.limitMonthlyUsd ?? undefined, @@ -545,7 +545,7 @@ export async function createUserOnly(data: { providerGroup: validatedData.providerGroup || null, tags: validatedData.tags, rpm: validatedData.rpm, - dailyQuota: validatedData.dailyQuota, + dailyQuota: validatedData.dailyQuota ?? undefined, limit5hUsd: validatedData.limit5hUsd ?? undefined, limitWeeklyUsd: validatedData.limitWeeklyUsd ?? undefined, limitMonthlyUsd: validatedData.limitMonthlyUsd ?? undefined, @@ -698,12 +698,12 @@ export async function editUser( providerGroup: validatedData.providerGroup, tags: validatedData.tags, rpm: validatedData.rpm, - dailyQuota: validatedData.dailyQuota, - limit5hUsd: validatedData.limit5hUsd, - limitWeeklyUsd: validatedData.limitWeeklyUsd, - limitMonthlyUsd: validatedData.limitMonthlyUsd, - limitTotalUsd: validatedData.limitTotalUsd, - limitConcurrentSessions: validatedData.limitConcurrentSessions, + dailyQuota: validatedData.dailyQuota ?? undefined, + limit5hUsd: validatedData.limit5hUsd ?? undefined, + limitWeeklyUsd: validatedData.limitWeeklyUsd ?? undefined, + limitMonthlyUsd: validatedData.limitMonthlyUsd ?? undefined, + limitTotalUsd: validatedData.limitTotalUsd ?? undefined, + limitConcurrentSessions: validatedData.limitConcurrentSessions ?? undefined, dailyResetMode: validatedData.dailyResetMode, dailyResetTime: validatedData.dailyResetTime, isEnabled: validatedData.isEnabled, diff --git a/src/app/[locale]/dashboard/_components/user/forms/key-edit-section.tsx b/src/app/[locale]/dashboard/_components/user/forms/key-edit-section.tsx index cc79b8e7b..c8e17f59f 100644 --- a/src/app/[locale]/dashboard/_components/user/forms/key-edit-section.tsx +++ b/src/app/[locale]/dashboard/_components/user/forms/key-edit-section.tsx @@ -42,7 +42,10 @@ export interface KeyEditSectionProps { }; /** providerGroup 为 admin-only 字段:非管理员仅可查看不可编辑 */ isAdmin?: boolean; - onChange: (field: string, value: any) => void; + onChange: { + (field: string, value: any): void; + (updates: Record): void; + }; scrollRef?: React.RefObject; translations: { sections: { diff --git a/src/app/[locale]/dashboard/_components/user/forms/limit-rule-picker.tsx b/src/app/[locale]/dashboard/_components/user/forms/limit-rule-picker.tsx index 5aea38f1e..d30d67450 100644 --- a/src/app/[locale]/dashboard/_components/user/forms/limit-rule-picker.tsx +++ b/src/app/[locale]/dashboard/_components/user/forms/limit-rule-picker.tsx @@ -1,7 +1,7 @@ "use client"; -import { useEffect, useMemo, useState } from "react"; import { AlertTriangle } from "lucide-react"; +import { useEffect, useMemo, useState } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, diff --git a/src/app/[locale]/dashboard/_components/user/forms/user-edit-section.tsx b/src/app/[locale]/dashboard/_components/user/forms/user-edit-section.tsx index fd4ffad8d..68542510e 100644 --- a/src/app/[locale]/dashboard/_components/user/forms/user-edit-section.tsx +++ b/src/app/[locale]/dashboard/_components/user/forms/user-edit-section.tsx @@ -48,7 +48,10 @@ export interface UserEditSectionProps { onToggleEnabled?: () => Promise; showProviderGroup?: boolean; modelSuggestions?: string[]; - onChange: (field: string, value: any) => void; + onChange: { + (field: string, value: any): void; + (updates: Record): void; + }; translations: { sections: { basicInfo: string; @@ -142,8 +145,15 @@ export function UserEditSection({ const [toggleConfirmOpen, setToggleConfirmOpen] = useState(false); const [isToggling, setIsToggling] = useState(false); - const emitChange = (field: string, value: any) => { - onChange(field, value); + const emitChange = (field: string | Record, value?: any) => { + if (typeof field === "object") { + // Batch update - call onChange for each field + Object.entries(field).forEach(([key, val]) => { + (onChange as (f: string, v: any) => void)(key, val); + }); + } else { + (onChange as (f: string, v: any) => void)(field, value); + } }; const handleToggleEnabled = async () => { diff --git a/src/app/[locale]/dashboard/_components/user/forms/user-form.tsx b/src/app/[locale]/dashboard/_components/user/forms/user-form.tsx index 017d113d2..8782587ef 100644 --- a/src/app/[locale]/dashboard/_components/user/forms/user-form.tsx +++ b/src/app/[locale]/dashboard/_components/user/forms/user-form.tsx @@ -118,7 +118,7 @@ export function UserForm({ user, onSuccess, currentUser }: UserFormProps) { name: data.name, note: data.note, rpm: data.rpm, - dailyQuota: data.dailyQuota, + dailyQuota: data.dailyQuota ?? undefined, providerGroup: data.providerGroup || null, tags: data.tags, limit5hUsd: data.limit5hUsd, @@ -136,7 +136,7 @@ export function UserForm({ user, onSuccess, currentUser }: UserFormProps) { name: data.name, note: data.note, rpm: data.rpm, - dailyQuota: data.dailyQuota, + dailyQuota: data.dailyQuota ?? undefined, providerGroup: data.providerGroup || null, tags: data.tags, limit5hUsd: data.limit5hUsd, diff --git a/src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx b/src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx index d673d91ce..c32517307 100644 --- a/src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx +++ b/src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx @@ -891,7 +891,9 @@ function UnifiedEditDialogInner({ limitConcurrentSessions: key.limitConcurrentSessions ?? 0, }} isAdmin={isAdmin} - onChange={(field, value) => handleKeyChange(key.id, field, value)} + onChange={(field: string | Record, value?: any) => + handleKeyChange(key.id, field, value) + } scrollRef={ scrollToKeyId === key.id || newlyAddedKeyId === key.id ? keyScrollRef diff --git a/src/repository/user.ts b/src/repository/user.ts index ad220ce7c..d511e6225 100644 --- a/src/repository/user.ts +++ b/src/repository/user.ts @@ -157,17 +157,18 @@ export async function updateUser(id: number, userData: UpdateUserData): Promise< if (userData.description !== undefined) dbData.description = userData.description; if (userData.rpm !== undefined) dbData.rpmLimit = userData.rpm; if (userData.dailyQuota !== undefined) - dbData.dailyLimitUsd = userData.dailyQuota === null ? null : userData.dailyQuota.toString(); + dbData.dailyLimitUsd = + userData.dailyQuota === null ? undefined : userData.dailyQuota.toString(); if (userData.providerGroup !== undefined) dbData.providerGroup = userData.providerGroup; if (userData.tags !== undefined) dbData.tags = userData.tags; if (userData.limit5hUsd !== undefined) - dbData.limit5hUsd = userData.limit5hUsd === null ? null : userData.limit5hUsd.toString(); + dbData.limit5hUsd = userData.limit5hUsd === null ? undefined : userData.limit5hUsd.toString(); if (userData.limitWeeklyUsd !== undefined) dbData.limitWeeklyUsd = - userData.limitWeeklyUsd === null ? null : userData.limitWeeklyUsd.toString(); + userData.limitWeeklyUsd === null ? undefined : userData.limitWeeklyUsd.toString(); if (userData.limitMonthlyUsd !== undefined) dbData.limitMonthlyUsd = - userData.limitMonthlyUsd === null ? null : userData.limitMonthlyUsd.toString(); + userData.limitMonthlyUsd === null ? undefined : userData.limitMonthlyUsd.toString(); if (userData.limitTotalUsd !== undefined) dbData.limitTotalUsd = userData.limitTotalUsd === null ? null : userData.limitTotalUsd.toString();