import { useState, useEffect } from 'react'; import { Box, Typography, Button, useTheme, useMediaQuery, } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { CardContainer } from '@/components/CardContainer'; import { PageWrapper } from '../PageWrapper'; import Logo from '@/components/Logo'; import { PasswordDialog } from './PasswordDialog'; import { Toast } from '@/components/Toast'; export function PasswordSecurity() { const theme = useTheme(); const fullScreen = useMediaQuery(theme.breakpoints.down('sm')); const { t } = useTranslation('security'); const [open, setOpen] = useState(false); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [currentPassword, setCurrentPassword] = useState(''); const [showValidation, setShowValidation] = useState(false); const [showPasswordAlert, setShowPasswordAlert] = useState(false); const [changePassword, setChangePassword] = useState(false); const [loading, setLoading] = useState(false); const hasNumber = /\d/.test(password); const hasMinLength = password.length >= 8; const hasUpperAndLower = /[A-Z]/.test(password) && /[a-z]/.test(password); const hasSpecialChar = /[!@#$%^&*]/.test(password); const validPassword = hasNumber && hasMinLength && hasUpperAndLower && hasSpecialChar; const matchPassword = password === confirmPassword; useEffect(() => { if (password) { if (!validPassword) { setShowValidation(true); } else { const timer = setTimeout(() => setShowValidation(false), 1000); return () => clearTimeout(timer); } } else { setShowValidation(false); } }, [password, validPassword]); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); const handleShowAlert = () => { setLoading(true); setTimeout(() => { setLoading(false); setShowPasswordAlert(true); setChangePassword(true); handleClose(); setPassword(''); setConfirmPassword(''); setCurrentPassword(''); }, 1500); }; return ( {changePassword ? t('securityForm.changePassword') : t('securityForm.addPassword')} } > {changePassword ? ( {t('securityForm.activePassword')} {t('securityForm.lastChange')} ) : ( {t('securityForm.notDeterminedPassword')} )} {/* New PasswordDialog component usage */} setShowPasswordAlert(false)} > {t('securityForm.alertSuccess')} ); }