From 2fed2e9cd6ed732e6eb53758f86672bb1c7508ff Mon Sep 17 00:00:00 2001 From: FabrizioCostaMedich Date: Mon, 25 Mar 2024 11:20:32 +0100 Subject: [PATCH] fix(messaging-size): fix message when choosing an oversized file --- assets/translations/en.json | 5 +++-- assets/translations/it.json | 5 +++-- .../tickets/components/MessagingView.tsx | 22 +++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 3ed634b4..c0c121f8 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -248,7 +248,8 @@ "virtualClassroom_plural": "Virtual classrooms", "visualization": "Visualization", "year": "year", - "yesterday": "Yesterday" + "yesterday": "Yesterday", + "sizeExc": "Excessive file size, maximum 32 MB" }, "contactsScreen": { "cancelRecentSearch": "Remove", @@ -505,7 +506,7 @@ "youHaveUnreadMessages": "You have {{total}} unread messages" }, "messagingView": { - "pickFile": "Pick file", + "pickFile": "Pick file max 32MB", "pickFileHint": "From your device or from the cloud", "pickPhoto": "Pick image", "pickPhotoHint": "From your library", diff --git a/assets/translations/it.json b/assets/translations/it.json index 47e3ba16..f4d45387 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -248,7 +248,8 @@ "virtualClassroom_plural": "Virtual classroom", "visualization": "Visualizzazione", "year": "anno", - "yesterday": "Ieri" + "yesterday": "Ieri", + "sizeExc": "File di dimensioni eccessive, massimo 32 MB" }, "contactsScreen": { "cancelRecentSearch": "Rimuovi", @@ -505,7 +506,7 @@ "youHaveUnreadMessages": "Hai {{total}} messaggi non letti" }, "messagingView": { - "pickFile": "Scegli un file", + "pickFile": "Scegli un file max 32MB", "pickFileHint": "Dal tuo dispositivo o dal cloud", "pickPhoto": "Scegli un'immagine", "pickPhotoHint": "Dalla tua galleria", diff --git a/src/features/tickets/components/MessagingView.tsx b/src/features/tickets/components/MessagingView.tsx index bc946377..d8d04726 100644 --- a/src/features/tickets/components/MessagingView.tsx +++ b/src/features/tickets/components/MessagingView.tsx @@ -15,6 +15,7 @@ import { MenuView } from '@react-native-menu/menu'; import { TranslucentView } from '../../../core/components/TranslucentView'; import { IS_IOS } from '../../../core/constants'; +import { useFeedbackContext } from '../../../core/contexts/FeedbackContext'; import { pdfSizes } from '../../courses/constants'; import { Attachment } from '../../services/types/Attachment'; import { AttachmentChip } from './AttachmentChip'; @@ -49,10 +50,27 @@ export const MessagingView = ({ }: Props) => { const { t } = useTranslation(); const styles = useStylesheet(createStyles); - + const types = [ + DocumentPicker.types.pdf, + DocumentPicker.types.images, + DocumentPicker.types.zip, + DocumentPicker.types.doc, + DocumentPicker.types.docx, + DocumentPicker.types.xlsx, + DocumentPicker.types.xls, + ]; + const { setFeedback } = useFeedbackContext(); const pickFile = async () => { - DocumentPicker.pickSingle().then(res => { + DocumentPicker.pickSingle({ type: types }).then(res => { if (!res.name || !res.size || !res.type) return; + if (res.size > 32 * 1000000) { + setFeedback({ + text: t('common.sizeExc'), + isError: true, + isPersistent: false, + }); + return; + } onAttachmentChange({ uri: res.uri,