Language selector on onboarding screen
Fixed docker-compose
This commit is contained in:
39
apps/web/src/features/onboarding/LanguageSwitcher.tsx
Normal file
39
apps/web/src/features/onboarding/LanguageSwitcher.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import { SUPPORTED_LOCALES } from '@gruperly/shared'
|
||||
import { ChevronDown, Languages } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useLocale, type LocalePreference } from '../../i18n'
|
||||
import { LOCALE_NAMES } from '../../i18n/locales'
|
||||
import { useSelectLocale } from '../settings/useSelectLocale'
|
||||
|
||||
const OPTIONS: LocalePreference[] = ['system', ...SUPPORTED_LOCALES]
|
||||
|
||||
/* Selector compacto para el header del onboarding: muestra el código del idioma
|
||||
actual y abre el `<select>` nativo (transparente encima de la píldora), que
|
||||
en mobile es la hoja del sistema. Guarda en la cuenta igual que en Ajustes. */
|
||||
export function LanguageSwitcher() {
|
||||
const { t } = useTranslation('settings')
|
||||
const { preference, locale, device } = useLocale()
|
||||
const select = useSelectLocale(true)
|
||||
|
||||
return (
|
||||
<div className="relative inline-flex items-center gap-1 rounded-full border border-border px-2.5 py-1 text-xs font-semibold text-foreground/70 transition-colors focus-within:ring-2 focus-within:ring-accent hover:bg-primary-soft">
|
||||
<Languages className="size-3.5" aria-hidden="true" />
|
||||
<span aria-hidden="true">{locale.split('-')[0].toUpperCase()}</span>
|
||||
<ChevronDown className="size-3" aria-hidden="true" />
|
||||
<select
|
||||
aria-label={t('language.title')}
|
||||
value={preference}
|
||||
onChange={(event) => select(event.target.value as LocalePreference)}
|
||||
className="absolute inset-0 cursor-pointer appearance-none opacity-0"
|
||||
>
|
||||
{OPTIONS.map((option) => (
|
||||
<option key={option} value={option} lang={option === 'system' ? undefined : option}>
|
||||
{option === 'system'
|
||||
? `${t('language.system')} (${LOCALE_NAMES[device]})`
|
||||
: LOCALE_NAMES[option]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { useAuth } from '../../context/AuthProvider'
|
||||
import { ConfirmationStep } from './ConfirmationStep'
|
||||
import { CountryStep } from './CountryStep'
|
||||
import { FirstGroupStep } from './FirstGroupStep'
|
||||
import { LanguageSwitcher } from './LanguageSwitcher'
|
||||
import { useOnboarding } from './OnboardingProvider'
|
||||
import { PaymentStep } from './PaymentStep'
|
||||
import { PlanStep } from './PlanStep'
|
||||
@@ -108,8 +109,11 @@ export function OnboardingView() {
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex min-h-dvh w-full max-w-md flex-col px-4 pt-8 pb-[calc(3rem+env(safe-area-inset-bottom))] sm:pt-12">
|
||||
<header className="mb-6 flex items-center justify-center">
|
||||
<header className="relative mb-6 flex items-center justify-center">
|
||||
<Logo className="h-6" />
|
||||
<div className="absolute right-0">
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Con Free no se muestran Cobros ni WhatsApp: el stepper refleja solo
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { SUPPORTED_LOCALES } from '@gruperly/shared'
|
||||
import { Check, Languages } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useToast } from '../../components/ui'
|
||||
import { useAuth } from '../../context/AuthProvider'
|
||||
import { useLocale, type LocalePreference } from '../../i18n'
|
||||
import { LOCALE_NAMES } from '../../i18n/locales'
|
||||
import { authClient } from '../../lib/auth-client'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { useSelectLocale } from './useSelectLocale'
|
||||
|
||||
const OPTIONS: LocalePreference[] = ['system', ...SUPPORTED_LOCALES]
|
||||
|
||||
@@ -18,19 +16,8 @@ type LanguageCardProps = {
|
||||
|
||||
export function LanguageCard({ syncProfile = false }: LanguageCardProps) {
|
||||
const { t } = useTranslation('settings')
|
||||
const { preference, device, setPreference } = useLocale()
|
||||
const { user } = useAuth()
|
||||
const toast = useToast()
|
||||
|
||||
const select = (next: LocalePreference) => {
|
||||
if (next === preference) return
|
||||
// Optimista: el idioma cambia ya; la cuenta se actualiza por detrás.
|
||||
setPreference(next)
|
||||
if (!syncProfile || !user) return
|
||||
void authClient.updateUser({ locale: next === 'system' ? null : next }).then(({ error }) => {
|
||||
if (error) toast.error(t('language.saveError'))
|
||||
})
|
||||
}
|
||||
const { preference, device } = useLocale()
|
||||
const select = useSelectLocale(syncProfile)
|
||||
|
||||
return (
|
||||
<div className="divide-y divide-border rounded-xl border border-border bg-surface">
|
||||
|
||||
25
apps/web/src/features/settings/useSelectLocale.ts
Normal file
25
apps/web/src/features/settings/useSelectLocale.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useToast } from '../../components/ui'
|
||||
import { useAuth } from '../../context/AuthProvider'
|
||||
import { useLocale, type LocalePreference } from '../../i18n'
|
||||
import { authClient } from '../../lib/auth-client'
|
||||
|
||||
/** Cambia el idioma al instante y, con `syncProfile`, lo guarda en la cuenta
|
||||
* del profe (Better Auth). La app de alumnos no tiene esa sesión: ahí queda
|
||||
* solo en el dispositivo. */
|
||||
export function useSelectLocale(syncProfile: boolean) {
|
||||
const { t } = useTranslation('settings')
|
||||
const { preference, setPreference } = useLocale()
|
||||
const { user } = useAuth()
|
||||
const toast = useToast()
|
||||
|
||||
return (next: LocalePreference) => {
|
||||
if (next === preference) return
|
||||
// Optimista: el idioma cambia ya; la cuenta se actualiza por detrás.
|
||||
setPreference(next)
|
||||
if (!syncProfile || !user) return
|
||||
void authClient.updateUser({ locale: next === 'system' ? null : next }).then(({ error }) => {
|
||||
if (error) toast.error(t('language.saveError'))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user