import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { useNavigate, Link } from 'react-router-dom'; import { useBoards } from '../hooks/useBoards'; import { useToast } from '../context/toasts/useToast'; const boardSchema = z.object({ name: z .string() .min(1, 'Board name is required') .max(100, 'Board name must be less than 100 characters'), description: z.string().max(500, 'Description must be less than 500 characters').optional(), }); type BoardFormData = z.infer; export function BoardCreate() { const navigate = useNavigate(); const { createBoard } = useBoards(); const { addNotification } = useToast(); const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(boardSchema), }); const onSubmit = async (data: BoardFormData) => { try { const newBoard = await createBoard(data); addNotification({ type: 'success', title: 'Board Created', message: `Board "${newBoard.name}" created successfully.`, duration: 3000, }); navigate(`/boards/${newBoard.id}`); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to create board'; addNotification({ type: 'error', title: 'Error Creating Board', message: errorMessage, duration: 5000, }); } }; return (
← Back to Boards

Create New Board

{errors.name &&

{errors.name.message}

}