Skip to content

Commit

Permalink
Merge pull request #26848 from namhihi237/fix-22608-add-error-when-cr…
Browse files Browse the repository at this point in the history
…eate-task-room-admin-only

add failure message when create a task error
  • Loading branch information
thienlnam authored Nov 7, 2023
2 parents d5725c5 + ce5e88f commit 5df95a1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/TaskView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function TaskView(props) {
<View>
<OfflineWithFeedback
shouldShowErrorMessages
errors={lodashGet(props, 'report.errorFields.editTask')}
onClose={() => Task.clearEditTaskErrors(props.report.reportID)}
errors={lodashGet(props, 'report.errorFields.editTask') || lodashGet(props, 'report.errorFields.createTask')}
onClose={() => Task.clearTaskErrors(props.report.reportID)}
errorRowStyles={styles.ph5}
>
<Hoverable>
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ export default {
markAsComplete: 'Mark as complete',
markAsIncomplete: 'Mark as incomplete',
assigneeError: 'There was an error assigning this task, please try another assignee.',
genericCreateTaskFailureMessage: 'Unexpected error create task, please try again later.',
},
statementPage: {
generatingPDF: "We're generating your PDF right now. Please come back later!",
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@ export default {
markAsComplete: 'Marcar como completada',
markAsIncomplete: 'Marcar como incompleta',
assigneeError: 'Hubo un error al asignar esta tarea, inténtalo con otro usuario.',
genericCreateTaskFailureMessage: 'Error inesperado al crear el tarea, por favor, inténtalo más tarde.',
},
statementPage: {
generatingPDF: 'Estamos generando tu PDF ahora mismo. ¡Por favor, vuelve más tarde!',
Expand Down
6 changes: 6 additions & 0 deletions src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ReportAction from '@src/types/onyx/ReportAction';
import * as Report from './Report';

function clearReportActionErrors(reportID: string, reportAction: ReportAction) {
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction);
Expand All @@ -24,6 +25,11 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction) {
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID}`, null);
}

// Delete the failed task report too
const taskReportID = reportAction.message?.[0]?.taskReportID;
if (taskReportID) {
Report.deleteReport(taskReportID);
}
return;
}

Expand Down
31 changes: 26 additions & 5 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as UserUtils from '@libs/UserUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import * as Report from './Report';

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -134,9 +135,13 @@ function createTaskAndNavigate(parentReportID, title, description, assigneeEmail
// FOR TASK REPORT
const failureData = [
{
onyxMethod: Onyx.METHOD.SET,
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTaskReport.reportID}`,
value: null,
value: {
errorFields: {
createTask: ErrorUtils.getMicroSecondOnyxError('task.genericCreateTaskFailureMessage'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -186,7 +191,11 @@ function createTaskAndNavigate(parentReportID, title, description, assigneeEmail
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
value: {[optimisticAddCommentReport.reportAction.reportActionID]: {pendingAction: null}},
value: {
[optimisticAddCommentReport.reportAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxError('task.genericCreateTaskFailureMessage'),
},
},
});

clearOutTaskInfo();
Expand Down Expand Up @@ -879,7 +888,19 @@ function canModifyTask(taskReport, sessionAccountID) {
/**
* @param {String} reportID
*/
function clearEditTaskErrors(reportID) {
function clearTaskErrors(reportID) {
const report = ReportUtils.getReport(reportID);

// Delete the task preview in the parent report
if (lodashGet(report, 'pendingFields.createChat') === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {
[report.parentReportActionID]: null,
});

Report.navigateToConciergeChatAndDeleteReport(reportID);
return;
}

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
pendingFields: null,
errorFields: null,
Expand Down Expand Up @@ -934,7 +955,7 @@ export {
cancelTask,
dismissModalAndClearOutTaskInfo,
getTaskAssigneeAccountID,
clearEditTaskErrors,
clearTaskErrors,
canModifyTask,
getTaskReportActionMessage,
};
3 changes: 3 additions & 0 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Message = {

moderationDecision?: Decision;
translationKey?: string;

/** ID of a task report */
taskReportID?: string;
};

type Person = {
Expand Down

0 comments on commit 5df95a1

Please sign in to comment.