From 6b83e1955bf1b55dcc0b8a8af458a19e94949d7a Mon Sep 17 00:00:00 2001 From: shubham vaidya Date: Mon, 29 Jul 2024 10:16:51 +0530 Subject: [PATCH 1/3] fix: updated the logic for maxFiles count in upload docs step --- src/components/dragdrop.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/dragdrop.tsx b/src/components/dragdrop.tsx index d5a758de..a7d84eb9 100644 --- a/src/components/dragdrop.tsx +++ b/src/components/dragdrop.tsx @@ -79,7 +79,7 @@ export const DragDrop = () => { const { data: status } = useFetchApplicationsQuery() const obj = status?.[status.length - 1] const applicationId = obj?.applicationId - + const MAX_FILES = 3; const [fileError, setFileError] = useState('') const [deleteDocResponse, setDeleteDocResponse] = useState({ severity: SeverityType.ERROR, @@ -93,6 +93,9 @@ export const DragDrop = () => { const [updateStatus] = useUpdateStatusMutation() const [updateDocument] = useUpdateDocumentMutation() const [removeDocument] = useRemoveDocumentMutation() + const [maxFiles, setMaxFiles] = useState( + documents?.length > 0 ? MAX_FILES - documents.length : MAX_FILES + ) const manageFileStatus = async (fileDetails: FileStatus) => { switch (fileDetails.stats) { @@ -102,6 +105,7 @@ export const DragDrop = () => { applicationId, body: { file: fileDetails.file }, }).unwrap() + setMaxFiles((prev) => prev - 1) break case 'rejected_file_type': setFileError(t('documentUpload.dragDropDocumentTypeErrorMsg')) @@ -147,6 +151,7 @@ export const DragDrop = () => { severity: SeverityType.SUCCESS, message: t('documentUpload.deleteSuccess'), }) + setMaxFiles((prev) => prev + 1) }) .catch((errors: any) => { console.log('errors', errors) @@ -205,11 +210,12 @@ export const DragDrop = () => { inputContent={} inputWithFilesContent={t('documentUpload.title')} submitButtonContent={t('documentUpload.upload')} - maxFiles={3} + maxFiles={maxFiles} accept=".pdf" maxSizeBytes={1000000} InputComponent={DragdropInput} PreviewComponent={(props) => } + disabled={maxFiles === 0} />
From 388dc93266bf8045d35c1af58771ca4bc649a68f Mon Sep 17 00:00:00 2001 From: shubham vaidya Date: Mon, 29 Jul 2024 13:56:42 +0530 Subject: [PATCH 2/3] fix: updated translations files --- src/components/dragdrop.tsx | 22 +++++++++++++++++----- src/locales/de/translations.json | 1 + src/locales/en/translations.json | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/dragdrop.tsx b/src/components/dragdrop.tsx index a7d84eb9..2cd8dad2 100644 --- a/src/components/dragdrop.tsx +++ b/src/components/dragdrop.tsx @@ -22,7 +22,7 @@ import Dropzone, { type IFileWithMeta } from 'react-dropzone-uploader' import 'react-dropzone-uploader/dist/styles.css' import { useTranslation } from 'react-i18next' import { FooterButton } from './footerButton' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useDispatch, useSelector } from 'react-redux' import { DragdropFiles } from './dragdropFiles' import DragdropLayout from './dragdropLayout' @@ -79,7 +79,7 @@ export const DragDrop = () => { const { data: status } = useFetchApplicationsQuery() const obj = status?.[status.length - 1] const applicationId = obj?.applicationId - const MAX_FILES = 3; + const MAX_FILES = 3 const [fileError, setFileError] = useState('') const [deleteDocResponse, setDeleteDocResponse] = useState({ severity: SeverityType.ERROR, @@ -93,9 +93,20 @@ export const DragDrop = () => { const [updateStatus] = useUpdateStatusMutation() const [updateDocument] = useUpdateDocumentMutation() const [removeDocument] = useRemoveDocumentMutation() - const [maxFiles, setMaxFiles] = useState( - documents?.length > 0 ? MAX_FILES - documents.length : MAX_FILES - ) + const [maxFiles, setMaxFiles] = useState(MAX_FILES) + + useEffect(() => { + if (documents?.length >= 0) { + const currentMaxFiles = + documents?.length > 0 ? MAX_FILES - documents?.length : MAX_FILES + setMaxFiles(currentMaxFiles) + + documents?.length === MAX_FILES && + setFileError( + t('documentUpload.dragDropExceedFilesCountErrorMsg', { MAX_FILES }) + ) + } + }, [documents]) const manageFileStatus = async (fileDetails: FileStatus) => { switch (fileDetails.stats) { @@ -152,6 +163,7 @@ export const DragDrop = () => { message: t('documentUpload.deleteSuccess'), }) setMaxFiles((prev) => prev + 1) + setFileError('') }) .catch((errors: any) => { console.log('errors', errors) diff --git a/src/locales/de/translations.json b/src/locales/de/translations.json index 07c77a3d..29192553 100644 --- a/src/locales/de/translations.json +++ b/src/locales/de/translations.json @@ -129,6 +129,7 @@ "dragDropSpanCaption": "Dateien durchsuchen", "dragDropExceedSizeErrorMsg": "Please select another document. The maximum upload size is limited to 1MB", "dragDropDocumentTypeErrorMsg": "The selected document type is not supported. Please upload a document with the type .pdf", + "dragDropExceedFilesCountErrorMsg": "Sie können maximal {{MAX_FILES}} Dokumente hochladen.", "or": "oder", "upload": "Hochladen", "uploadStatusDone": "Done", diff --git a/src/locales/en/translations.json b/src/locales/en/translations.json index 745b4650..9d95eab5 100644 --- a/src/locales/en/translations.json +++ b/src/locales/en/translations.json @@ -129,6 +129,7 @@ "dragDropSpanCaption": "browse files", "dragDropExceedSizeErrorMsg": "Please select another document. The maximum upload size is limited to 1MB", "dragDropDocumentTypeErrorMsg": "The selected document type is not supported. Please upload a document with the type .pdf", + "dragDropExceedFilesCountErrorMsg": "You can only upload up to {{MAX_FILES}} documents.", "or": "or", "upload": "Upload", "uploadStatusDone": "Done", From 89cbf73134de9c31350381b28f0290555f662199 Mon Sep 17 00:00:00 2001 From: shubhamv-ss Date: Thu, 8 Aug 2024 15:02:37 +0530 Subject: [PATCH 3/3] fix: changelog file updated --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17543d49..9dbf7b56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## unreleased + +### Bugfix + +- updated the logic for maxFiles count in upload docs step [#234](https://github.com/eclipse-tractusx/portal-frontend-registration/pull/234) + ## 2.0.1 ### Change