Skip to content

Commit

Permalink
fix task title is not updated dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Oct 5, 2024
1 parent 998fe1d commit 8616228
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function TaskPreview({taskReportID, action, contextMenuAnchor, chatReportID, che
const isTaskCompleted = !isEmptyObject(taskReport)
? taskReport?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && taskReport.statusNum === CONST.REPORT.STATUS_NUM.APPROVED
: action?.childStateNum === CONST.REPORT.STATE_NUM.APPROVED && action?.childStatusNum === CONST.REPORT.STATUS_NUM.APPROVED;
const taskTitle = Str.htmlEncode(TaskUtils.getTaskTitle(taskReportID, action?.childReportName ?? ''));
const taskTitle = Str.htmlEncode(TaskUtils.getTaskTitleFromReport(taskReport, action?.childReportName ?? ''));
const taskAssigneeAccountID = Task.getTaskAssigneeAccountID(taskReport) ?? action?.childManagerAccountID ?? -1;
const hasAssignee = taskAssigneeAccountID > 0;
const personalDetails = usePersonalDetails();
Expand Down
13 changes: 9 additions & 4 deletions src/libs/TaskUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {Report} from '@src/types/onyx';

Check failure on line 5 in src/libs/TaskUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

All imports in the declaration are only used as types. Use `import type`
import type {Message} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
import * as Localize from './Localize';
Expand Down Expand Up @@ -37,12 +38,16 @@ function getTaskReportActionMessage(action: OnyxEntry<ReportAction>): Pick<Messa
}
}

function getTaskTitle(taskReportID: string, fallbackTitle = ''): string {
const taskReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`] ?? {};
function getTaskTitleFromReport(taskReport: OnyxEntry<Report>, fallbackTitle = ''): string {
// We need to check for reportID, not just reportName, because when a receiver opens the task for the first time,
// an optimistic report is created with the only property – reportName: 'Chat report',
// and it will be displayed as the task title without checking for reportID to be present.
return Object.hasOwn(taskReport, 'reportID') && 'reportName' in taskReport && typeof taskReport.reportName === 'string' ? taskReport.reportName : fallbackTitle;
return taskReport?.reportID && taskReport.reportName ? taskReport.reportName : fallbackTitle;
}

function getTaskTitle(taskReportID: string, fallbackTitle = ''): string {
const taskReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`];
return getTaskTitleFromReport(taskReport, fallbackTitle);
}

function getTaskCreatedMessage(reportAction: OnyxEntry<ReportAction>) {
Expand All @@ -51,4 +56,4 @@ function getTaskCreatedMessage(reportAction: OnyxEntry<ReportAction>) {
return taskTitle ? Localize.translateLocal('task.messages.created', {title: taskTitle}) : '';
}

export {isActiveTaskEditRoute, getTaskReportActionMessage, getTaskTitle, getTaskCreatedMessage};
export {isActiveTaskEditRoute, getTaskReportActionMessage, getTaskTitle, getTaskTitleFromReport, getTaskCreatedMessage};

0 comments on commit 8616228

Please sign in to comment.