From 77343762f2e7602d9f3b356394c5bd66e670e712 Mon Sep 17 00:00:00 2001 From: vladislavkeblysh Date: Thu, 29 Feb 2024 10:56:42 +0200 Subject: [PATCH] fix: [AXIMST-545] fixed upload modal error text --- src/generic/modal-dropzone/ModalDropzone.jsx | 5 ++++- .../modal-dropzone/ModalDropzone.test.jsx | 22 +++++++++++++++++++ src/i18n/messages/ar.json | 1 + src/i18n/messages/de.json | 1 + src/i18n/messages/de_DE.json | 1 + src/i18n/messages/es_419.json | 1 + src/i18n/messages/fa_IR.json | 1 + src/i18n/messages/fr.json | 1 + src/i18n/messages/fr_CA.json | 1 + src/i18n/messages/hi.json | 1 + src/i18n/messages/it.json | 1 + src/i18n/messages/it_IT.json | 1 + src/i18n/messages/pt.json | 1 + src/i18n/messages/pt_PT.json | 1 + src/i18n/messages/ru.json | 1 + src/i18n/messages/uk.json | 1 + src/i18n/messages/zh_CN.json | 1 + src/textbooks/textbook-form/TextbookForm.jsx | 5 +++++ src/textbooks/textbook-form/messages.js | 4 ++++ 19 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/generic/modal-dropzone/ModalDropzone.jsx b/src/generic/modal-dropzone/ModalDropzone.jsx index 1448eec446..0fe257097c 100644 --- a/src/generic/modal-dropzone/ModalDropzone.jsx +++ b/src/generic/modal-dropzone/ModalDropzone.jsx @@ -23,6 +23,7 @@ const ModalDropzone = ({ imageHelpText, previewComponent, imageDropzoneText, + invalidFileSizeMore, isOpen, onClose, onCancel, @@ -44,7 +45,7 @@ const ModalDropzone = ({ onChange, onCancel, onClose, fileTypes, onSavingStatus, }); - const invalidSizeMore = intl.formatMessage( + const invalidSizeMore = invalidFileSizeMore || intl.formatMessage( messages.uploadImageDropzoneInvalidSizeMore, { maxSize: maxSize / (1000 * 1000) }, ); @@ -128,6 +129,7 @@ ModalDropzone.defaultProps = { previewComponent: null, imageDropzoneText: '', maxSize: UPLOAD_FILE_MAX_SIZE, + invalidFileSizeMore: '', }; ModalDropzone.propTypes = { @@ -142,6 +144,7 @@ ModalDropzone.propTypes = { onChange: PropTypes.func.isRequired, onSavingStatus: PropTypes.func.isRequired, maxSize: PropTypes.number, + invalidFileSizeMore: PropTypes.string, }; export default ModalDropzone; diff --git a/src/generic/modal-dropzone/ModalDropzone.test.jsx b/src/generic/modal-dropzone/ModalDropzone.test.jsx index 5e3438abff..d6c9b7e198 100644 --- a/src/generic/modal-dropzone/ModalDropzone.test.jsx +++ b/src/generic/modal-dropzone/ModalDropzone.test.jsx @@ -110,4 +110,26 @@ describe('', () => { expect(getByText(expectedErrorMessage)).toBeInTheDocument(); }); }); + + it('displays a custom error message when the file size exceeds the limit', async () => { + const maxSizeInBytes = 20 * 1000 * 1000; + const expectedErrorMessage = 'Custom error message'; + + const { getByText, getByRole } = render( + , + ); + const dropzoneInput = getByRole('presentation', { hidden: true }); + + const file = new File( + [new ArrayBuffer(maxSizeInBytes + 1)], + 'test-file.png', + { type: 'image/png' }, + ); + + userEvent.upload(dropzoneInput.firstChild, file); + + await waitFor(() => { + expect(getByText(expectedErrorMessage)).toBeInTheDocument(); + }); + }); }); diff --git a/src/i18n/messages/ar.json b/src/i18n/messages/ar.json index 729952e313..ce2523d6fd 100644 --- a/src/i18n/messages/ar.json +++ b/src/i18n/messages/ar.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/de.json b/src/i18n/messages/de.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/de.json +++ b/src/i18n/messages/de.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/de_DE.json b/src/i18n/messages/de_DE.json index 8e69a3526b..8e96591efd 100644 --- a/src/i18n/messages/de_DE.json +++ b/src/i18n/messages/de_DE.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/es_419.json b/src/i18n/messages/es_419.json index e540aade69..77ce266b8d 100644 --- a/src/i18n/messages/es_419.json +++ b/src/i18n/messages/es_419.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/fa_IR.json b/src/i18n/messages/fa_IR.json index 3c324a3200..0ed7620ebd 100644 --- a/src/i18n/messages/fa_IR.json +++ b/src/i18n/messages/fa_IR.json @@ -204,6 +204,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/fr.json b/src/i18n/messages/fr.json index 6e4b9bc478..4b8c9639f9 100644 --- a/src/i18n/messages/fr.json +++ b/src/i18n/messages/fr.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/fr_CA.json b/src/i18n/messages/fr_CA.json index 6ad4da61ea..c238ebb87f 100644 --- a/src/i18n/messages/fr_CA.json +++ b/src/i18n/messages/fr_CA.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/hi.json b/src/i18n/messages/hi.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/hi.json +++ b/src/i18n/messages/hi.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/it.json b/src/i18n/messages/it.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/it.json +++ b/src/i18n/messages/it.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/it_IT.json b/src/i18n/messages/it_IT.json index d170c26369..d8d64b7005 100644 --- a/src/i18n/messages/it_IT.json +++ b/src/i18n/messages/it_IT.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/pt.json b/src/i18n/messages/pt.json index d85c0f84e0..d1bfeabc17 100644 --- a/src/i18n/messages/pt.json +++ b/src/i18n/messages/pt.json @@ -1178,6 +1178,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/pt_PT.json b/src/i18n/messages/pt_PT.json index 17d8967124..1d1074fb43 100644 --- a/src/i18n/messages/pt_PT.json +++ b/src/i18n/messages/pt_PT.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/uk.json b/src/i18n/messages/uk.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/uk.json +++ b/src/i18n/messages/uk.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/i18n/messages/zh_CN.json b/src/i18n/messages/zh_CN.json index eb318e4a41..3f9107c501 100644 --- a/src/i18n/messages/zh_CN.json +++ b/src/i18n/messages/zh_CN.json @@ -1182,6 +1182,7 @@ "course-authoring.textbooks.form.upload-modal.title": "Upload a new PDF to “{courseName}”", "course-authoring.textbooks.form.upload-modal.dropzone-text": "Drag and drop your PDF file here or click to upload", "course-authoring.textbooks.form.upload-modal.help-text": "File must be in PDF format", + "course-authoring.textbooks.form.upload-modal.file-size-invalid-text": "File size must be less than {maxSize}MB.", "course-authoring.textbooks.form.delete-modal.title": "Delete “{textbookTitle}”?", "course-authoring.textbooks.form.delete-modal.description": "Deleting a textbook cannot be undone and once deleted any reference to it in your courseware's navigation will also be removed.", "course-authoring.course-unit.xblock.iframe.error.text": "Unit iframe failed to load. Server possibly returned 4xx or 5xx response.", diff --git a/src/textbooks/textbook-form/TextbookForm.jsx b/src/textbooks/textbook-form/TextbookForm.jsx index 7162a199ca..d8e8905478 100644 --- a/src/textbooks/textbook-form/TextbookForm.jsx +++ b/src/textbooks/textbook-form/TextbookForm.jsx @@ -21,6 +21,7 @@ import FormikControl from '../../generic/FormikControl'; import PromptIfDirty from '../../generic/PromptIfDirty'; import ModalDropzone from '../../generic/modal-dropzone/ModalDropzone'; import { useModel } from '../../generic/model-store'; +import { UPLOAD_FILE_MAX_SIZE } from '../../constants'; import textbookFormValidationSchema from './validations'; import messages from './messages'; @@ -162,6 +163,10 @@ const TextbookForm = ({ imageDropzoneText={intl.formatMessage(messages.uploadModalDropzoneText)} imageHelpText={intl.formatMessage(messages.uploadModalHelperText)} onSavingStatus={onSavingStatus} + invalidFileSizeMore={intl.formatMessage( + messages.uploadModalFileInvalidSizeText, + { maxSize: UPLOAD_FILE_MAX_SIZE / (1000 * 1000) }, + )} previewComponent={( )} diff --git a/src/textbooks/textbook-form/messages.js b/src/textbooks/textbook-form/messages.js index 7d5c2bdff2..88ace3d4bf 100644 --- a/src/textbooks/textbook-form/messages.js +++ b/src/textbooks/textbook-form/messages.js @@ -93,6 +93,10 @@ const messages = defineMessages({ id: 'course-authoring.textbooks.form.upload-modal.help-text', defaultMessage: 'File must be in PDF format', }, + uploadModalFileInvalidSizeText: { + id: 'course-authoring.textbooks.form.upload-modal.file-size-invalid-text', + defaultMessage: 'File size must be less than {maxSize}MB.', + }, }); export default messages;