refactor(front): extract shared utils and rewire pages

This commit is contained in:
Matthieu
2026-02-06 17:16:16 +01:00
parent 1fbd1d1b2e
commit 9ee348fff0
36 changed files with 1686 additions and 2194 deletions

41
app/utils/events.ts Normal file
View File

@@ -0,0 +1,41 @@
/**
* Type-safe event handlers for form inputs.
* These helpers extract values from DOM events in a way that satisfies TypeScript.
*/
/**
* Extract the string value from an input event.
*/
export const getInputValue = (event: Event): string => {
const target = event.target as HTMLInputElement | null
return target?.value ?? ''
}
/**
* Extract the numeric value from an input event.
*/
export const getInputNumber = (event: Event): number => {
const target = event.target as HTMLInputElement | null
const value = target?.value ?? ''
const parsed = parseFloat(value)
return Number.isNaN(parsed) ? 0 : parsed
}
/**
* Extract the checked state from a checkbox event.
*/
export const getCheckboxValue = (event: Event): boolean => {
const target = event.target as HTMLInputElement | null
return target?.checked ?? false
}
/**
* Extract an optional numeric value from an input event (empty string = undefined).
*/
export const getOptionalNumber = (event: Event): number | undefined => {
const target = event.target as HTMLInputElement | null
const value = target?.value ?? ''
if (value.trim() === '') return undefined
const parsed = parseFloat(value)
return Number.isNaN(parsed) ? undefined : parsed
}

View File

@@ -20,8 +20,10 @@ export const maskEmail = (rawValue: string): string => {
return ''
}
const [localPart, domain] = value.split('@')
if (!domain) {
const parts = value.split('@')
const localPart = parts[0] ?? ''
const domain = parts[1]
if (!domain || !localPart) {
return value
}
@@ -29,7 +31,7 @@ export const maskEmail = (rawValue: string): string => {
return `${localPart[0] ?? ''}·@${domain}`
}
const start = localPart[0]
const start = localPart[0] ?? ''
const end = localPart.slice(-1)
const masked = '·'.repeat(Math.max(0, localPart.length - 2))