mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
refactor: migrate to eslint flat config and format codebase with prettier
- Remove legacy .eslintrc.cjs and .eslintignore - Add eslint.config.js with flat config, security rules (no-eval, no-implied-eval, no-new-func, no-script-url) - Add .prettierrc and .prettierignore - Format entire codebase with prettier
This commit is contained in:
@@ -1,108 +1,117 @@
|
||||
import { useState } from 'react'
|
||||
import { useSearchParams, Link, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { authApi } from '../api/auth'
|
||||
import LanguageSwitcher from '../components/LanguageSwitcher'
|
||||
import { useState } from 'react';
|
||||
import { useSearchParams, Link, useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { authApi } from '../api/auth';
|
||||
import LanguageSwitcher from '../components/LanguageSwitcher';
|
||||
|
||||
export default function ResetPassword() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const [searchParams] = useSearchParams()
|
||||
const token = searchParams.get('token')
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const token = searchParams.get('token');
|
||||
|
||||
const [password, setPassword] = useState('')
|
||||
const [confirmPassword, setConfirmPassword] = useState('')
|
||||
const [status, setStatus] = useState<'form' | 'loading' | 'success' | 'error'>('form')
|
||||
const [error, setError] = useState('')
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [status, setStatus] = useState<'form' | 'loading' | 'success' | 'error'>('form');
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
|
||||
if (!token) {
|
||||
setError(t('resetPassword.invalidToken', 'Invalid or missing reset token'))
|
||||
return
|
||||
setError(t('resetPassword.invalidToken', 'Invalid or missing reset token'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 8) {
|
||||
setError(t('auth.passwordTooShort', 'Password must be at least 8 characters'))
|
||||
return
|
||||
setError(t('auth.passwordTooShort', 'Password must be at least 8 characters'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
setError(t('auth.passwordMismatch', 'Passwords do not match'))
|
||||
return
|
||||
setError(t('auth.passwordMismatch', 'Passwords do not match'));
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus('loading')
|
||||
setStatus('loading');
|
||||
|
||||
try {
|
||||
await authApi.resetPassword(token, password)
|
||||
setStatus('success')
|
||||
setTimeout(() => navigate('/login', { replace: true }), 2000)
|
||||
await authApi.resetPassword(token, password);
|
||||
setStatus('success');
|
||||
setTimeout(() => navigate('/login', { replace: true }), 2000);
|
||||
} catch (err: unknown) {
|
||||
setStatus('error')
|
||||
const error = err as { response?: { data?: { detail?: string } } }
|
||||
setError(error.response?.data?.detail || t('common.error'))
|
||||
setStatus('error');
|
||||
const error = err as { response?: { data?: { detail?: string } } };
|
||||
setError(error.response?.data?.detail || t('common.error'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!token) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center py-8 px-4 sm:py-12">
|
||||
<div className="flex min-h-screen items-center justify-center px-4 py-8 sm:py-12">
|
||||
<div className="fixed inset-0 bg-gradient-to-br from-dark-950 via-dark-900 to-dark-950" />
|
||||
<div className="fixed top-4 right-4 z-50">
|
||||
<div className="fixed right-4 top-4 z-50">
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
<div className="relative max-w-md w-full text-center">
|
||||
<div className="relative w-full max-w-md text-center">
|
||||
<div className="card">
|
||||
<div className="text-error-400 text-5xl mb-4">!</div>
|
||||
<h2 className="text-xl font-semibold text-dark-50 mb-2">
|
||||
<div className="mb-4 text-5xl text-error-400">!</div>
|
||||
<h2 className="mb-2 text-xl font-semibold text-dark-50">
|
||||
{t('resetPassword.invalidToken', 'Invalid reset link')}
|
||||
</h2>
|
||||
<p className="text-dark-400 mb-6">
|
||||
{t('resetPassword.tokenExpiredOrInvalid', 'This password reset link is invalid or has expired.')}
|
||||
<p className="mb-6 text-dark-400">
|
||||
{t(
|
||||
'resetPassword.tokenExpiredOrInvalid',
|
||||
'This password reset link is invalid or has expired.',
|
||||
)}
|
||||
</p>
|
||||
<Link to="/login" className="btn-primary w-full inline-block">
|
||||
<Link to="/login" className="btn-primary inline-block w-full">
|
||||
{t('auth.backToLogin', 'Back to login')}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center py-8 px-4 sm:py-12">
|
||||
<div className="flex min-h-screen items-center justify-center px-4 py-8 sm:py-12">
|
||||
<div className="fixed inset-0 bg-gradient-to-br from-dark-950 via-dark-900 to-dark-950" />
|
||||
<div className="fixed inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-accent-500/10 via-transparent to-transparent" />
|
||||
<div className="fixed top-4 right-4 z-50">
|
||||
<div className="fixed right-4 top-4 z-50">
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
|
||||
<div className="relative max-w-md w-full">
|
||||
<div className="relative w-full max-w-md">
|
||||
<div className="card">
|
||||
{status === 'success' ? (
|
||||
<div className="text-center">
|
||||
<div className="w-16 h-16 mx-auto mb-4 rounded-2xl bg-success-500/20 flex items-center justify-center">
|
||||
<svg className="w-8 h-8 text-success-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<div className="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-success-500/20">
|
||||
<svg
|
||||
className="h-8 w-8 text-success-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</div>
|
||||
<h2 className="text-xl font-bold text-dark-50 mb-2">
|
||||
<h2 className="mb-2 text-xl font-bold text-dark-50">
|
||||
{t('resetPassword.success', 'Password changed!')}
|
||||
</h2>
|
||||
<p className="text-dark-400 mb-4">
|
||||
<p className="mb-4 text-dark-400">
|
||||
{t('resetPassword.redirectingToLogin', 'Redirecting to login...')}
|
||||
</p>
|
||||
<div className="animate-spin rounded-full h-6 w-6 border-2 border-accent-500 border-t-transparent mx-auto" />
|
||||
<div className="mx-auto h-6 w-6 animate-spin rounded-full border-2 border-accent-500 border-t-transparent" />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-dark-50 mb-2 text-center">
|
||||
<h2 className="mb-2 text-center text-xl font-bold text-dark-50">
|
||||
{t('resetPassword.title', 'Set new password')}
|
||||
</h2>
|
||||
<p className="text-dark-400 mb-6 text-center">
|
||||
<p className="mb-6 text-center text-dark-400">
|
||||
{t('resetPassword.enterNewPassword', 'Enter your new password below.')}
|
||||
</p>
|
||||
|
||||
@@ -140,7 +149,7 @@ export default function ResetPassword() {
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-error-500/10 border border-error-500/30 text-error-400 px-4 py-3 rounded-xl text-sm">
|
||||
<div className="rounded-xl border border-error-500/30 bg-error-500/10 px-4 py-3 text-sm text-error-400">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
@@ -152,7 +161,7 @@ export default function ResetPassword() {
|
||||
>
|
||||
{status === 'loading' ? (
|
||||
<span className="flex items-center justify-center gap-2">
|
||||
<span className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||
<span className="h-4 w-4 animate-spin rounded-full border-2 border-white/30 border-t-white" />
|
||||
{t('common.loading')}
|
||||
</span>
|
||||
) : (
|
||||
@@ -162,7 +171,10 @@ export default function ResetPassword() {
|
||||
</form>
|
||||
|
||||
<div className="mt-4 text-center">
|
||||
<Link to="/login" className="text-sm text-dark-400 hover:text-dark-200 transition-colors">
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-sm text-dark-400 transition-colors hover:text-dark-200"
|
||||
>
|
||||
{t('auth.backToLogin', 'Back to login')}
|
||||
</Link>
|
||||
</div>
|
||||
@@ -171,5 +183,5 @@ export default function ResetPassword() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user