From 5ece0416726c331555c14281590fd15ef827a417 Mon Sep 17 00:00:00 2001 From: tone Date: Fri, 19 Dec 2025 22:23:16 +0800 Subject: [PATCH] lint --- .../app/(with-header-footer)/blog/page.tsx | 1 - .../app/console/(with-menu)/layout.tsx | 4 +- .../app/console/(with-menu)/profile/page.tsx | 4 +- .../user/list/components/user-info-editor.tsx | 3 +- .../console/(with-menu)/user/list/page.tsx | 4 +- .../login/components/EmailLoginMode.tsx | 130 +++++++++--------- apps/frontend/app/console/login/page.tsx | 4 +- .../components/human-verification.tsx | 10 +- apps/frontend/hooks/admin/user/use-user.ts | 4 +- apps/frontend/lib/api/client.ts | 2 +- .../lib/api/endpoints/admin.client.ts | 30 ++-- .../frontend/lib/api/endpoints/auth.client.ts | 5 +- apps/frontend/lib/api/server.ts | 2 +- 13 files changed, 106 insertions(+), 97 deletions(-) diff --git a/apps/frontend/app/(with-header-footer)/blog/page.tsx b/apps/frontend/app/(with-header-footer)/blog/page.tsx index 72de2ec..b0b0843 100644 --- a/apps/frontend/app/(with-header-footer)/blog/page.tsx +++ b/apps/frontend/app/(with-header-footer)/blog/page.tsx @@ -1,4 +1,3 @@ -import { useCallback } from "react" import { Alert, AlertDescription, diff --git a/apps/frontend/app/console/(with-menu)/layout.tsx b/apps/frontend/app/console/(with-menu)/layout.tsx index a310473..e8de1b6 100644 --- a/apps/frontend/app/console/(with-menu)/layout.tsx +++ b/apps/frontend/app/console/(with-menu)/layout.tsx @@ -15,8 +15,6 @@ import { import { useUserStore } from "@/store/useUserStore"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; -// import { useUserMe } from "@/hooks/user/use-user-me"; -// import { toast } from "sonner"; export default function ConsoleMenuLayout({ children, @@ -30,7 +28,7 @@ export default function ConsoleMenuLayout({ if (userStore.initialized && !userStore.user) { router.replace('/console/login') } - }, [userStore]) + }, [userStore, router]) return ( diff --git a/apps/frontend/app/console/(with-menu)/profile/page.tsx b/apps/frontend/app/console/(with-menu)/profile/page.tsx index 892b638..2ba8339 100644 --- a/apps/frontend/app/console/(with-menu)/profile/page.tsx +++ b/apps/frontend/app/console/(with-menu)/profile/page.tsx @@ -3,17 +3,15 @@ import { Button } from "@/components/ui/button"; import { Field, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet } from "@/components/ui/field"; import { useUserStore } from "@/store/useUserStore"; -import { Checkbox } from "@radix-ui/react-checkbox"; import { Table, TableBody, - TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" -import { ReactElement, useMemo, useState } from "react"; +import { ReactElement, useState } from "react"; import { Dialog, DialogClose, diff --git a/apps/frontend/app/console/(with-menu)/user/list/components/user-info-editor.tsx b/apps/frontend/app/console/(with-menu)/user/list/components/user-info-editor.tsx index 8d26210..14402b0 100644 --- a/apps/frontend/app/console/(with-menu)/user/list/components/user-info-editor.tsx +++ b/apps/frontend/app/console/(with-menu)/user/list/components/user-info-editor.tsx @@ -27,6 +27,7 @@ import { AlertCircle } from "lucide-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { AdminAPI } from "@/lib/api/client"; +import { UserEntity } from "@/lib/api/endpoints/admin.client"; export function UserInfoEditor({ onClose, @@ -35,7 +36,7 @@ export function UserInfoEditor({ userId, }: { onClose: () => void, - onUserUpdate: (user: User) => void, + onUserUpdate: (user: UserEntity) => void, onUserSoftDelete: (userId: string) => void, userId: string }) { diff --git a/apps/frontend/app/console/(with-menu)/user/list/page.tsx b/apps/frontend/app/console/(with-menu)/user/list/page.tsx index 2afdc9c..b0c5679 100644 --- a/apps/frontend/app/console/(with-menu)/user/list/page.tsx +++ b/apps/frontend/app/console/(with-menu)/user/list/page.tsx @@ -6,19 +6,19 @@ import { TooltipContent, TooltipProvider, TooltipTrigger, Tooltip } from "@/comp import { useUserList } from "@/hooks/admin/user/use-user-list"; import { useState } from "react"; import { UserInfoEditor } from "./components/user-info-editor"; -import { User } from "@/lib/types/user"; import { CreateUserEditor } from "./components/create-user-editor"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; import { toast } from "sonner"; import { ApiError } from "next/dist/server/api-utils"; import { AdminAPI } from "@/lib/api/client"; +import { UserEntity } from "@/lib/api/endpoints/admin.client"; export default function Page() { const { users, isLoading, error, mutate, refresh } = useUserList(); const [editorUserId, setEditorUserId] = useState(""); - const handleUserUpdateLocal = async (newUser: User) => { + const handleUserUpdateLocal = async (newUser: UserEntity) => { await mutate( (data) => { if (!data) return data; diff --git a/apps/frontend/app/console/login/components/EmailLoginMode.tsx b/apps/frontend/app/console/login/components/EmailLoginMode.tsx index 15d2a27..98f206b 100644 --- a/apps/frontend/app/console/login/components/EmailLoginMode.tsx +++ b/apps/frontend/app/console/login/components/EmailLoginMode.tsx @@ -1,67 +1,67 @@ -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp"; -import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"; -import { useState, useCallback } from "react"; -import { toast } from "sonner"; -import LoginHeader from "./LoginHeader"; -import { SendCodeFormData } from "./types"; -import { Label } from "@/components/ui/label"; +// import { Button } from "@/components/ui/button"; +// import { Input } from "@/components/ui/input"; +// import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp"; +// import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"; +// import { useState, useCallback } from "react"; +// import { toast } from "sonner"; +// import LoginHeader from "./LoginHeader"; +// import { SendCodeFormData } from "./types"; +// import { Label } from "@/components/ui/label"; -export default function EmailLoginMode({ onSendCode }: { onSendCode: (data: SendCodeFormData) => Promise }) { - const [email, setEmail] = useState(""); - const handleSendCode = useCallback(() => { - if (!email.trim().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) { - toast.error('请输入正确的邮箱地址'); - return; - } - onSendCode({ - type: 'email', - email, - }) - }, [email, onSendCode]); +// export default function EmailLoginMode({ onSendCode }: { onSendCode: (data: SendCodeFormData) => Promise }) { +// const [email, setEmail] = useState(""); +// const handleSendCode = useCallback(() => { +// if (!email.trim().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) { +// toast.error('请输入正确的邮箱地址'); +// return; +// } +// onSendCode({ +// type: 'email', +// email, +// }) +// }, [email, onSendCode]); - return ( - <> - -
- - setEmail(e.target.value)} - required /> -
-
-
- -
-
- - - - - - - - - - - -
-
- - - ) -} +// return ( +// <> +// +//
+// +// setEmail(e.target.value)} +// required /> +//
+//
+//
+// +//
+//
+// +// +// +// +// +// +// +// +// +// +// +//
+//
+// +// +// ) +// } diff --git a/apps/frontend/app/console/login/page.tsx b/apps/frontend/app/console/login/page.tsx index 11fd96e..2998b8a 100644 --- a/apps/frontend/app/console/login/page.tsx +++ b/apps/frontend/app/console/login/page.tsx @@ -27,7 +27,7 @@ export default function Login() { if (userStore.user) { router.replace('/console') } - }, [userStore]) + }, [userStore, router]) return ( <> @@ -41,7 +41,7 @@ export default function Login() { e.preventDefault(); const formData = new FormData(e.currentTarget); - let handler = (await (async () => { + const handler = (await (async () => { if (loginMode === 'password') { return import('./components/PasswordLoginMode'); } else if (loginMode === 'sms') { diff --git a/apps/frontend/components/human-verification.tsx b/apps/frontend/components/human-verification.tsx index 56c88ee..e85e116 100644 --- a/apps/frontend/components/human-verification.tsx +++ b/apps/frontend/components/human-verification.tsx @@ -8,7 +8,7 @@ import { DialogTitle, DialogTrigger, } from "@/components/ui/dialog" -import { ReactNode, useEffect, useState } from "react" +import { ReactNode, useCallback, useEffect, useState } from "react" interface HumanVerificationProps { open?: boolean; @@ -18,19 +18,19 @@ interface HumanVerificationProps { children: ReactNode; } -export function HumanVerification({ open, onOpenChange, onSuccess, onFail, children }: HumanVerificationProps) { +export function HumanVerification({ open, onOpenChange, onSuccess, children }: HumanVerificationProps) { const [i_open, i_setOpen] = useState(false); - const setOpen = (o: boolean) => { + const setOpen = useCallback((o: boolean) => { i_setOpen(o); onOpenChange?.(o); - }; + }, [onOpenChange]); useEffect(() => { if (i_open) { setOpen(false); onSuccess?.(); } - }, [i_open]); + }, [i_open, onSuccess, setOpen]); return ( diff --git a/apps/frontend/hooks/admin/user/use-user.ts b/apps/frontend/hooks/admin/user/use-user.ts index c6bf194..6caf939 100644 --- a/apps/frontend/hooks/admin/user/use-user.ts +++ b/apps/frontend/hooks/admin/user/use-user.ts @@ -1,10 +1,10 @@ import { AdminAPI } from "@/lib/api/client"; -import { User } from "@/lib/types/user"; +import { UserEntity } from "@/lib/api/endpoints/admin.client"; import { toast } from "sonner"; import useSWR from "swr"; export function useUser(userId: string) { - const { data, error, isLoading, mutate } = useSWR( + const { data, error, isLoading, mutate } = useSWR( ['/api/admin/user', userId], () => AdminAPI.getUser(userId), { diff --git a/apps/frontend/lib/api/client.ts b/apps/frontend/lib/api/client.ts index 722f614..9bdea1a 100644 --- a/apps/frontend/lib/api/client.ts +++ b/apps/frontend/lib/api/client.ts @@ -2,7 +2,7 @@ import { APIResponse, HttpMethod, normalizeAPIError } from './common'; interface ClientFetchRequestOptions extends RequestInit { method?: HttpMethod; - body?: any; + body?: string; } export async function clientFetch( diff --git a/apps/frontend/lib/api/endpoints/admin.client.ts b/apps/frontend/lib/api/endpoints/admin.client.ts index 6e8d6a6..dddcc27 100644 --- a/apps/frontend/lib/api/endpoints/admin.client.ts +++ b/apps/frontend/lib/api/endpoints/admin.client.ts @@ -2,7 +2,19 @@ import { Resource } from "@/lib/types/resource"; import { clientFetch } from "../client"; import { Blog } from "@/lib/types/blog"; import { BlogPermission } from "@/lib/types/Blog.Permission.enum"; -import { User } from "@/lib/types/user"; +import { Role } from "@/lib/types/role"; + +export interface UserEntity { + userId: string; + username: string; + nickname: string; + email?: string; + phone?: string; + avatar?: string; + createdAt: string; + deletedAt: string | null; + roles: Role[]; +} // ======== Resource ======== export async function listResources() { @@ -24,7 +36,7 @@ export async function createResource(data: CreateResourceParams) { data.description = data.description.trim(); data.imageUrl = data.imageUrl.trim(); data.link = data.link.trim(); - for (let tag of data.tags) { + for (const tag of data.tags) { tag.name = tag.name.trim(); } @@ -59,7 +71,7 @@ export async function updateResource(id: string, data: UpdateResourceParams) { data.description = data.description.trim(); data.imageUrl = data.imageUrl.trim(); data.link = data.link.trim(); - for (let tag of data.tags) { + for (const tag of data.tags) { tag.name = tag.name.trim(); } @@ -139,18 +151,18 @@ interface CreateUserParams { } export async function createUser(data: CreateUserParams) { type Keys = keyof CreateUserParams; - for (let key in data) { + for (const key in data) { data[key as Keys] = data[key as Keys]?.trim() || null; } - return clientFetch("/api/admin/user", { + return clientFetch("/api/admin/user", { method: "POST", body: JSON.stringify(data), }); } export function getUser(id: string) { - return clientFetch(`/api/admin/user/${id}`); + return clientFetch(`/api/admin/user/${id}`); } export interface UserListParams { @@ -158,7 +170,7 @@ export interface UserListParams { pageSize?: number } export interface UserListResponse { - items: User[], + items: UserEntity[], total: number page: number pageSize: number @@ -200,8 +212,8 @@ export async function updateUser(userId: string, user: updateUser) { user.nickname = user.nickname.trim(); user.email = user.email?.trim() || null; user.phone = user.phone?.trim() || null; - - return clientFetch(`/api/admin/user/${userId}`, { + + return clientFetch(`/api/admin/user/${userId}`, { body: JSON.stringify(user), method: "PUT", }); diff --git a/apps/frontend/lib/api/endpoints/auth.client.ts b/apps/frontend/lib/api/endpoints/auth.client.ts index 952d0a5..e121382 100644 --- a/apps/frontend/lib/api/endpoints/auth.client.ts +++ b/apps/frontend/lib/api/endpoints/auth.client.ts @@ -1,7 +1,7 @@ import { User } from "@/lib/types/user"; import { clientFetch } from "../client"; import { APIError } from "../common"; -import { PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; +import { AuthenticationResponseJSON, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; export async function loginByPassword(identifier: string, password: string) { identifier = identifier.trim(); @@ -85,7 +85,8 @@ export async function getLoginByPasskeyOptions() { }) } -export async function loginByPasskey(credentialResponse: any) { +/** @lint-ignore */ +export async function loginByPasskey(credentialResponse: AuthenticationResponseJSON) { return clientFetch<{ user: User }>('/api/auth/passkey/login', { method: 'POST', body: JSON.stringify({ diff --git a/apps/frontend/lib/api/server.ts b/apps/frontend/lib/api/server.ts index 12912c7..ba042d6 100644 --- a/apps/frontend/lib/api/server.ts +++ b/apps/frontend/lib/api/server.ts @@ -3,7 +3,7 @@ import { APIResponse, HttpMethod, normalizeAPIError } from './common'; interface ServerFetchRequestOptions extends RequestInit { method?: HttpMethod; - body?: any; + body?: string; } export async function serverFetch(