diff --git a/frontend/src/components/kanban/CreateCardModal.tsx b/frontend/src/components/kanban/CreateCardModal.tsx new file mode 100644 index 0000000..09eba9c --- /dev/null +++ b/frontend/src/components/kanban/CreateCardModal.tsx @@ -0,0 +1,120 @@ +import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { z } from 'zod'; +import { ModalContentProps } from '../../types'; +import { useToast } from '../../context/toasts/useToast'; + +const cardSchema = z.object({ + name: z + .string() + .min(1, 'Card name is required') + .max(100, 'Card name must be less than 100 characters'), + description: z.string().max(2000, 'Description must be less than 2000 characters').optional(), +}); + +type CardFormData = z.infer; + +interface CreateCardModalProps extends ModalContentProps { + onCreate: (data: { name: string; description?: string }) => Promise; +} + +export function CreateCardModal({ onClose, onCreate }: CreateCardModalProps) { + const { addNotification } = useToast(); + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: zodResolver(cardSchema), + }); + + const onSubmit = async (data: CardFormData) => { + try { + await onCreate(data); + onClose(); + } catch (err) { + const errorMessage = err instanceof Error ? err.message : 'Failed to create card'; + addNotification({ + type: 'error', + title: 'Error Creating Card', + message: errorMessage, + duration: 5000, + }); + } + }; + + return ( +
+
+ + +
+ +
+
+ + + {errors.name &&

{errors.name.message}

} +
+ +
+ +