feat(app): identity screens and /app shell — auth store, login/signup/reset flows, dashboard, account
- 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
This commit is contained in:
1 parent
0f7292f9b3
commit
c517ea267b
46 files changed
+2798
-11
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { z } from 'zod'
|
||||
import type { OwnProfilePatch } from '@faunosteo/supabase'
|
||||
|
||||
/**
|
||||
* Account forms. Messages are i18n keys; a `|value` suffix carries the
|
||||
* placeholder (`account.error.too_long|80` → {max} = 80).
|
||||
*/
|
||||
function optionalText(max: number) {
|
||||
return z.string().trim().max(max, `account.error.too_long|${max}`)
|
||||
}
|
||||
|
||||
export const personalSchema = z.object({
|
||||
display_name: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'account.error.required')
|
||||
.max(80, 'account.error.too_long|80'),
|
||||
first_name: optionalText(80),
|
||||
last_name: optionalText(80),
|
||||
phone: z
|
||||
.string()
|
||||
.trim()
|
||||
.refine((v) => v === '' || /^\+[1-9][0-9]{6,14}$/.test(v), 'account.error.phone_format'),
|
||||
})
|
||||
export type PersonalValues = z.infer<typeof personalSchema>
|
||||
|
||||
export const professionalSchema = z.object({
|
||||
professional_title: optionalText(80),
|
||||
practice_name: optionalText(120),
|
||||
siret: z
|
||||
.string()
|
||||
.transform((v) => v.replace(/\s+/g, ''))
|
||||
.refine((v) => v === '' || /^[0-9]{14}$/.test(v), 'account.error.siret_format'),
|
||||
})
|
||||
export type ProfessionalValues = z.infer<typeof professionalSchema>
|
||||
|
||||
export const preferencesSchema = z.object({
|
||||
timezone: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'account.error.required')
|
||||
.max(64, 'account.error.too_long|64'),
|
||||
})
|
||||
export type PreferencesValues = z.infer<typeof preferencesSchema>
|
||||
|
||||
/** '' → null: the columns are nullable and refuse empty strings. */
|
||||
function orNull(value: string): string | null {
|
||||
return value === '' ? null : value
|
||||
}
|
||||
|
||||
export function personalPatch(v: PersonalValues): OwnProfilePatch {
|
||||
return {
|
||||
display_name: v.display_name,
|
||||
first_name: orNull(v.first_name),
|
||||
last_name: orNull(v.last_name),
|
||||
phone: orNull(v.phone),
|
||||
}
|
||||
}
|
||||
|
||||
export function professionalPatch(v: ProfessionalValues): OwnProfilePatch {
|
||||
return {
|
||||
professional_title: orNull(v.professional_title),
|
||||
practice_name: orNull(v.practice_name),
|
||||
siret: orNull(v.siret),
|
||||
}
|
||||
}
|
||||
|
||||
export function preferencesPatch(v: PreferencesValues): OwnProfilePatch {
|
||||
return { timezone: v.timezone }
|
||||
}
|
||||
|
||||
/** Splits `key|value` and fills {max}. */
|
||||
export function translateFieldError(
|
||||
t: (key: string) => string,
|
||||
message: string | undefined,
|
||||
): string | undefined {
|
||||
if (!message) return undefined
|
||||
const [key, value] = message.split('|')
|
||||
return value ? t(key).replace('{max}', value) : t(key)
|
||||
}
|
||||
Reference in new issue
Block a user