diff --git a/src/components/NoteManager/components/NewNote.tsx b/src/components/NoteManager/components/NewNote.tsx index 8c7aaa6c..409b1264 100644 --- a/src/components/NoteManager/components/NewNote.tsx +++ b/src/components/NoteManager/components/NewNote.tsx @@ -20,17 +20,27 @@ type NewNoteProps = { export const NewNote = ({ version, onCancel, onSave, selectionStart, selectionEnd }: NewNoteProps) => { const [noteContentError, setNoteContentError] = useState(null); + const [noteLabelsError, setNoteLabelsError] = useState(null); const [labels, setLabels] = useState(["local"]); const latestOnCancel = useLatestCallback(onCancel); const latestOnSave = useLatestCallback(onSave); + const handleLabelsChange = useCallback((nextLabels: string[]) => { + setLabels(nextLabels); + if (nextLabels.length > 0) { + setNoteLabelsError(null); + } + }, []); + const handleCancelClick = useCallback(() => { latestOnCancel.current(); }, [latestOnCancel]); const handleSaveClick = useCallback(() => { const noteContent = textAreaRef.current?.value ?? ""; + setNoteContentError(null); + setNoteLabelsError(null); const mathValidationError = validateMath(noteContent); if (mathValidationError) { @@ -41,6 +51,10 @@ export const NewNote = ({ version, onCancel, onSave, selectionStart, selectionEn setNoteContentError("Note content cannot be empty"); return; } + if (labels.length === 0) { + setNoteLabelsError("Select at least one label"); + return; + } latestOnSave.current({ noteContent, labels }); }, [latestOnSave, labels]); @@ -56,7 +70,7 @@ export const NewNote = ({ version, onCancel, onSave, selectionStart, selectionEn noteDirty, currentVersionLink, handleCancelClick, - handleNoteLabelsChange: setLabels, + handleNoteLabelsChange: handleLabelsChange, handleSaveClick, originalVersionLink, selectionStart, @@ -83,6 +97,7 @@ export const NewNote = ({ version, onCancel, onSave, selectionStart, selectionEn /> {noteContentError ?
{noteContentError}
: null} + {noteLabelsError ?
{noteLabelsError}
: null}