Skip to content
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
8 changes: 6 additions & 2 deletions src/components/OfflineWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ function applyStrikeThrough(children) {

const OfflineWithFeedback = (props) => {
const hasErrors = !_.isEmpty(props.errors);

// Some errors have a null message. This is used to apply opacity only and to avoid showing redundant messages.
const errorMessages = _.omit(props.errors, (e) => e === null);
const hasErrorMessages = !_.isEmpty(errorMessages);
Comment thread
therealsujitk marked this conversation as resolved.
const isOfflinePendingAction = props.network.isOffline && props.pendingAction;
const isUpdateOrDeleteError = hasErrors && (props.pendingAction === 'delete' || props.pendingAction === 'update');
const isAddError = hasErrors && props.pendingAction === 'add';
Expand All @@ -111,11 +115,11 @@ const OfflineWithFeedback = (props) => {
{children}
</View>
)}
{props.shouldShowErrorMessages && hasErrors && (
{props.shouldShowErrorMessages && hasErrorMessages && (
<View style={StyleUtils.combineStyles(styles.offlineFeedback.error, props.errorRowStyles)}>
<DotIndicatorMessage
style={[styles.flex1]}
messages={props.errors}
messages={errorMessages}
type="error"
/>
<Tooltip text={props.translate('common.close')}>
Expand Down
98 changes: 63 additions & 35 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ function buildOnyxDataForMoneyRequest(
[chatCreatedAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
[reportPreviewAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
},
Comment thread
therealsujitk marked this conversation as resolved.
}
: {}),
[reportPreviewAction.reportActionID]: {
created: reportPreviewAction.created,
},
: {
[reportPreviewAction.reportActionID]: {
created: reportPreviewAction.created,
},
}),
Comment thread
therealsujitk marked this conversation as resolved.
},
},
{
Expand All @@ -237,6 +241,9 @@ function buildOnyxDataForMoneyRequest(
[iouCreatedAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
[iouAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
},
Comment thread
therealsujitk marked this conversation as resolved.
}
: {
[iouAction.reportActionID]: {
Expand Down Expand Up @@ -470,15 +477,6 @@ function createSplitsAndOnyxData(participants, currentUserLogin, amount, comment
}

const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${groupChatReport.reportID}`,
value: {
[groupIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${groupTransaction.transactionID}`,
Expand All @@ -488,16 +486,37 @@ function createSplitsAndOnyxData(participants, currentUserLogin, amount, comment
},
];

if (!existingGroupChatReport) {
if (existingGroupChatReport) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${groupChatReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${groupChatReport.reportID}`,
value: {
errorFields: {
createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'),
[groupIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'),
},
},
});
} else {
failureData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${groupChatReport.reportID}`,
value: {
errorFields: {
createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${groupChatReport.reportID}`,
value: {
[groupIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
},
},
},
);
}

// Loop through participants creating individual chats, iouReports and reportActionIDs as needed
Expand Down Expand Up @@ -910,15 +929,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
];

const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`,
value: {
[optimisticIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`,
Expand All @@ -943,21 +953,39 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
key: optimisticChatReportData.key,
value: {pendingFields: null},
});
failureData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: optimisticChatReportData.key,
value: {
errorFields: {
createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`,
value: {
[optimisticIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError(null),
},
},
},
);

// Add an optimistic created action to the optimistic reportActions data
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;
} else {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: optimisticChatReportData.key,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`,
value: {
errorFields: {
createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'),
[optimisticIOUReportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'),
},
},
});
Comment thread
therealsujitk marked this conversation as resolved.

// Add an optimistic created action to the optimistic reportActions data
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;

// If we're going to fail to create the report itself, let's not have redundant error messages for the IOU
failureData[0].value[optimisticIOUReportAction.reportActionID] = {pendingAction: null};
}

const optimisticData = [optimisticChatReportData, optimisticIOUReportData, optimisticReportActionsData, optimisticTransactionData];
Expand Down