image upload only

This commit is contained in:
Wind-Explorer
2024-08-13 02:07:32 +08:00
parent 2472d8ca6b
commit 0db0dc5b27

View File

@@ -3,6 +3,7 @@ import config from "../config";
import instance from "../security/http";
import { AxiosResponse } from "axios";
import { Card } from "@nextui-org/react";
import { popToast } from "../utilities";
interface InsertImageProps {
label: string;
@@ -65,6 +66,13 @@ const InsertBillImage: React.FC<InsertImageProps> = ({
) => {
const selectedFiles = event.target.files as FileList;
const file = selectedFiles?.[0] || null;
if (file && !file.type.startsWith("image/")) {
console.error("Selected file is not an image.");
popToast("Please upload only image.", 2);
return;
}
setSelectedFile(file);
setPreviewImage(file ? URL.createObjectURL(file) : "");
onImageSelected(file);