From 10a44755cfc074a7ec3c5dff67caef2f6990c54f Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 2 Jul 2026 23:07:07 -0400 Subject: [PATCH] Adding code --- src/components/ProfileForm.jsx | 266 ++++++++++++++++++++++++--------- 1 file changed, 196 insertions(+), 70 deletions(-) diff --git a/src/components/ProfileForm.jsx b/src/components/ProfileForm.jsx index 2ed853e..d53c5a1 100644 --- a/src/components/ProfileForm.jsx +++ b/src/components/ProfileForm.jsx @@ -9,6 +9,7 @@ import './ProfileForm.css'; const ProfileForm = () => { const navigate = useNavigate(); const [activeView, setActiveView] = useState('profile'); + const [subView, setSubView] = useState('details'); // Add this state for toggling const [formData, setFormData] = useState({ firstname: '', lastname: '', @@ -17,6 +18,13 @@ const ProfileForm = () => { createdDate: new Date().toISOString().split('T')[0], lastLoginDate: new Date().toISOString().split('T')[0], }); + + // Add password state + const [passwordData, setPasswordData] = useState({ + currentPassword: '', + newPassword: '', + confirmNewPassword: '' + }); useEffect(() => { const fetchData = async () => { @@ -47,6 +55,15 @@ const ProfileForm = () => { setFormData({ ...formData, [name]: value }); }; + // Add password change handler + const handlePasswordChange = (e) => { + const { name, value } = e.target; + setPasswordData(prev => ({ + ...prev, + [name]: value + })); + }; + const handleNavClick = (view) => { if (view === 'profile') { navigate('/user/profile'); @@ -55,6 +72,183 @@ const ProfileForm = () => { } }; + const validateForm = () => { + const newErrors = {}; + + // Password validation + if (!passwordData.currentPassword) { + newErrors.currentPassword = 'Current Password is required'; + } + + // Confirm password validation + if (passwordData.newPassword !== passwordData.confirmNewPassword) { + newErrors.confirmNewPassword = 'Passwords do not match'; + } + + return newErrors; + }; + + // Add password submit handler + const handlePasswordSubmit = async (e) => { + e.preventDefault(); + // You can add your password update logic here + console.log('Password update requested:', passwordData); + + const validationErrors = validateForm(); + + if (Object.keys(validationErrors).length > 0) { + setErrors(validationErrors); + setIsLoading(false); + return; + } + + try { + const userId = tokenService.getUserId(); + const currentPassword = passwordData.currentPassword; + const newPassword = passwordData.newPassword; + const confirmNewPassword = passwordData.confirmNewPassword; + + const response = await userApi.update_password(userId, currentPassword, newPassword, confirmNewPassword); + if (response) { + console.log('Successfully updated password'); + } else { + console.error('Error updating password'); + } + } catch (error) { + } finally { + } + }; + + // Render password change form + const renderPasswordForm = () => ( +
+

Change Password

+
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+ ); + + // Render profile details form + const renderProfileForm = () => ( +
+
+

User Profile

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ ); + return (
{/* Navbar */} @@ -84,76 +278,8 @@ const ProfileForm = () => {
- {/* Main Content */} -
-

User Profile

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
+ {/* Main Content - Toggle between views */} + {subView === 'details' ? renderProfileForm() : renderPasswordForm()} ); };