refactor(notes): extract title validation into domain service

This commit is contained in:
devcodetools committed 2026-09-13 16:58:12 +02:00
1 parent 557e48116a
commit 5aeeb21f7f
3 files changed
+37 -3

No files matched your search

+4 -3
View File
@@ -3,6 +3,7 @@ import type {
NoteEditorProps,
NoteFormProps,
} from '../interfaces/note-editor'
import { isTitleValid, normalizeTitle } from '../lib/noteValidation'
import DeleteModal from './DeleteModal'
const TITLE_REQUIRED_MESSAGE = 'Le titre est obligatoire.'
@@ -82,15 +83,15 @@ function NoteEditor(props: NoteEditorProps) {
const handleTitleChange = (value: string) => {
setTitle(value)
if (titleMissing && value.trim() !== '') setTitleMissing(false)
if (titleMissing && isTitleValid(value)) setTitleMissing(false)
}
const handleSubmit = () => {
if (title.trim() === '') {
if (!isTitleValid(title)) {
setTitleMissing(true)
return
}
const safeTitle = title.trim()
const safeTitle = normalizeTitle(title)
if (props.mode === 'create') {
props.onCreate(safeTitle, content)
} else {