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
6 changes: 4 additions & 2 deletions src/libs/actions/QuickActionNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {generateReportID} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {PersonalDetails} from '@src/types/onyx';
import type {DistanceExpenseType} from '@src/types/onyx/IOU';
import type {QuickActionName} from '@src/types/onyx/QuickAction';
import type QuickAction from '@src/types/onyx/QuickAction';
Expand All @@ -12,6 +13,7 @@ type NavigateToQuickActionParams = {
quickAction: QuickAction;
selectOption: (onSelected: () => void, shouldRestrictAction: boolean) => void;
lastDistanceExpenseType?: DistanceExpenseType;
targetAccountPersonalDetails: PersonalDetails;
currentUserAccountID: number;
};

Expand All @@ -35,7 +37,7 @@ function getQuickActionRequestType(action: QuickActionName | undefined, lastDist
}

function navigateToQuickAction(params: NavigateToQuickActionParams) {
const {isValidReport, quickAction, selectOption, lastDistanceExpenseType, currentUserAccountID} = params;
const {isValidReport, quickAction, selectOption, lastDistanceExpenseType, targetAccountPersonalDetails, currentUserAccountID} = params;
const reportID = isValidReport && quickAction?.chatReportID ? quickAction?.chatReportID : generateReportID();
const requestType = getQuickActionRequestType(quickAction?.action, lastDistanceExpenseType);

Expand All @@ -54,7 +56,7 @@ function navigateToQuickAction(params: NavigateToQuickActionParams) {
selectOption(() => startMoneyRequest(CONST.IOU.TYPE.PAY, reportID, undefined, true), false);
break;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => startOutCreateTaskQuickAction(currentUserAccountID, isValidReport ? reportID : '', quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID), false);
selectOption(() => startOutCreateTaskQuickAction(currentUserAccountID, isValidReport ? reportID : '', targetAccountPersonalDetails), false);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
case CONST.QUICK_ACTIONS.TRACK_SCAN:
Expand Down
47 changes: 23 additions & 24 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@
quickAction?: OnyxEntry<OnyxTypes.QuickAction>;
};

let allPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = value),
});

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

Check warning on line 61 in src/libs/actions/Task.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 All @@ -77,7 +71,7 @@
});

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

Check warning on line 74 in src/libs/actions/Task.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 @@ -827,9 +821,9 @@
}
}

function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: number, currentUserAccountID: number) {
function setNewOptimisticAssignee(currentUserAccountID: number, assigneePersonalDetails: OnyxTypes.PersonalDetails) {
const report: ReportUtils.OptimisticChatReport = ReportUtils.buildOptimisticChatReport({
participantList: [assigneeAccountID, currentUserAccountID],
participantList: [assigneePersonalDetails.accountID, currentUserAccountID],
reportName: '',
policyID: CONST.POLICY.OWNER_EMAIL_FAKE,
ownerAccountID: CONST.POLICY.OWNER_ACCOUNT_ID_FAKE,
Expand All @@ -839,12 +833,12 @@
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);

const optimisticPersonalDetailsListAction: OnyxTypes.PersonalDetails = {
accountID: assigneeAccountID,
avatar: allPersonalDetails?.[assigneeAccountID]?.avatar,
displayName: allPersonalDetails?.[assigneeAccountID]?.displayName ?? assigneeLogin,
login: assigneeLogin,
accountID: assigneePersonalDetails.accountID,
avatar: assigneePersonalDetails?.avatar,
displayName: assigneePersonalDetails?.displayName ?? assigneePersonalDetails?.login,
login: assigneePersonalDetails?.login,
};
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[assigneeAccountID]: optimisticPersonalDetailsListAction});
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[assigneePersonalDetails.accountID]: optimisticPersonalDetailsListAction});
return {assignee: optimisticPersonalDetailsListAction, assigneeReport: report};
}

Expand All @@ -854,9 +848,8 @@
* It also sets the shareDestination as that chat report if a share destination isn't already set
*/
function setAssigneeValue(
assigneeEmail: string,
assigneeAccountID: number,
currentUserAccountID: number,
assigneePersonalDetails: OnyxTypes.PersonalDetails,
shareToReportID?: string,
chatReport?: OnyxEntry<OnyxTypes.Report>,
isCurrentUser = false,
Expand All @@ -873,11 +866,11 @@
} else {
// Check for the chatReport by participants IDs
if (!report) {
report = ReportUtils.getChatByParticipants([assigneeAccountID, currentUserAccountID]);
report = ReportUtils.getChatByParticipants([assigneePersonalDetails.accountID, currentUserAccountID]);
}
// If chat report is still not found we need to build new optimistic chat report
if (!report) {
report = setNewOptimisticAssignee(assigneeEmail, assigneeAccountID, currentUserAccountID).assigneeReport;
report = setNewOptimisticAssignee(currentUserAccountID, assigneePersonalDetails).assigneeReport;
}
const reportMetadata = ReportUtils.getReportMetadata(report?.reportID);

Expand All @@ -900,7 +893,7 @@
}

// This is only needed for creation of a new task and so it should only be stored locally
Onyx.merge(ONYXKEYS.TASK, {assignee: assigneeEmail, assigneeAccountID});
Onyx.merge(ONYXKEYS.TASK, {assignee: assigneePersonalDetails?.login ?? '', assigneeAccountID: assigneePersonalDetails.accountID});

// When we're editing the assignee, we immediately call editTaskAssignee. Since setting the assignee is async,
// the chatReport is not yet set when editTaskAssignee is called. So we return the chatReport here so that
Expand All @@ -919,27 +912,33 @@
/**
* Clears out the task info from the store and navigates to the NewTaskDetails page
*/
function clearOutTaskInfoAndNavigate(currentUserAccountID: number, reportID?: string, chatReport?: OnyxEntry<OnyxTypes.Report>, accountID = 0, skipConfirmation = false) {
function clearOutTaskInfoAndNavigate(
currentUserAccountID: number,
assigneePersonalDetails?: OnyxTypes.PersonalDetails,
reportID?: string,
chatReport?: OnyxEntry<OnyxTypes.Report>,
skipConfirmation = false,
) {
clearOutTaskInfo(skipConfirmation);
if (reportID && reportID !== '0') {
setParentReportID(reportID);
}
if (accountID > 0) {
const accountLogin = allPersonalDetails?.[accountID]?.login ?? '';
setAssigneeValue(accountLogin, accountID, currentUserAccountID, reportID, chatReport, accountID === currentUserAccountID, skipConfirmation);
const assigneeAccountID = assigneePersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID;
if (assigneePersonalDetails && assigneeAccountID > 0) {
setAssigneeValue(currentUserAccountID, assigneePersonalDetails, reportID, chatReport, assigneeAccountID === currentUserAccountID, skipConfirmation);
}
Navigation.navigate(ROUTES.NEW_TASK_DETAILS.getRoute(Navigation.getReportRHPActiveRoute()));
}

/**
* Start out create task action quick action step
*/
function startOutCreateTaskQuickAction(currentUserAccountID: number, reportID: string, targetAccountID: number) {
function startOutCreateTaskQuickAction(currentUserAccountID: number, reportID: string, targetAccountPersonalDetails: OnyxTypes.PersonalDetails) {
// The second parameter of clearOutTaskInfoAndNavigate is the chat report or DM report
// between the user and the person to whom the task is assigned.
// Since chatReportID isn't stored in NVP_QUICK_ACTION_GLOBAL_CREATE, we set
// it to undefined. This will make setAssigneeValue to search for the correct report.
clearOutTaskInfoAndNavigate(currentUserAccountID, reportID, undefined, targetAccountID, true);
clearOutTaskInfoAndNavigate(currentUserAccountID, targetAccountPersonalDetails, reportID, undefined, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function AttachmentPickerWithMenuItems({
icon: Expensicons.Task,
text: translate('newTaskPage.assignTask'),
shouldCallAfterModalHide: shouldUseNarrowLayout,
onSelected: () => clearOutTaskInfoAndNavigate(currentUserPersonalDetails.accountID, reportID, report),
onSelected: () => clearOutTaskInfoAndNavigate(currentUserPersonalDetails.accountID, undefined, reportID, report),
},
];
}, [report, translate, shouldUseNarrowLayout, currentUserPersonalDetails.accountID, reportID]);
Expand Down
6 changes: 4 additions & 2 deletions src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ function ReportFooter({
if (isValidMention) {
assignee = Object.values(allPersonalDetails ?? {}).find((value) => value?.login === mentionWithDomain) ?? undefined;
if (!Object.keys(assignee ?? {}).length) {
const assigneeAccountID = generateAccountID(mentionWithDomain);
const optimisticDataForNewAssignee = setNewOptimisticAssignee(mentionWithDomain, assigneeAccountID, personalDetail.accountID);
const optimisticDataForNewAssignee = setNewOptimisticAssignee(personalDetail.accountID, {
accountID: generateAccountID(mentionWithDomain),
login: mentionWithDomain,
});
assignee = optimisticDataForNewAssignee.assignee;
assigneeChatReport = optimisticDataForNewAssignee.assigneeReport;
}
Expand Down
15 changes: 14 additions & 1 deletion src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,19 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
showDelegateNoAccessModal();
return;
}
navigateToQuickAction({isValidReport, quickAction, selectOption, lastDistanceExpenseType, currentUserAccountID: currentUserPersonalDetails.accountID});
const targetAccountPersonalDetails = {
...personalDetails?.[quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID],
accountID: quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID,
};

Comment thread
parasharrajat marked this conversation as resolved.
navigateToQuickAction({
isValidReport,
quickAction,
selectOption,
lastDistanceExpenseType,
targetAccountPersonalDetails,
currentUserAccountID: currentUserPersonalDetails.accountID,
});
});
};
return [
Expand Down Expand Up @@ -489,6 +501,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
isValidReport,
selectOption,
lastDistanceExpenseType,
personalDetails,
currentUserPersonalDetails.accountID,
showDelegateNoAccessModal,
reportID,
Expand Down
17 changes: 12 additions & 5 deletions src/pages/tasks/TaskAssigneeSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {InteractionManager, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionListWithSections';
import type {ListItem} from '@components/SelectionListWithSections/types';
Expand Down Expand Up @@ -76,6 +77,8 @@ function TaskAssigneeSelectorModal() {
);
}, [optionsWithoutCurrentUser, debouncedSearchTerm, countryCode]);

const allPersonalDetails = usePersonalDetails();

const report: OnyxEntry<Report> = useMemo(() => {
if (!route.params?.reportID) {
return;
Expand Down Expand Up @@ -141,13 +144,18 @@ function TaskAssigneeSelectorModal() {
return;
}

const assigneePersonalDetails = {
...allPersonalDetails?.[option?.accountID ?? CONST.DEFAULT_NUMBER_ID],
accountID: option.accountID ?? CONST.DEFAULT_NUMBER_ID,
login: option.login ?? '',
};

// Check to see if we're editing a task and if so, update the assignee
if (report) {
if (option.accountID !== report.managerID) {
const assigneeChatReport = setAssigneeValue(
option?.login ?? '',
option?.accountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserPersonalDetails.accountID,
assigneePersonalDetails,
report.reportID,
undefined, // passing null as report because for editing task the report will be task details report page not the actual report where task was created
isCurrentUser({...option, accountID: option?.accountID ?? CONST.DEFAULT_NUMBER_ID, login: option?.login ?? ''}),
Expand All @@ -169,9 +177,8 @@ function TaskAssigneeSelectorModal() {
// If there's no report, we're creating a new task
} else if (option.accountID) {
setAssigneeValue(
option?.login ?? '',
option.accountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserPersonalDetails.accountID,
assigneePersonalDetails,
task?.shareDestination ?? '',
undefined, // passing null as report is null in this condition
isCurrentUser({...option, accountID: option?.accountID ?? CONST.DEFAULT_NUMBER_ID, login: option?.login ?? undefined}),
Expand All @@ -182,7 +189,7 @@ function TaskAssigneeSelectorModal() {
});
}
},
[report, currentUserPersonalDetails.accountID, task?.shareDestination, backTo],
[report, currentUserPersonalDetails.accountID, allPersonalDetails, task?.shareDestination, backTo],
);

const handleBackButtonPress = useCallback(() => Navigation.goBack(!route.params?.reportID ? ROUTES.NEW_TASK.getRoute(backTo) : backTo), [route.params, backTo]);
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/QuickActionNavigationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation';
import {startOutCreateTaskQuickAction} from '@libs/actions/Task';
import {generateReportID} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import createPersonalDetails from '../utils/collections/personalDetails';

jest.mock('@libs/actions/IOU', () => ({
startMoneyRequest: jest.fn(),
Expand All @@ -28,6 +29,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});

Expand All @@ -43,6 +45,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});

Expand All @@ -58,6 +61,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});

Expand All @@ -73,6 +77,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});

Expand All @@ -88,6 +93,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
lastDistanceExpenseType: CONST.IOU.REQUEST_TYPE.DISTANCE_MANUAL,
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});
Expand All @@ -104,6 +110,7 @@ describe('IOU Utils', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(1),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});

Expand All @@ -122,6 +129,7 @@ describe('Non IOU quickActions test:', () => {
selectOption: (onSelected: () => void) => {
onSelected();
},
targetAccountPersonalDetails: createPersonalDetails(123),
currentUserAccountID: CONST.DEFAULT_NUMBER_ID,
});
expect(startOutCreateTaskQuickAction).toHaveBeenCalled();
Expand Down
Loading