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'],
|
||||
})
|
||||
|
||||
|
||||
2
apps/web/src/i18n/i18next.d.ts
vendored
2
apps/web/src/i18n/i18next.d.ts
vendored
@@ -18,6 +18,7 @@ import type billing from './locales/es-AR/billing.json'
|
||||
import type mp from './locales/es-AR/mp.json'
|
||||
import type whatsapp from './locales/es-AR/whatsapp.json'
|
||||
import type onboarding from './locales/es-AR/onboarding.json'
|
||||
import type account from './locales/es-AR/account.json'
|
||||
import type validation from './locales/es-AR/validation.json'
|
||||
|
||||
// es-AR es la fuente: una clave que no exista ahí rompe el typecheck.
|
||||
@@ -32,6 +33,7 @@ declare module 'i18next' {
|
||||
pwa: typeof pwa
|
||||
settings: typeof settings
|
||||
validation: typeof validation
|
||||
'account': typeof account
|
||||
'onboarding': typeof onboarding
|
||||
'whatsapp': typeof whatsapp
|
||||
'mp': typeof mp
|
||||
|
||||
25
apps/web/src/i18n/locales/en/account.json
Normal file
25
apps/web/src/i18n/locales/en/account.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"profile": {
|
||||
"title": "My profile",
|
||||
"subtitle": "Your personal details."
|
||||
},
|
||||
"security": {
|
||||
"title": "Security",
|
||||
"subtitle": "Manage your password and passkeys.",
|
||||
"changePassword": "Change password",
|
||||
"currentPassword": "Current password",
|
||||
"newPassword": "New password",
|
||||
"submit": "Update password",
|
||||
"updated": "Password updated.",
|
||||
"changeError": "We couldn't change the password",
|
||||
"passkeys": "Passkeys",
|
||||
"register": "Add",
|
||||
"passkeyAdded": "Passkey added.",
|
||||
"passkeyError": "We couldn't add the passkey: {{reason}}",
|
||||
"unknownError": "unknown error",
|
||||
"noPasskeys": "You haven't added any passkeys yet.",
|
||||
"device": "Device",
|
||||
"securityKey": "Security key",
|
||||
"deletePasskey": "Delete passkey"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,10 @@
|
||||
},
|
||||
"password": {
|
||||
"min": "The password must be at least 8 characters",
|
||||
"mismatch": "The passwords don't match"
|
||||
"mismatch": "The passwords don't match",
|
||||
"currentPassword": "Enter your current password",
|
||||
"newPasswordMin": "The new password must be at least 8 characters",
|
||||
"newPasswordDifferent": "The new password must be different"
|
||||
},
|
||||
"update": {
|
||||
"empty": "Send at least one field to update"
|
||||
|
||||
25
apps/web/src/i18n/locales/es-419/account.json
Normal file
25
apps/web/src/i18n/locales/es-419/account.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"profile": {
|
||||
"title": "Mi perfil",
|
||||
"subtitle": "Tus datos personales."
|
||||
},
|
||||
"security": {
|
||||
"title": "Seguridad",
|
||||
"subtitle": "Administra tu contraseña y tus llaves de acceso (passkeys).",
|
||||
"changePassword": "Cambiar contraseña",
|
||||
"currentPassword": "Contraseña actual",
|
||||
"newPassword": "Nueva contraseña",
|
||||
"submit": "Actualizar contraseña",
|
||||
"updated": "Contraseña actualizada.",
|
||||
"changeError": "No se pudo cambiar la contraseña",
|
||||
"passkeys": "Passkeys",
|
||||
"register": "Registrar",
|
||||
"passkeyAdded": "Passkey registrada correctamente.",
|
||||
"passkeyError": "No se pudo agregar la passkey: {{reason}}",
|
||||
"unknownError": "error desconocido",
|
||||
"noPasskeys": "Todavía no registraste ninguna passkey.",
|
||||
"device": "Dispositivo",
|
||||
"securityKey": "Llave de seguridad",
|
||||
"deletePasskey": "Eliminar passkey"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,10 @@
|
||||
},
|
||||
"password": {
|
||||
"min": "La contraseña debe tener al menos 8 caracteres",
|
||||
"mismatch": "Las contraseñas no coinciden"
|
||||
"mismatch": "Las contraseñas no coinciden",
|
||||
"currentPassword": "Ingresa tu contraseña actual",
|
||||
"newPasswordMin": "La nueva contraseña debe tener al menos 8 caracteres",
|
||||
"newPasswordDifferent": "La nueva contraseña debe ser distinta"
|
||||
},
|
||||
"update": {
|
||||
"empty": "Envía al menos un campo para actualizar"
|
||||
|
||||
25
apps/web/src/i18n/locales/es-AR/account.json
Normal file
25
apps/web/src/i18n/locales/es-AR/account.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"profile": {
|
||||
"title": "Mi perfil",
|
||||
"subtitle": "Tus datos personales."
|
||||
},
|
||||
"security": {
|
||||
"title": "Seguridad",
|
||||
"subtitle": "Gestioná tu contraseña y tus llaves de acceso (passkeys).",
|
||||
"changePassword": "Cambiar contraseña",
|
||||
"currentPassword": "Contraseña actual",
|
||||
"newPassword": "Nueva contraseña",
|
||||
"submit": "Actualizar contraseña",
|
||||
"updated": "Contraseña actualizada.",
|
||||
"changeError": "No se pudo cambiar la contraseña",
|
||||
"passkeys": "Passkeys",
|
||||
"register": "Registrar",
|
||||
"passkeyAdded": "Passkey registrada correctamente.",
|
||||
"passkeyError": "No se pudo agregar la passkey: {{reason}}",
|
||||
"unknownError": "error desconocido",
|
||||
"noPasskeys": "Todavía no registraste ninguna passkey.",
|
||||
"device": "Dispositivo",
|
||||
"securityKey": "Llave de seguridad",
|
||||
"deletePasskey": "Eliminar passkey"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,10 @@
|
||||
},
|
||||
"password": {
|
||||
"min": "La contraseña debe tener al menos 8 caracteres",
|
||||
"mismatch": "Las contraseñas no coinciden"
|
||||
"mismatch": "Las contraseñas no coinciden",
|
||||
"currentPassword": "Ingresá tu contraseña actual",
|
||||
"newPasswordMin": "La nueva contraseña debe tener al menos 8 caracteres",
|
||||
"newPasswordDifferent": "La nueva contraseña debe ser distinta"
|
||||
},
|
||||
"update": {
|
||||
"empty": "Enviá al menos un campo para actualizar"
|
||||
|
||||
25
apps/web/src/i18n/locales/pt-BR/account.json
Normal file
25
apps/web/src/i18n/locales/pt-BR/account.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"profile": {
|
||||
"title": "Meu perfil",
|
||||
"subtitle": "Seus dados pessoais."
|
||||
},
|
||||
"security": {
|
||||
"title": "Segurança",
|
||||
"subtitle": "Gerencie sua senha e suas chaves de acesso (passkeys).",
|
||||
"changePassword": "Alterar senha",
|
||||
"currentPassword": "Senha atual",
|
||||
"newPassword": "Nova senha",
|
||||
"submit": "Atualizar senha",
|
||||
"updated": "Senha atualizada.",
|
||||
"changeError": "Não foi possível alterar a senha",
|
||||
"passkeys": "Passkeys",
|
||||
"register": "Cadastrar",
|
||||
"passkeyAdded": "Passkey cadastrada com sucesso.",
|
||||
"passkeyError": "Não foi possível adicionar a passkey: {{reason}}",
|
||||
"unknownError": "erro desconhecido",
|
||||
"noPasskeys": "Você ainda não cadastrou nenhuma passkey.",
|
||||
"device": "Dispositivo",
|
||||
"securityKey": "Chave de segurança",
|
||||
"deletePasskey": "Excluir passkey"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,10 @@
|
||||
},
|
||||
"password": {
|
||||
"min": "A senha deve ter pelo menos 8 caracteres",
|
||||
"mismatch": "As senhas não coincidem"
|
||||
"mismatch": "As senhas não coincidem",
|
||||
"currentPassword": "Informe sua senha atual",
|
||||
"newPasswordMin": "A nova senha deve ter pelo menos 8 caracteres",
|
||||
"newPasswordDifferent": "A nova senha deve ser diferente"
|
||||
},
|
||||
"update": {
|
||||
"empty": "Envie pelo menos um campo para atualizar"
|
||||
|
||||
Reference in New Issue
Block a user