Commit 67de58d9 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Se modifica el como se muestra la preview de la imagen

parent c84f4834
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -4,16 +4,16 @@ import { useDropzone } from "react-dropzone";
import { useState } from 'react';
import "react-toastify/dist/ReactToastify.css";
import { UseFormSetValue } from 'react-hook-form';
import { TownFormValues } from '../../infraestructure/entities/town';
import { Town } from '../../infraestructure/entities/town';

interface props {
  setValue : UseFormSetValue<TownFormValues>
  setValue : UseFormSetValue<Town>
}

export const ImageDropzone = ({setValue}: props) => {
  const MAX_SIZE = 10485760;
  const [preview, setPreview] = useState<string | ArrayBuffer | null>(null);  
  const {fileRejections,getRootProps, getInputProps} = useDropzone(
  const {getRootProps, getInputProps} = useDropzone(
    {
      multiple: false,
      maxSize: MAX_SIZE,
@@ -22,8 +22,6 @@ export const ImageDropzone = ({setValue}: props) => {
        'image/png': []
      },
      onDrop(acceptedFiles, fileRejections) {
        const file = new FileReader;
        
        fileRejections.map(({file, errors}) => (
          toast.error(errors[0].message, {
            position: "bottom-right",
@@ -36,15 +34,11 @@ export const ImageDropzone = ({setValue}: props) => {
            theme: "colored"
            })));
        
        acceptedFiles.map((file)=>{
          {setValue('imageURL',file,{shouldValidate: true})}
        acceptedFiles.forEach((file)=>{
          const preview = URL.createObjectURL(file);
          setValue('imageURL',file,{shouldValidate: true});
          setPreview(preview);
        });

        file.onload = () => {
          setPreview(file.result);
        };

        file.readAsDataURL(acceptedFiles[0]);
      }
    }
  );