Barazo default frontend barazo.forum
at main 39 lines 1.0 kB view raw
1/** 2 * TopicForm validation logic and types. 3 * @see specs/prd-web.md Section 4 (Editor Components) 4 */ 5 6export interface TopicFormValues { 7 title: string 8 content: string 9 category: string 10 tags?: string[] 11 crossPostBluesky?: boolean 12 crossPostFrontpage?: boolean 13} 14 15export interface FormErrors { 16 title?: string 17 content?: string 18 category?: string 19} 20 21export function validateTopicForm(values: TopicFormValues): FormErrors { 22 const errors: FormErrors = {} 23 if (!values.title.trim()) { 24 errors.title = 'Title is required' 25 } else if (values.title.trim().length < 3) { 26 errors.title = 'Title must be at least 3 characters' 27 } else if (values.title.trim().length > 200) { 28 errors.title = 'Title must be at most 200 characters' 29 } 30 if (!values.content.trim()) { 31 errors.content = 'Content is required' 32 } else if (values.content.trim().length < 10) { 33 errors.content = 'Content must be at least 10 characters' 34 } 35 if (!values.category) { 36 errors.category = 'Category is required' 37 } 38 return errors 39}