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
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1055 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1060,7 +1060,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1063 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1078,7 +1078,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1081 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1090,7 +1090,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1093 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1098,7 +1098,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1101 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1108,7 +1108,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1111 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1116,7 +1116,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1119 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1152,14 +1152,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1155 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1162 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1185,7 +1185,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1188 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -8381,8 +8381,8 @@
};
}

function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: number, currentUserAccountID: number): OptimisticEditedTaskReportAction {
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);
function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: number, currentUserAccountID: number, delegateEmailParam: string | undefined): OptimisticEditedTaskReportAction {
const delegateAccountDetails = delegateEmailParam ? getPersonalDetailByEmail(delegateEmailParam) : undefined;

return {
reportActionID: rand64(),
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task
API.write(WRITE_COMMANDS.EDIT_TASK, parameters, {optimisticData, successData, failureData});
}

// eslint-disable-next-line @typescript-eslint/max-params -- Will be refactored in next PR; full restructure tracked in https://github.com/Expensify/App/issues/66417

@Krishna2323 Krishna2323 Apr 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann I'll refactor this in the next PR. Once this is merged.

function editTaskAssignee(
report: OnyxTypes.Report,
parentReport: OnyxEntry<OnyxTypes.Report>,
Expand All @@ -725,12 +726,13 @@ function editTaskAssignee(
currentUserEmail: string,
currentUserAccountID: number,
hasOutstandingChildTask: boolean,
delegateEmail: string | undefined,
assigneeAccountID: number | null = 0,
assigneeChatReport?: OnyxEntry<OnyxTypes.Report>,
isOptimisticReport?: boolean,
) {
// Create the EditedReportAction on the task
const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? CONST.DEFAULT_NUMBER_ID, currentUserAccountID);
const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? CONST.DEFAULT_NUMBER_ID, currentUserAccountID, delegateEmail);
const reportName = report.reportName?.trim();

let assigneeChatReportOnyxData;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/tasks/TaskAssigneeSelectorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable es/no-optional-chaining */
import {useRoute} from '@react-navigation/native';
import {delegateEmailSelector} from '@selectors/Account';
import React, {useEffect} from 'react';
import {InteractionManager, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -46,6 +47,7 @@ function TaskAssigneeSelectorModal() {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});

const {searchTerm, debouncedSearchTerm, setSearchTerm, availableOptions, areOptionsInitialized} = useSearchSelector({
selectionMode: CONST.SEARCH_SELECTOR.SELECTION_MODE_SINGLE,
Expand Down Expand Up @@ -174,6 +176,7 @@ function TaskAssigneeSelectorModal() {
currentUserEmail,
currentUserPersonalDetails.accountID,
hasOutstandingChildTask,
delegateEmail,
option?.accountID,
assigneeChatReport,
isOptimisticReport,
Expand Down
84 changes: 82 additions & 2 deletions tests/actions/TaskTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
createTaskAndNavigate,
deleteTask,
editTask,
editTaskAssignee,
getFinishOnboardingTaskOnyxData,
getNavigationUrlOnTaskDelete,
} from '@libs/actions/Task';
Expand Down Expand Up @@ -973,15 +974,94 @@ describe('actions/Task', () => {
expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID);
});

it('should set delegateAccountID to undefined when delegateEmail is empty', () => {
it('should set delegateAccountID to undefined when delegateEmail is undefined', () => {
const reportID = 'task_report_edit_2';
const taskReport = {
reportID,
type: CONST.REPORT.TYPE.TASK,
reportName: 'Original Task Title',
};

editTask(taskReport, {title: 'Updated Title'}, '');
editTask(taskReport, {title: 'Updated Title'}, undefined);

// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure
const calls = (API.write as jest.Mock).mock.calls;
const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>];
const optimisticData = onyxData.optimisticData ?? [];

const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
expect(reportActionsUpdate).toBeDefined();

const reportAction = Object.values(reportActionsUpdate?.value as Record<string, ReportAction>).at(0);
expect(reportAction?.delegateAccountID).toBeUndefined();
});
});

describe('editTaskAssignee', () => {
const DELEGATE_EMAIL = 'delegate@example.com';
const DELEGATE_ACCOUNT_ID = 999;
const CURRENT_USER_ACCOUNT_ID = 123;
const ASSIGNEE_ACCOUNT_ID = 456;

beforeEach(async () => {
jest.clearAllMocks();
writeSpy.mockClear();

global.fetch = getGlobalFetchMock();

await act(async () => {
await Onyx.clear();
await Onyx.set(ONYXKEYS.SESSION, {
email: 'user@example.com',
accountID: CURRENT_USER_ACCOUNT_ID,
});
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
[DELEGATE_ACCOUNT_ID]: {
accountID: DELEGATE_ACCOUNT_ID,
login: DELEGATE_EMAIL,
displayName: 'Delegate User',
},
[ASSIGNEE_ACCOUNT_ID]: {
accountID: ASSIGNEE_ACCOUNT_ID,
login: 'assignee@example.com',
displayName: 'Assignee User',
},
});
});
await waitForBatchedUpdatesWithAct();
});

it('should include delegateAccountID in optimistic report action when delegateEmail is provided', () => {
const reportID = 'task_report_assignee_1';
const taskReport = {
reportID,
type: CONST.REPORT.TYPE.TASK,
reportName: 'Task with assignee',
};

editTaskAssignee(taskReport, undefined, CURRENT_USER_ACCOUNT_ID, 'assignee@example.com', 'user@example.com', CURRENT_USER_ACCOUNT_ID, false, DELEGATE_EMAIL, ASSIGNEE_ACCOUNT_ID);

// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure
const calls = (API.write as jest.Mock).mock.calls;
const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>];
const optimisticData = onyxData.optimisticData ?? [];

const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
expect(reportActionsUpdate).toBeDefined();

const reportAction = Object.values(reportActionsUpdate?.value as Record<string, ReportAction>).at(0);
expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID);
});

it('should set delegateAccountID to undefined when delegateEmail is undefined', () => {
const reportID = 'task_report_assignee_2';
const taskReport = {
reportID,
type: CONST.REPORT.TYPE.TASK,
reportName: 'Task with assignee',
};

editTaskAssignee(taskReport, undefined, CURRENT_USER_ACCOUNT_ID, 'assignee@example.com', 'user@example.com', CURRENT_USER_ACCOUNT_ID, false, undefined, ASSIGNEE_ACCOUNT_ID);

// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure
const calls = (API.write as jest.Mock).mock.calls;
Expand Down
Loading