import { IoInformationCircleOutline } from "react-icons/io5"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { useDropzone } from "react-dropzone"; import { HiOutlineUpload } from "react-icons/hi"; import { MdClose } from "react-icons/md"; import { toast } from "sonner"; import { t } from "@/utils"; import CustomImage from "@/components/Common/CustomImage"; const ComponentFour = ({ uploadedImages, setUploadedImages, otherImages, setOtherImages, setStep, handleGoBack, }) => { const onDrop = (acceptedFiles) => { if (acceptedFiles.length == 0) { toast.error(t("wrongFile")); } else { setUploadedImages(acceptedFiles); } }; const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, accept: { "image/jpeg": [".jpeg", ".jpg"], "image/png": [".png"], }, multiple: false, }); const files = () => uploadedImages?.map((file, index) => (
{file.name} {Math.round(file.size / 1024)} KB
)); const removeImage = (index) => { setUploadedImages((prevImages) => prevImages.filter((_, i) => i !== index)); }; const onOtherDrop = (acceptedFiles) => { const currentFilesCount = otherImages.length; // Number of files already uploaded const remainingSlots = 5 - currentFilesCount; // How many more files can be uploaded if (remainingSlots === 0) { // Show error if the limit has been reached toast.error(t("imageLimitExceeded")); return; } if (acceptedFiles.length > remainingSlots) { // Show error if the number of new files exceeds the remaining slots toast.error( t("youCanUpload") + " " + remainingSlots + " " + t("moreImages") ); return; } // Add the new files to the state setOtherImages((prevImages) => [...prevImages, ...acceptedFiles]); }; const { getRootProps: getRootOtheProps, getInputProps: getInputOtherProps, isDragActive: isDragOtherActive, } = useDropzone({ onDrop: onOtherDrop, accept: { "image/jpeg": [".jpeg", ".jpg"], "image/png": [".png"], }, multiple: true, }); const removeOtherImage = (index) => { setOtherImages((prevImages) => prevImages.filter((_, i) => i !== index)); }; const filesOther = () => otherImages && otherImages?.map((file, index) => (
{file.name} {Math.round(file.size / 1024)} KB
)); return (
{t("mainPicture")}
0 ? "none" : "" }} > {isDragActive ? ( {t("dropFiles")} ) : (
{t("dragFiles")} {t("or")}
{t("upload")}
)}
{files()}
{t("otherPicture")}

{t("maxOtherImages")}

= 5 ? "none" : "" }} > {isDragOtherActive ? ( {t("dropFiles")} ) : (
{t("dragFiles")} {t("or")}
{t("upload")}
)}
{filesOther()}
); }; export default ComponentFour;