From 14af0abbbbaf4f55dba70aab3bc3e9190ecca89f Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Thu, 3 Jun 2021 06:09:21 +0530 Subject: [PATCH 1/2] added file type check --- src/libs/actions/Report.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 79d6c99c86e8..53bfa45135c9 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -21,6 +21,7 @@ import Log from '../Log'; import {isReportMessageAttachment, sortReportsByLastVisited} from '../reportUtils'; import Timers from '../Timers'; import {dangerouslyGetReportActionsMaxSequenceNumber, isReportMissingActions} from './ReportActions'; +import Growl from '../Growl'; let currentUserEmail; let currentUserAccountID; @@ -1040,7 +1041,17 @@ function addAction(reportID, text, file) { // the same way report actions can. persist: !isAttachment, }) - .then(({reportAction}) => updateReportWithNewAction(reportID, reportAction)); + .then((response) => { + if (response.jsonCode === 408) { + Growl.show('Upload Failed. File is not supported.', CONST.GROWL.ERROR); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { + [optimisticReportActionID]: null, + }); + console.error(response.message); + return; + } + updateReportWithNewAction(reportID, response.reportAction); + }); } /** From 266fc19b6917e5a468c1eec21458f9e4dd560564 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 4 Jun 2021 08:25:01 +0530 Subject: [PATCH 2/2] localized error --- src/CONST.js | 2 ++ src/components/withLocalize.js | 3 ++- src/languages/en.js | 1 + src/libs/actions/Report.js | 13 ++++++++++++- src/libs/translate.js | 4 +++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 7c0721bad621..257bd0703cdc 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -189,6 +189,8 @@ const CONST = { WARNING: 'warning', DURATION: 2000, }, + + DEFAULT_LOCALE: 'en', }; export default CONST; diff --git a/src/components/withLocalize.js b/src/components/withLocalize.js index 4a45ac62004e..28b9409796d3 100755 --- a/src/components/withLocalize.js +++ b/src/components/withLocalize.js @@ -8,6 +8,7 @@ import {translate} from '../libs/translate'; import DateUtils from '../libs/DateUtils'; import {toLocalPhone, fromLocalPhone} from '../libs/LocalePhoneNumber'; import numberFormat from '../libs/numberFormat'; +import CONST from '../CONST'; const withLocalizePropTypes = { /** Returns translated string for given locale and phrase */ @@ -66,7 +67,7 @@ function withLocalizeHOC(WrappedComponent) { ]), }; WithLocalize.defaultProps = { - preferredLocale: 'en', + preferredLocale: CONST.DEFAULT_LOCALE, forwardedRef: undefined, }; return React.forwardRef((props, ref) => ( diff --git a/src/languages/en.js b/src/languages/en.js index fa4489706212..eb00922f56d7 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -77,6 +77,7 @@ export default { addAttachment: 'Add Attachment', writeSomething: 'Write something...', youAppearToBeOffline: 'You appear to be offline.', + fileUploadFailed: 'Upload Failed. File is not supported.', }, reportActionContextMenu: { copyToClipboard: 'Copy to Clipboard', diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 53bfa45135c9..eded48301edc 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -22,6 +22,7 @@ import {isReportMessageAttachment, sortReportsByLastVisited} from '../reportUtil import Timers from '../Timers'; import {dangerouslyGetReportActionsMaxSequenceNumber, isReportMissingActions} from './ReportActions'; import Growl from '../Growl'; +import {translate} from '../translate'; let currentUserEmail; let currentUserAccountID; @@ -58,6 +59,16 @@ Onyx.connect({ }, }); +let translateLocal = (phrase, variables) => translate(CONST.DEFAULT_LOCALE, phrase, variables); +Onyx.connect({ + key: ONYXKEYS.PREFERRED_LOCALE, + callback: (preferredLocale) => { + if (preferredLocale) { + translateLocal = (phrase, variables) => translate(preferredLocale, phrase, variables); + } + }, +}); + const typingWatchTimers = {}; /** @@ -1043,7 +1054,7 @@ function addAction(reportID, text, file) { }) .then((response) => { if (response.jsonCode === 408) { - Growl.show('Upload Failed. File is not supported.', CONST.GROWL.ERROR); + Growl.show(translateLocal('reportActionCompose.fileUploadFailed'), CONST.GROWL.ERROR); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { [optimisticReportActionID]: null, }); diff --git a/src/libs/translate.js b/src/libs/translate.js index 7560fdc15626..2d548f8acd84 100644 --- a/src/libs/translate.js +++ b/src/libs/translate.js @@ -3,6 +3,7 @@ import Str from 'expensify-common/lib/str'; import Log from './Log'; import Config from '../CONFIG'; import translations from '../languages/translations'; +import CONST from '../CONST'; /** * Return translated string for given locale and phrase @@ -12,7 +13,8 @@ import translations from '../languages/translations'; * @param {Object} [variables] * @returns {String} */ -function translate(locale = 'en', phrase, variables = {}) { +// eslint-disable-next-line no-undef +function translate(locale = CONST.DEFAULT_LOCALE, phrase, variables = {}) { const localeLanguage = locale.substring(0, 2); const fullLocale = lodashGet(translations, locale, {}); const language = lodashGet(translations, localeLanguage, {});