blob: d33cbcbeebb6ccf7a99d1b4588b842c5ca3fc9d1 [file] [log] [blame]
TRM-coding29174c22025-06-18 23:56:51 +08001import React, { useState } from 'react';
2import { FaCamera, FaTimes } from 'react-icons/fa';
3
4const EditProfileForm = ({ user, onSave, onCancel }) => {
5 const [avatar, setAvatar] = useState(user.avatar || '');
6 const [bio, setBio] = useState(user.bio || '');
7 const [gender, setGender] = useState('secret');
8 const [birthday, setBirthday] = useState('');
9 const [location, setLocation] = useState('');
10
11 const handleSubmit = (e) => {
12 e.preventDefault();
13 onSave({ avatar, bio });
14 };
15
16 return (
17 <form onSubmit={handleSubmit}>
18 <div className="mb-6">
19 <label className="block text-sm font-medium text-gray-700 mb-2">头像</label>
20 <div className="flex items-center">
21 <div className="relative">
22 <div className="w-20 h-20 rounded-full bg-gradient-to-r from-pink-300 to-orange-300 flex items-center justify-center">
23 {avatar ? (
24 <img src={avatar} alt="Avatar" className="w-full h-full rounded-full" />
25 ) : (
26 <div className="text-white text-2xl">{user.username.charAt(0)}</div>
27 )}
28 </div>
29 <button
30 type="button"
31 className="absolute bottom-0 right-0 bg-white rounded-full p-1 shadow-md"
32 >
33 <FaCamera className="text-gray-700 text-sm" />
34 </button>
35 </div>
36 <div className="ml-4">
37 <input
38 type="text"
39 value={avatar}
40 onChange={(e) => setAvatar(e.target.value)}
41 placeholder="输入头像URL"
42 className="w-full rounded-md border-gray-300 shadow-sm text-sm"
43 />
44 </div>
45 </div>
46 </div>
47
48 <div className="mb-4">
49 <label className="block text-sm font-medium text-gray-700 mb-2">个人简介</label>
50 <textarea
51 value={bio}
52 onChange={(e) => setBio(e.target.value)}
53 rows="3"
54 maxLength="100"
55 className="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm"
56 placeholder="介绍一下自己吧~"
57 />
58 <div className="text-right text-xs text-gray-500 mt-1">{bio.length}/100</div>
59 </div>
60
61 <div className="grid grid-cols-2 gap-4 mb-4">
62 <div>
63 <label className="block text-sm font-medium text-gray-700 mb-2">性别</label>
64 <select
65 value={gender}
66 onChange={(e) => setGender(e.target.value)}
67 className="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm"
68 >
69 <option value="secret">保密</option>
70 <option value="male">男</option>
71 <option value="female">女</option>
72 </select>
73 </div>
74
75 <div>
76 <label className="block text-sm font-medium text-gray-700 mb-2">生日</label>
77 <input
78 type="date"
79 value={birthday}
80 onChange={(e) => setBirthday(e.target.value)}
81 className="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm"
82 />
83 </div>
84 </div>
85
86 <div className="mb-6">
87 <label className="block text-sm font-medium text-gray-700 mb-2">地区</label>
88 <input
89 type="text"
90 value={location}
91 onChange={(e) => setLocation(e.target.value)}
92 placeholder="填写你所在的城市"
93 className="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm"
94 />
95 </div>
96
97 <div className="flex justify-end space-x-3">
98 <button
99 type="button"
100 onClick={onCancel}
101 className="px-5 py-2 bg-gray-100 text-gray-700 rounded-full text-sm hover:bg-gray-200"
102 >
103 取消
104 </button>
105 <button
106 type="submit"
107 className="px-5 py-2 bg-red-500 text-white rounded-full text-sm hover:bg-red-600"
108 >
109 保存
110 </button>
111 </div>
112 </form>
113 );
114};
115
116export default EditProfileForm;