Skip to content

Commit

Permalink
fix: [AXIMST-545] fixed upload modal error text
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislavkeblysh committed Feb 29, 2024
1 parent 7efcb22 commit 7734376
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/generic/modal-dropzone/ModalDropzone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ModalDropzone = ({
imageHelpText,
previewComponent,
imageDropzoneText,
invalidFileSizeMore,
isOpen,
onClose,
onCancel,
Expand All @@ -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) },
);
Expand Down Expand Up @@ -128,6 +129,7 @@ ModalDropzone.defaultProps = {
previewComponent: null,
imageDropzoneText: '',
maxSize: UPLOAD_FILE_MAX_SIZE,
invalidFileSizeMore: '',
};

ModalDropzone.propTypes = {
Expand All @@ -142,6 +144,7 @@ ModalDropzone.propTypes = {
onChange: PropTypes.func.isRequired,
onSavingStatus: PropTypes.func.isRequired,
maxSize: PropTypes.number,
invalidFileSizeMore: PropTypes.string,
};

export default ModalDropzone;
22 changes: 22 additions & 0 deletions src/generic/modal-dropzone/ModalDropzone.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,26 @@ describe('<ModalDropzone />', () => {
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(
<RootWrapper {...props} maxSize={maxSizeInBytes} invalidFileSizeMore={expectedErrorMessage} />,
);
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();
});
});
});
1 change: 1 addition & 0 deletions src/i18n/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/es_419.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/fa_IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/fr_CA.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/pt_PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 5 additions & 0 deletions src/textbooks/textbook-form/TextbookForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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={(
<Icon src={PdfIcon} className="modal-preview-icon" />
)}
Expand Down
4 changes: 4 additions & 0 deletions src/textbooks/textbook-form/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 7734376

Please sign in to comment.