Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the logic for maxFiles count in upload docs step #234

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 21 additions & 3 deletions src/components/dragdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -93,6 +93,20 @@ export const DragDrop = () => {
const [updateStatus] = useUpdateStatusMutation()
const [updateDocument] = useUpdateDocumentMutation()
const [removeDocument] = useRemoveDocumentMutation()
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) {
Expand All @@ -102,6 +116,7 @@ export const DragDrop = () => {
applicationId,
body: { file: fileDetails.file },
}).unwrap()
setMaxFiles((prev) => prev - 1)
break
case 'rejected_file_type':
setFileError(t('documentUpload.dragDropDocumentTypeErrorMsg'))
Expand Down Expand Up @@ -147,6 +162,8 @@ export const DragDrop = () => {
severity: SeverityType.SUCCESS,
message: t('documentUpload.deleteSuccess'),
})
setMaxFiles((prev) => prev + 1)
setFileError('')
})
.catch((errors: any) => {
console.log('errors', errors)
Expand Down Expand Up @@ -205,11 +222,12 @@ export const DragDrop = () => {
inputContent={<DragdropContent />}
inputWithFilesContent={t('documentUpload.title')}
submitButtonContent={t('documentUpload.upload')}
maxFiles={3}
maxFiles={maxFiles}
accept=".pdf"
maxSizeBytes={1000000}
InputComponent={DragdropInput}
PreviewComponent={(props) => <DragdropFiles props={props} />}
disabled={maxFiles === 0}
/>
</div>
<div className="documentsData mx-auto col-9 mt-4">
Expand Down
1 change: 1 addition & 0 deletions src/locales/de/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down