'use client';
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useUserStore } from './store';
import { useLayoutStore } from '@/modules/layout/store';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Pencil, Key, User } from 'lucide-react';
import PandaPNG from '@/assets/panda.jpg';
const ProfileCard = () => {
const { me, getMe } = useLayoutStore();
const { setShowEdit, setShowChangePassword } = useUserStore();
useEffect(() => {
getMe();
}, [getMe]);
return (
个人信息
管理您的个人资料和账户设置
{/* Avatar */}
{me?.avatar ? (

) : (

)}
{me?.username || '-'}
{me?.description || '暂无描述'}
{/* User Info Fields */}
{me?.username || '-'}
{me?.nickname || '-'}
{me?.description || '暂无描述'}
{/* Edit Profile Button */}
);
};
const EditProfileModal = () => {
const { showEdit, setShowEdit, setFormData, updateSelf, loading } = useUserStore();
const { me, getMe } = useLayoutStore();
const {
handleSubmit,
reset,
register,
} = useForm();
useEffect(() => {
if (showEdit) {
reset({
nickname: me?.nickname || '',
description: me?.description || '',
});
}
}, [me, showEdit, reset]);
const onSubmit = async (data: any) => {
const res = await updateSelf(data);
if (res) {
setShowEdit(false);
setFormData({});
await getMe();
}
};
return (
);
};
const ChangePasswordModal = () => {
const { showChangePassword, setShowChangePassword, loading } = useUserStore();
const {
handleSubmit,
formState: { errors },
reset,
register,
} = useForm();
const onSubmit = async (data: any) => {
const { updateSelf } = useUserStore.getState();
const res = await updateSelf({
password: data.newPassword,
});
if (res) {
setShowChangePassword(false);
reset();
}
};
return (
);
};
export const UserProfile = () => {
return (
);
};
export default UserProfile