diff --git a/components/ui/image-upload.tsx b/components/ui/image-upload.tsx index 826585d..3a670f8 100644 --- a/components/ui/image-upload.tsx +++ b/components/ui/image-upload.tsx @@ -1,63 +1,77 @@ -"use client" +"use client"; -import Image from "next/image" -import { useEffect, useState } from "react" -import { ImagePlus, Trash } from "lucide-react" -import { CldUploadWidget } from "next-cloudinary" +import Image from "next/image"; +import { useEffect, useState } from "react"; +import { ImagePlus, Trash } from "lucide-react"; +import { CldUploadWidget } from "next-cloudinary"; -import { Button } from "@/components/ui/button" +import { Button } from "@/components/ui/button"; interface ImageUploadProps { - disabled?: boolean - onChange: (value: string) => void - onRemove: (value: string) => void - value: string[] + disabled?: boolean; + onChange: (value: string) => void; + onRemove: (value: string) => void; + value: string[]; } const ImageUpload: React.FC = ({ disabled, onChange, onRemove, - value + value, }) => { - const [isMounted, setIsMounted] = useState(false) + const [isMounted, setIsMounted] = useState(false); useEffect(() => { - setIsMounted(true) - }, []) + setIsMounted(true); + }, []); const onUpload = (result: any) => { - onChange(result.info.secure_url) - } + // Validate file type (allow only 'jpg', 'png', and 'jpeg') + const allowedFileTypes = ["jpg", "png", "jpeg"]; + const fileType = result.info.format.toLowerCase(); + + if (allowedFileTypes.includes(fileType)) { + onChange(result.info.secure_url); + } else { + // Handle invalid file type (e.g., show a message) + console.error( + "Invalid file type. Please upload a JPG, PNG, or JPEG file." + ); + } + }; if (!isMounted) { - return null + return null; } - + return (
{value.map((url) => ( -
+
-
- Image + Image
))}
{({ open }) => { const onClick = () => { - open() - } + open(); + }; return ( - ) + ); }}
- ) -} + ); +}; -export default ImageUpload \ No newline at end of file +export default ImageUpload; diff --git a/package-lock.json b/package-lock.json index 1e02106..bf2e5c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "ecommerce-admin", "version": "0.1.0", + "hasInstallScript": true, "dependencies": { "@clerk/nextjs": "^4.21.14", "@hookform/resolvers": "^3.1.1",