Skip to content

Commit

Permalink
fix(file upload): change error text of uploaded file from byte to mb (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Usmanfee authored Nov 7, 2024
1 parent 11269cf commit bc1179e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
34 changes: 17 additions & 17 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ npm/npmjs/-/resolve/1.22.8, MIT AND ISC, approved, #15315
npm/npmjs/-/resolve/2.0.0-next.5, MIT AND ISC, approved, #3078
npm/npmjs/-/reusify/1.0.4, MIT, approved, clearlydefined
npm/npmjs/-/rimraf/3.0.2, ISC, approved, clearlydefined
npm/npmjs/-/rollup/4.24.0, MIT, approved, clearlydefined
npm/npmjs/-/rollup/4.24.0, MIT AND (ISC AND MIT), approved, #16917
npm/npmjs/-/run-parallel/1.2.0, MIT, approved, clearlydefined
npm/npmjs/-/safe-array-concat/1.1.2, MIT, approved, clearlydefined
npm/npmjs/-/safe-regex-test/1.0.3, MIT, approved, clearlydefined
Expand Down Expand Up @@ -690,22 +690,22 @@ npm/npmjs/@react-hook/latest/1.0.3, MIT, approved, clearlydefined
npm/npmjs/@reduxjs/toolkit/2.2.7, MIT AND (BSD-2-Clause AND ISC AND MIT) AND Apache-2.0, approved, #14170
npm/npmjs/@remix-run/router/1.19.2, MIT, approved, clearlydefined
npm/npmjs/@rollup/pluginutils/5.1.2, MIT, approved, #16428
npm/npmjs/@rollup/rollup-android-arm-eabi/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-android-arm64/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-darwin-arm64/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-darwin-x64/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-arm-gnueabihf/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-arm-musleabihf/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-arm64-gnu/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-arm64-musl/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-powerpc64le-gnu/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-riscv64-gnu/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-s390x-gnu/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-x64-gnu/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-linux-x64-musl/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-win32-arm64-msvc/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-win32-ia32-msvc/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-win32-x64-msvc/4.24.0, MIT, approved, clearlydefined
npm/npmjs/@rollup/rollup-android-arm-eabi/4.24.0, MIT AND (ISC AND MIT), approved, #16904
npm/npmjs/@rollup/rollup-android-arm64/4.24.0, MIT AND (ISC AND MIT), approved, #16918
npm/npmjs/@rollup/rollup-darwin-arm64/4.24.0, MIT AND (ISC AND MIT), approved, #16908
npm/npmjs/@rollup/rollup-darwin-x64/4.24.0, MIT AND (ISC AND MIT), approved, #16901
npm/npmjs/@rollup/rollup-linux-arm-gnueabihf/4.24.0, MIT AND (ISC AND MIT), approved, #16906
npm/npmjs/@rollup/rollup-linux-arm-musleabihf/4.24.0, MIT AND (ISC AND MIT), approved, #16914
npm/npmjs/@rollup/rollup-linux-arm64-gnu/4.24.0, MIT AND (ISC AND MIT), approved, #16910
npm/npmjs/@rollup/rollup-linux-arm64-musl/4.24.0, MIT AND (ISC AND MIT), approved, #16912
npm/npmjs/@rollup/rollup-linux-powerpc64le-gnu/4.24.0, MIT AND (ISC AND MIT), approved, #16916
npm/npmjs/@rollup/rollup-linux-riscv64-gnu/4.24.0, MIT AND (ISC AND MIT), approved, #16907
npm/npmjs/@rollup/rollup-linux-s390x-gnu/4.24.0, MIT AND (ISC AND MIT), approved, #16919
npm/npmjs/@rollup/rollup-linux-x64-gnu/4.24.0, MIT AND (ISC AND MIT), approved, #16915
npm/npmjs/@rollup/rollup-linux-x64-musl/4.24.0, MIT AND (ISC AND MIT), approved, #16911
npm/npmjs/@rollup/rollup-win32-arm64-msvc/4.24.0, MIT AND (ISC AND MIT), approved, #16909
npm/npmjs/@rollup/rollup-win32-ia32-msvc/4.24.0, MIT AND (ISC AND MIT), approved, #16913
npm/npmjs/@rollup/rollup-win32-x64-msvc/4.24.0, MIT AND (ISC AND MIT), approved, #16902
npm/npmjs/@rtsao/scc/1.1.0, MIT, approved, clearlydefined
npm/npmjs/@sinclair/typebox/0.27.8, MIT, approved, clearlydefined
npm/npmjs/@sinonjs/commons/3.0.1, BSD-3-Clause, approved, #12905
Expand Down
5 changes: 4 additions & 1 deletion src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,10 @@
"placeholder": "",
"uploadError": "Not Uploaded",
"uploadSuccess": "Uploaded",
"uploadProgess": "Uploaded % of % files"
"uploadProgess": "Uploaded % of % files",
"error": {
"fileTooLarge": "Datei ist größer als"
}
},
"userRoles": {
"title": "Assigned Catena-X Portal Roles",
Expand Down
5 changes: 4 additions & 1 deletion src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,10 @@
"placeholder": "",
"uploadError": "Not Uploaded",
"uploadSuccess": "Uploaded",
"uploadProgess": "Uploaded % of % files"
"uploadProgess": "Uploaded % of % files",
"error": {
"fileTooLarge": "File is larger than"
}
},
"userRoles": {
"title": "Assigned Catena-X Portal Roles",
Expand Down
14 changes: 13 additions & 1 deletion src/components/shared/basic/Dropzone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { type FunctionComponent, useCallback, useState } from 'react'
import { type Accept, useDropzone } from 'react-dropzone'
import { useTranslation } from 'react-i18next'
import { CONVERT_TO_MB } from 'types/Constants'

export type DropzoneFile = File & Partial<UploadFile>

Expand Down Expand Up @@ -111,6 +112,17 @@ export const Dropzone = ({
[currentFiles, onChange, handleDelete]
)

const handleFileSizeValidator = (file: File) => {
if (!maxFileSize) return null
const fileSizeInMB = (file.size / CONVERT_TO_MB).toFixed(2)
return file.size > maxFileSize
? {
code: 'size-too-large',
message: `${t('shared.dropzone.error.fileTooLarge')} ${fileSizeInMB} MB`,
}
: null
}

const {
getRootProps,
getInputProps,
Expand All @@ -123,7 +135,7 @@ export const Dropzone = ({
maxFiles: isSingleUpload ? 0 : maxFilesToUpload,
accept: acceptFormat,
multiple: !isSingleUpload,
maxSize: maxFileSize,
validator: handleFileSizeValidator,
})

let DropAreaComponent = DefaultDropArea
Expand Down
2 changes: 2 additions & 0 deletions src/types/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,5 @@ export enum HINTS {
COMING_SOON = 'coming_soon',
NEW = 'new',
}

export const CONVERT_TO_MB = 1048576

0 comments on commit bc1179e

Please sign in to comment.