diff --git a/src/modules/todos/components/todo-form.tsx b/src/modules/todos/components/todo-form.tsx index d26d514..9417c4a 100644 --- a/src/modules/todos/components/todo-form.tsx +++ b/src/modules/todos/components/todo-form.tsx @@ -5,6 +5,7 @@ import { Upload, X } from "lucide-react"; import Image from "next/image"; import { useState, useTransition } from "react"; import { useForm } from "react-hook-form"; +import toast from "react-hot-toast"; import type { z } from "zod"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; @@ -108,6 +109,22 @@ export function TodoForm({ const handleImageChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { + // Validate file size (5MB = 5 * 1024 * 1024 bytes) + const maxSize = 5 * 1024 * 1024; + if (file.size > maxSize) { + toast.error("Image must be less than 5MB"); + e.target.value = ""; // Reset input + return; + } + + // Validate file type + const validTypes = ["image/png", "image/jpeg", "image/jpg"]; + if (!validTypes.includes(file.type)) { + toast.error("Only PNG and JPG images are allowed"); + e.target.value = ""; // Reset input + return; + } + setImageFile(file); const reader = new FileReader(); reader.onloadend = () => {