Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/modules/todos/components/todo-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -108,6 +109,22 @@ export function TodoForm({
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
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 = () => {
Expand Down