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

File upload failure checking #3332

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ const CONST = {
WARNING: 'warning',
DURATION: 2000,
},

DEFAULT_LOCALE: 'en',
};

export default CONST;
3 changes: 2 additions & 1 deletion src/components/withLocalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -66,7 +67,7 @@ function withLocalizeHOC(WrappedComponent) {
]),
};
WithLocalize.defaultProps = {
preferredLocale: 'en',
preferredLocale: CONST.DEFAULT_LOCALE,
forwardedRef: undefined,
};
return React.forwardRef((props, ref) => (
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
24 changes: 23 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Log from '../Log';
import {isReportMessageAttachment, sortReportsByLastVisited} from '../reportUtils';
import Timers from '../Timers';
import {dangerouslyGetReportActionsMaxSequenceNumber, isReportMissingActions} from './ReportActions';
import Growl from '../Growl';
import {translate} from '../translate';

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -57,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 = {};

/**
Expand Down Expand Up @@ -1040,7 +1052,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(translateLocal('reportActionCompose.fileUploadFailed'), CONST.GROWL.ERROR);
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {
[optimisticReportActionID]: null,
});
console.error(response.message);
return;
}
updateReportWithNewAction(reportID, response.reportAction);
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/libs/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, {});
Expand Down