import React from 'react' import { useForm } from 'react-hook-form' import { useMutation } from '@tanstack/react-query' import { UserAPI } from './api.ts' import { useAuth } from './hooks.tsx' export default function SettingsPage() { const { register, handleSubmit, formState: { errors } } = useForm<{ nickname: string email: string phone?: string password?: string }>() const { mutate: updateUser, isPending } = useMutation({ mutationFn: async (data: { nickname: string email: string phone?: string password?: string }) => { return UserAPI.updateCurrentUser({ nickname: data.nickname, email: data.email, phone: data.phone, ...(data.password ? { password: data.password } : {}) }) }, onSuccess: () => alert('更新成功'), onError: (error) => { console.error('更新失败:', error) alert('更新失败') } }) const onSubmit = (data: { nickname: string email: string phone?: string password?: string }) => { updateUser(data) } return (

设置

编辑个人信息

{errors.nickname &&

{errors.nickname.message}

}
{errors.email &&

{errors.email.message}

}
) }