diff --git a/client/cms/src/components/profile/edit-profile-dialog.tsx b/client/cms/src/components/profile/edit-profile-dialog.tsx
index 3917bf4..e9efd34 100644
--- a/client/cms/src/components/profile/edit-profile-dialog.tsx
+++ b/client/cms/src/components/profile/edit-profile-dialog.tsx
@@ -19,18 +19,25 @@ import {
import {
Input,
} from '@/components/ui/input';
+import { useUpdateUser } from '@/hooks/data/useUpdateUser';
+import { useUserInfo } from '@/hooks/data/useUserInfo';
const formSchema = z.object({
- email: z.string(),
+ username: z.string().min(5),
nickname: z.string().min(1),
subtitle: z.string().min(1),
+ avatar: z.url().min(1),
});
export function EditProfileDialog() {
+ const { data: user } = useUserInfo();
+ const { mutateAsync } = useUpdateUser();
+
const form = useForm({
defaultValues: {
- email: '',
- nickname: '',
- subtitle: '',
+ avatar: user.avatar,
+ username: user.username,
+ nickname: user.nickname,
+ subtitle: user.subtitle,
},
validators: {
onBlur: formSchema,
@@ -39,13 +46,12 @@ export function EditProfileDialog() {
value,
}) => {
try {
- toast(
- {JSON.stringify(value, null, 2)},
- );
+ await mutateAsync(value);
+ toast.success('个人资料更新成功');
}
catch (error) {
console.error('Form submission error', error);
- toast.error('Failed to submit the form. Please try again.');
+ toast.error('更新个人资料失败,请重试');
}
},
});
@@ -53,60 +59,94 @@ export function EditProfileDialog() {
return (
);
}
diff --git a/client/cms/src/components/profile/edit-profile-form.tsx b/client/cms/src/components/profile/edit-profile-form.tsx
deleted file mode 100644
index 771dcae..0000000
--- a/client/cms/src/components/profile/edit-profile-form.tsx
+++ /dev/null
@@ -1,102 +0,0 @@
-import {
- useForm,
-} from '@tanstack/react-form';
-import {
- toast,
-} from 'sonner';
-import {
- z,
-} from 'zod';
-import {
- Button,
-} from '@/components/ui/button';
-import {
- Field,
- FieldError,
- FieldLabel,
-} from '@/components/ui/field';
-import {
- Input,
-} from '@/components/ui/input';
-
-const formSchema = z.object({
- email: z.string(),
- nickname: z.string().min(1),
- subtitle: z.string().min(1),
-});
-
-export default function EditProfileForm() {
- const form = useForm({
- defaultValues: {
- email: '',
- nickname: '',
- subtitle: '',
- },
- validators: {
- onBlur: formSchema,
- },
- onSubmit: async ({
- value,
- }) => {
- try {
- toast(
- {JSON.stringify(value, null, 2)},
- );
- }
- catch (error) {
- console.error('Form submission error', error);
- toast.error('Failed to submit the form. Please try again.');
- }
- },
- });
-
- return (
-