diff --git a/frontend/src/components/settings/general/GeneralContainer.jsx b/frontend/src/components/settings/general/GeneralContainer.jsx index b2c40f3..d851c1b 100644 --- a/frontend/src/components/settings/general/GeneralContainer.jsx +++ b/frontend/src/components/settings/general/GeneralContainer.jsx @@ -6,13 +6,19 @@ const GeneralContainer = () => { const [loading, setLoading] = useState(true); const [showApiKey, setShowApiKey] = useState(false); const [showPassword, setShowPassword] = useState(false); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); + const [showCurrentPassword, setShowCurrentPassword] = useState(false); + const [showUsernameCurrentPassword, setShowUsernameCurrentPassword] = + useState(false); const [copySuccess, setCopySuccess] = useState(false); const [formData, setFormData] = useState({ apiKey: '', username: '', + usernameCurrentPassword: '', password: '', - currentUsername: '', - currentPassword: '' + confirmPassword: '', + currentPassword: '', + currentUsername: '' }); useEffect(() => { @@ -26,9 +32,11 @@ const GeneralContainer = () => { setFormData({ apiKey: 'sk-1234567890abcdef', username: 'admin', - password: 'currentpassword', - currentUsername: 'admin', - currentPassword: 'currentpassword' + usernameCurrentPassword: '', + password: '', + confirmPassword: '', + currentPassword: '', + currentUsername: 'admin' }); } catch (error) { console.error('Error fetching settings:', error); @@ -49,7 +57,6 @@ const GeneralContainer = () => { ); if (confirmed) { console.log('Will reset API key'); - // Here you would call your API endpoint to reset the key } }; @@ -60,31 +67,60 @@ const GeneralContainer = () => { })); }; - const handlePasswordChange = e => { + const handleUsernameCurrentPasswordChange = e => { setFormData(prev => ({ ...prev, - password: e.target.value + usernameCurrentPassword: e.target.value + })); + }; + + const handlePasswordChange = e => { + const newPassword = e.target.value; + setFormData(prev => ({ + ...prev, + password: newPassword + })); + }; + + const handleConfirmPasswordChange = e => { + setFormData(prev => ({ + ...prev, + confirmPassword: e.target.value + })); + }; + + const handleCurrentPasswordChange = e => { + setFormData(prev => ({ + ...prev, + currentPassword: e.target.value })); }; const handleSaveUsername = () => { - console.log('Will save username:', formData.username); + console.log('Will save username:', { + newUsername: formData.username, + currentPassword: formData.usernameCurrentPassword + }); setFormData(prev => ({ ...prev, - currentUsername: formData.username + currentUsername: formData.username, + usernameCurrentPassword: '' })); }; const handleSavePassword = () => { + if (formData.password !== formData.confirmPassword) { + alert('Passwords do not match'); + return; + } const confirmed = window.confirm( 'Are you sure you want to change your password?' ); if (confirmed) { - console.log('Will save password:', formData.password); - setFormData(prev => ({ - ...prev, - currentPassword: formData.password - })); + console.log('Will save password with verification', { + newPassword: formData.password, + currentPassword: formData.currentPassword + }); } }; @@ -97,7 +133,6 @@ const GeneralContainer = () => { } const hasUsernameChanges = formData.username !== formData.currentUsername; - const hasPasswordChanges = formData.password !== formData.currentPassword; return (