import React, { useState } from 'react'; import { Box, PasswordInput, Stack, Text } from '@mantine/core'; import type { UserProfileSettings } from '@/types/models'; interface SecuritySettingsProps { settings: UserProfileSettings; onInputChange: (key: keyof UserProfileSettings, value: string) => void; } type PasswordField = 'currentPassword' | 'newPassword' | 'confirmNewPassword'; const SecuritySettings: React.FC = ({ settings, onInputChange, }) => { const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const handlePasswordChange = (field: PasswordField, value: string) => { if (field === 'confirmNewPassword') { setConfirmPassword(value); // Check if passwords match when either password field changes if (value !== settings.newPassword) { setError('Passwords do not match'); } else { setError(''); } } else { onInputChange(field, value); // Check if passwords match when either password field changes if (field === 'newPassword' && value !== confirmPassword) { setError('Passwords do not match'); } else if (value === confirmPassword) { setError(''); } } }; return ( handlePasswordChange('currentPassword', e.currentTarget.value) } placeholder="Enter current password" /> handlePasswordChange('newPassword', e.currentTarget.value) } placeholder="Enter new password" /> handlePasswordChange('confirmNewPassword', e.currentTarget.value) } placeholder="Confirm new password" error={error} /> Password must be at least 8 characters long. Leave password fields empty if you don't want to change it. ); }; export default SecuritySettings;