) => {
+ setIsUploaded(false);
+ setError(null);
if (disabled) return null;
e.preventDefault();
const transferFiles = e.dataTransfer.files;
@@ -86,8 +128,24 @@ export const FileLoader = ({
const file = Array.from(transferFiles);
if (!multiply) {
+ if (maxFileKBSize && file[0].size / 1024 > maxFileKBSize) {
+ setError('ErrorWeight');
+ return;
+ }
+ try {
+ const { width, height } = await getImageDimensions(file[0]);
+ if (width !== height) {
+ setError('ErrorSize');
+ return;
+ }
+ } catch {
+ setError('ErrorSize');
+ return;
+ }
+
setFiles([file[0]]);
onChange([file[0]]);
+ setIsUploaded(true);
return;
}
@@ -115,15 +173,22 @@ export const FileLoader = ({
{
[style.active]: isDragActive,
[style.disabled]: disabled,
+ [style.error]: error,
+ [style['is-uploaded']]: isUploaded,
},
className,
)}
>
{isDragDropEnabled && (
<>
-
-

-
+ {!isUploaded && !error && (
+
+

+
+ )}
+
+ {error && }
+ {isUploaded && }
{t(Translation.FILE_LOADER_LINK)}
@@ -132,10 +197,71 @@ export const FileLoader = ({
{t(Translation.FILE_LOADER_TEXT)} {fileTypeText}
-
- {extensionsText}
- {maxFileMBSize && ` (${t(Translation.FILE_LOADER_LIMIT, { maxFileMBSize })})`}
-
+
+ {error === 'ErrorWeight' && (
+ <>
+
+ {t(Translation.FILE_LOADER_ERROR_WEIGHT, { maxFileKBSize })}
+
+
+
+ {t(Translation.FILE_LOADER_ERROR_COMPRESS)}
+
+ e.stopPropagation()}
+ rel="noopener noreferrer"
+ >
+ iloveimg.com/compress-image
+
+
+ >
+ )}
+ {error === 'ErrorSize' && (
+ <>
+
+ {t(Translation.FILE_LOADER_ERROR_SIZE)}
+
+
+
+ {t(Translation.FILE_LOADER_ERROR_CROP)}
+
+ e.stopPropagation()}
+ rel="noopener noreferrer"
+ >
+ iloveimg.com/crop-image
+
+
+ >
+ )}
+
+ {!error && (
+ <>
+ {isUploaded && (
+
+ {t(Translation.FILE_LOADER_UPLOADED)}
+
+ )}
+
+
+ {extensionsText}
+ {maxFileKBSize && ` (${t(Translation.FILE_LOADER_LIMIT, { maxFileKBSize })})`}
+
+
+ {t(Translation.FILE_LOADER_SIZE)}
+
+
+ {t(Translation.FILE_LOADER_SQUARE)}
+
+ >
+ )}
+
>
)}
{
@@ -80,7 +80,7 @@ export const ImageLoaderWithoutCropper = ({