feat(i18n): traducir perfil y seguridad
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useAuth } from '../../context/AuthProvider'
|
||||
import { Avatar } from '../../components/ui'
|
||||
|
||||
export function ProfileView() {
|
||||
const { user } = useAuth()
|
||||
const { t } = useTranslation(['account', 'common'])
|
||||
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-primary">Mi perfil</h1>
|
||||
<p className="mt-1 text-sm text-foreground/60">Tus datos personales.</p>
|
||||
<h1 className="text-2xl font-bold text-primary">{t('profile.title')}</h1>
|
||||
<p className="mt-1 text-sm text-foreground/60">{t('profile.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl border border-border bg-surface p-5">
|
||||
@@ -16,7 +18,7 @@ export function ProfileView() {
|
||||
<Avatar name={user?.name} src={user?.image ?? undefined} className="size-14 text-lg" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-base font-semibold text-primary">
|
||||
{user?.name ?? 'Usuario'}
|
||||
{user?.name ?? t('common:user.fallbackName')}
|
||||
</p>
|
||||
<p className="truncate text-sm text-foreground/50">{user?.email}</p>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { useState } from 'react'
|
||||
import { Fingerprint, Loader2, Trash2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useIntlLocale } from '../../i18n'
|
||||
import { authClient } from '../../lib/auth-client'
|
||||
import { Button } from '../../components/ui'
|
||||
|
||||
export function PasskeyList({ onRefresh }: { onRefresh: () => void }) {
|
||||
const { data, isPending } = authClient.useListPasskeys()
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null)
|
||||
const { t } = useTranslation('account')
|
||||
const locale = useIntlLocale()
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
setDeletingId(id)
|
||||
@@ -23,7 +27,7 @@ export function PasskeyList({ onRefresh }: { onRefresh: () => void }) {
|
||||
|
||||
const passkeys = data ?? []
|
||||
if (passkeys.length === 0) {
|
||||
return <p className="text-sm text-foreground/60">Todavía no registraste ninguna passkey.</p>
|
||||
return <p className="text-sm text-foreground/60">{t('security.noPasskeys')}</p>
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -36,14 +40,14 @@ export function PasskeyList({ onRefresh }: { onRefresh: () => void }) {
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium text-primary">{passkey.name ?? 'Passkey'}</p>
|
||||
<p className="text-xs text-foreground/50">
|
||||
{passkey.deviceType === 'singleDevice' ? 'Dispositivo' : 'Llave de seguridad'} ·{' '}
|
||||
{new Date(passkey.createdAt).toLocaleDateString('es-AR')}
|
||||
{passkey.deviceType === 'singleDevice' ? t('security.device') : t('security.securityKey')} ·{' '}
|
||||
{new Date(passkey.createdAt).toLocaleDateString(locale)}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
aria-label="Eliminar passkey"
|
||||
aria-label={t('security.deletePasskey')}
|
||||
disabled={deletingId === passkey.id}
|
||||
onClick={() => void handleDelete(passkey.id)}
|
||||
>
|
||||
|
||||
@@ -3,6 +3,8 @@ import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { Fingerprint, KeyRound, Loader2, Plus } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { authClient } from '../../lib/auth-client'
|
||||
import { Button, FieldError, Input, Label } from '../../components/ui'
|
||||
import { PasskeyList } from './PasskeyList'
|
||||
@@ -12,6 +14,7 @@ import type { ChangePasswordValues } from './schema'
|
||||
export function SecurityPage() {
|
||||
const [passkeyKeys, setPasskeyKeys] = useState(0)
|
||||
const [feedback, setFeedback] = useState<string | null>(null)
|
||||
const { t } = useTranslation('account')
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -29,9 +32,9 @@ export function SecurityPage() {
|
||||
setFeedback(null)
|
||||
const { error } = await authClient.passkey.addPasskey()
|
||||
if (error) {
|
||||
setFeedback(`No se pudo agregar la passkey: ${error.message ?? 'error desconocido'}`)
|
||||
setFeedback(t('security.passkeyError', { reason: error.message ?? t('security.unknownError') }))
|
||||
} else {
|
||||
setFeedback('Passkey registrada correctamente.')
|
||||
setFeedback(t('security.passkeyAdded'))
|
||||
refreshPasskeys()
|
||||
}
|
||||
}
|
||||
@@ -45,20 +48,20 @@ export function SecurityPage() {
|
||||
})
|
||||
if (error) {
|
||||
setError('currentPassword', {
|
||||
message: error.message ?? 'No se pudo cambiar la contraseña',
|
||||
message: errorMessage(error, t('security.changeError')),
|
||||
})
|
||||
return
|
||||
}
|
||||
reset({ currentPassword: '', newPassword: '' })
|
||||
setFeedback('Contraseña actualizada.')
|
||||
setFeedback(t('security.updated'))
|
||||
})
|
||||
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-primary">Seguridad</h1>
|
||||
<h1 className="text-2xl font-bold text-primary">{t('security.title')}</h1>
|
||||
<p className="mt-1 text-sm text-foreground/60">
|
||||
Gestioná tu contraseña y tus llaves de acceso (passkeys).
|
||||
{t('security.subtitle')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -69,11 +72,11 @@ export function SecurityPage() {
|
||||
<div className="rounded-xl border border-border bg-surface p-5">
|
||||
<div className="mb-4 flex items-center gap-2">
|
||||
<KeyRound className="size-4 text-accent" />
|
||||
<h2 className="text-base font-semibold text-primary">Cambiar contraseña</h2>
|
||||
<h2 className="text-base font-semibold text-primary">{t('security.changePassword')}</h2>
|
||||
</div>
|
||||
<form onSubmit={onChangePassword} className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="currentPassword">Contraseña actual</Label>
|
||||
<Label htmlFor="currentPassword">{t('security.currentPassword')}</Label>
|
||||
<Input
|
||||
id="currentPassword"
|
||||
type="password"
|
||||
@@ -84,7 +87,7 @@ export function SecurityPage() {
|
||||
<FieldError message={errors.currentPassword?.message} />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="newPassword">Nueva contraseña</Label>
|
||||
<Label htmlFor="newPassword">{t('security.newPassword')}</Label>
|
||||
<Input
|
||||
id="newPassword"
|
||||
type="password"
|
||||
@@ -96,7 +99,7 @@ export function SecurityPage() {
|
||||
</div>
|
||||
<Button type="submit" variant="primary" disabled={isSubmitting}>
|
||||
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||
Actualizar contraseña
|
||||
{t('security.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -105,11 +108,11 @@ export function SecurityPage() {
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Fingerprint className="size-4 text-accent" />
|
||||
<h2 className="text-base font-semibold text-primary">Passkeys</h2>
|
||||
<h2 className="text-base font-semibold text-primary">{t('security.passkeys')}</h2>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={() => void handleAddPasskey()}>
|
||||
<Plus className="size-4" />
|
||||
Registrar
|
||||
{t('security.register')}
|
||||
</Button>
|
||||
</div>
|
||||
<PasskeyList key={passkeyKeys} onRefresh={refreshPasskeys} />
|
||||
|
||||
@@ -2,11 +2,11 @@ import { z } from 'zod'
|
||||
|
||||
export const changePasswordSchema = z
|
||||
.object({
|
||||
currentPassword: z.string().min(1, 'Ingresá tu contraseña actual'),
|
||||
newPassword: z.string().min(8, 'La nueva contraseña debe tener al menos 8 caracteres'),
|
||||
currentPassword: z.string().min(1, 'password.currentPassword'),
|
||||
newPassword: z.string().min(8, 'password.newPasswordMin'),
|
||||
})
|
||||
.refine((v) => v.currentPassword !== v.newPassword, {
|
||||
message: 'La nueva contraseña debe ser distinta',
|
||||
message: 'password.newPasswordDifferent',
|
||||
path: ['newPassword'],
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user