- state/authStore: session subscription (initialize + onAuthStateChange), profile + roles load, recovery flag, URL failure; services/localeSync: profiles.locale <-> localeStore - routes: /login, /signup, /forgot-password, /reset-password, /auth/callback; guards RequireAuth (next=) and RedirectIfSignedIn; /app (dashboard), /app/account behind the guard - shell: AppLayout (desktop sidebar, light top bar, mobile drawer), SidebarNav, UserBadge, SignOutButton - account: personal / professional / preferences / security sections, one save each, Zod validation with i18n keys - ui: Icon, FormField, Notice, ButtonLink (buttonClassName shared), PasswordField, OAuthButtons (config-driven) - Home header: Mon espace / Se connecter when Supabase is configured; local tool routes untouched - i18n: auth.*, shell.*, dashboard.*, account.*, home.space.* in fr + en
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import type { Profile } from '@faunosteo/supabase'
|
|
import FormField from '@/components/ui/FormField'
|
|
import Select from '@/components/ui/Select'
|
|
import SaveRow from './SaveRow'
|
|
import SectionCard from './SectionCard'
|
|
import {
|
|
preferencesPatch,
|
|
preferencesSchema,
|
|
translateFieldError,
|
|
} from '@/account/validation'
|
|
import { useProfileForm } from '@/account/useProfileForm'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import type { Locale } from '@/i18n/types'
|
|
import { useT } from '@/i18n/useT'
|
|
|
|
const LOCALES: { value: Locale; labelKey: string }[] = [
|
|
{ value: 'fr', labelKey: 'lang.switch_to_fr' },
|
|
{ value: 'en', labelKey: 'lang.switch_to_en' },
|
|
]
|
|
|
|
/** Browser list when available, else the current value alone. */
|
|
function timezoneOptions(current: string): string[] {
|
|
const intl = Intl as unknown as { supportedValuesOf?: (key: string) => string[] }
|
|
const list = intl.supportedValuesOf?.('timeZone') ?? []
|
|
return list.includes(current) ? list : [current, ...list]
|
|
}
|
|
|
|
/**
|
|
* Language is saved through the locale store (the sync writes profiles.locale)
|
|
* so switching here and in the header behave the same. Timezone saves directly.
|
|
*/
|
|
export default function PreferencesForm({ profile }: { profile: Profile }) {
|
|
const t = useT()
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const setLocale = useLocaleStore((s) => s.setLocale)
|
|
const form = useProfileForm(
|
|
{ timezone: profile.timezone },
|
|
preferencesSchema,
|
|
preferencesPatch,
|
|
)
|
|
|
|
return (
|
|
<SectionCard
|
|
id="preferences"
|
|
title={t('account.preferences.title')}
|
|
description={t('account.preferences.description')}
|
|
>
|
|
<form onSubmit={form.submit} noValidate className="space-y-4">
|
|
<FormField id="locale" label={t('account.preferences.language')}>
|
|
<Select
|
|
id="locale"
|
|
value={locale}
|
|
onChange={(e) => setLocale(e.target.value as Locale)}
|
|
>
|
|
{LOCALES.map((item) => (
|
|
<option key={item.value} value={item.value}>
|
|
{t(item.labelKey)}
|
|
</option>
|
|
))}
|
|
</Select>
|
|
</FormField>
|
|
<FormField
|
|
id="timezone"
|
|
label={t('account.preferences.timezone')}
|
|
hint={t('account.preferences.timezone_hint')}
|
|
error={translateFieldError(t, form.errors.timezone)}
|
|
>
|
|
<Select id="timezone" value={form.values.timezone} onChange={form.field('timezone')}>
|
|
{timezoneOptions(form.values.timezone).map((tz) => (
|
|
<option key={tz} value={tz}>
|
|
{tz}
|
|
</option>
|
|
))}
|
|
</Select>
|
|
</FormField>
|
|
<SaveRow state={form.state} />
|
|
</form>
|
|
</SectionCard>
|
|
)
|
|
}
|