update accept UploadImageModal

This commit is contained in:
ArtChaos189 2023-12-16 13:03:23 +03:00
parent 9ce829f98f
commit 194c3aade5
2 changed files with 16 additions and 2 deletions

@ -4,14 +4,23 @@ import SearchIcon from "../../../assets/icons/SearchIcon";
import UnsplashIcon from "../../../assets/icons/Unsplash.svg"; import UnsplashIcon from "../../../assets/icons/Unsplash.svg";
import { useRef, useState, type DragEvent } from "react"; import { useRef, useState, type DragEvent } from "react";
type ImageFormat = "jpg" | "jpeg" | "png" | "gif";
interface ModalkaProps { interface ModalkaProps {
isOpen: boolean; isOpen: boolean;
onClose: () => void; onClose: () => void;
handleImageChange: (file: File) => void; handleImageChange: (file: File) => void;
description?: string; description?: string;
accept?: ImageFormat[];
} }
export const UploadImageModal: React.FC<ModalkaProps> = ({ handleImageChange, isOpen, onClose, description }) => { export const UploadImageModal: React.FC<ModalkaProps> = ({
handleImageChange,
isOpen,
onClose,
accept,
description,
}) => {
const theme = useTheme(); const theme = useTheme();
const dropZone = useRef<HTMLDivElement>(null); const dropZone = useRef<HTMLDivElement>(null);
const [ready, setReady] = useState(false); const [ready, setReady] = useState(false);
@ -31,6 +40,10 @@ export const UploadImageModal: React.FC<ModalkaProps> = ({ handleImageChange, is
handleImageChange(file); handleImageChange(file);
}; };
const acceptedFormats = accept ? accept.map((format) => "." + format).join(", ") : "";
console.log(acceptedFormats);
return ( return (
<Modal <Modal
open={isOpen} open={isOpen}
@ -67,7 +80,7 @@ export const UploadImageModal: React.FC<ModalkaProps> = ({ handleImageChange, is
<input <input
onChange={(event) => event.target.files?.[0] && handleImageChange(event.target.files[0])} onChange={(event) => event.target.files?.[0] && handleImageChange(event.target.files[0])}
hidden hidden
accept=".jpg, .jpeg, .png" accept={acceptedFormats || ".jpg, .jpeg, .png , .gif"}
multiple multiple
type="file" type="file"
data-cy="upload-image-input" data-cy="upload-image-input"

@ -52,6 +52,7 @@ export default function FaviconDropZone({ imageUrl, onImageUploadClick, onDelete
onClose={closeImageUploadModal} onClose={closeImageUploadModal}
handleImageChange={handleImageUpload} handleImageChange={handleImageUpload}
description="Принимает JPG, PNG — максимум 5mb" description="Принимает JPG, PNG — максимум 5mb"
accept={["jpeg", "jpg", "png"]}
/> />
<Box <Box
onDragEnter={() => !imageUrl && setIsDropReady(true)} onDragEnter={() => !imageUrl && setIsDropReady(true)}