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
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function TaskPreview({
disabled={!isTaskActionable}
onPress={callFunctionIfActionIsAllowed(() => {
if (isTaskCompleted) {
reopenTask(taskReport, taskReportID);
reopenTask(taskReport, currentUserPersonalDetails.accountID, taskReportID);
} else {
completeTask(taskReport, taskReportID);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TaskView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
return;
}
if (isCompleted) {
reopenTask(report);
reopenTask(report, currentUserPersonalDetails.accountID);
} else {
completeTask(report);
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/TaskHeaderActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {View} from 'react-native';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useParentReport from '@hooks/useParentReport';
import useReportIsArchived from '@hooks/useReportIsArchived';
Expand All @@ -10,7 +11,6 @@ import {callFunctionIfActionIsAllowed} from '@userActions/Session';
import {canActionTask, completeTask, reopenTask} from '@userActions/Task';
import type * as OnyxTypes from '@src/types/onyx';
import Button from './Button';
import {useSession} from './OnyxListItemProvider';

type TaskHeaderActionButtonProps = {
/** The report currently being looked at */
Expand All @@ -20,10 +20,10 @@ type TaskHeaderActionButtonProps = {
function TaskHeaderActionButton({report}: TaskHeaderActionButtonProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const session = useSession();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const parentReport = useParentReport(report.reportID);
const isParentReportArchived = useReportIsArchived(parentReport?.reportID);
const isTaskActionable = canActionTask(report, session?.accountID, parentReport, isParentReportArchived);
const isTaskActionable = canActionTask(report, currentUserPersonalDetails?.accountID, parentReport, isParentReportArchived);

if (!canWriteInReport(report)) {
return null;
Expand All @@ -41,7 +41,7 @@ function TaskHeaderActionButton({report}: TaskHeaderActionButtonProps) {
return;
}
if (isCompletedTaskReport(report)) {
reopenTask(report);
reopenTask(report, currentUserPersonalDetails.accountID);
} else {
completeTask(report);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TestDrive/TestDriveDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function TestDriveDemo() {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
setIsVisible(true);
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived);
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserPersonalDetails.accountID);
});

// This should fire only during mount.
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10012,13 +10012,13 @@ function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean {
/**
* Navigates to the appropriate screen based on the presence of a private note for the current user.
*/
function navigateToPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Session>, backTo?: string) {
if (isEmpty(report) || isEmpty(session) || !session.accountID) {
function navigateToPrivateNotes(report: OnyxEntry<Report>, accountID: number, backTo?: string) {
if (isEmpty(report) || !accountID) {
return;
}
const currentUserPrivateNote = report.privateNotes?.[session.accountID]?.note ?? '';
const currentUserPrivateNote = report.privateNotes?.[accountID]?.note ?? '';
if (isEmpty(currentUserPrivateNote)) {
Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID, backTo));
Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, accountID, backTo));
return;
}
Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID, backTo));
Expand Down
12 changes: 8 additions & 4 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ function appendSetupCategoriesOnboardingData(
setupCategoryTaskReport: OnyxEntry<Report>,
setupCategoryTaskParentReport: OnyxEntry<Report>,
isSetupCategoriesTaskParentReportArchived: boolean,
currentUserAccountID: number,
) {
const finishOnboardingTaskData = getFinishOnboardingTaskOnyxData(setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived);
const finishOnboardingTaskData = getFinishOnboardingTaskOnyxData(setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived, currentUserAccountID);
onyxData.optimisticData?.push(...(finishOnboardingTaskData.optimisticData ?? []));
onyxData.successData?.push(...(finishOnboardingTaskData.successData ?? []));
onyxData.failureData?.push(...(finishOnboardingTaskData.failureData ?? []));
Expand Down Expand Up @@ -316,6 +317,7 @@ function setWorkspaceCategoryEnabled(
isSetupCategoriesTaskParentReportArchived: boolean,
setupCategoryTaskReport: OnyxEntry<Report>,
setupCategoryTaskParentReport: OnyxEntry<Report>,
currentUserAccountID: number,
policyCategories: PolicyCategories = {},
policyTagLists: PolicyTagLists = {},
allTransactionViolations: OnyxCollection<TransactionViolations> = {},
Expand Down Expand Up @@ -385,7 +387,7 @@ function setWorkspaceCategoryEnabled(
};

pushTransactionViolationsOnyxData(onyxData, policyID, policyTagLists, policyCategories, allTransactionViolations, {}, optimisticPolicyCategoriesData);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived, currentUserAccountID);

const parameters = {
policyID,
Expand Down Expand Up @@ -591,9 +593,10 @@ function createPolicyCategory(
isSetupCategoriesTaskParentReportArchived: boolean,
setupCategoryTaskReport: OnyxEntry<Report>,
setupCategoryTaskParentReport: OnyxEntry<Report>,
currentUserAccountID: number,
) {
const onyxData = buildOptimisticPolicyCategories(policyID, [categoryName]);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived, currentUserAccountID);
const parameters = {
policyID,
categories: JSON.stringify([{name: categoryName}]),
Expand Down Expand Up @@ -975,6 +978,7 @@ function deleteWorkspaceCategories(
isSetupCategoriesTaskParentReportArchived: boolean,
setupCategoryTaskReport: OnyxEntry<Report>,
setupCategoryTaskParentReport: OnyxEntry<Report>,
currentUserAccountID: number,
policyTagLists: PolicyTagLists = {},
policyCategories: PolicyCategories = {},
transactionViolations: OnyxCollection<TransactionViolations> = {},
Expand Down Expand Up @@ -1024,7 +1028,7 @@ function deleteWorkspaceCategories(

const optimisticPolicyData: Partial<Policy> = shouldDisableRequiresCategory ? {requiresCategory: false} : {};
pushTransactionViolationsOnyxData(onyxData, policyID, policyTagLists, policyCategories, transactionViolations, optimisticPolicyData, optimisticPolicyCategoriesData);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived);
appendSetupCategoriesOnboardingData(onyxData, setupCategoryTaskReport, setupCategoryTaskParentReport, isSetupCategoriesTaskParentReportArchived, currentUserAccountID);

const parameters = {
policyID,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/QuickActionNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type NavigateToQuickActionParams = {
quickAction: QuickAction;
selectOption: (onSelected: () => void, shouldRestrictAction: boolean) => void;
lastDistanceExpenseType?: DistanceExpenseType;
currentUserAccountID: number;
};

function getQuickActionRequestType(action: QuickActionName | undefined, lastDistanceExpenseType?: DistanceExpenseType): IOURequestType | undefined {
Expand All @@ -34,7 +35,7 @@ function getQuickActionRequestType(action: QuickActionName | undefined, lastDist
}

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

Expand All @@ -53,7 +54,7 @@ function navigateToQuickAction(params: NavigateToQuickActionParams) {
selectOption(() => startMoneyRequest(CONST.IOU.TYPE.PAY, reportID, undefined, true), false);
break;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => startOutCreateTaskQuickAction(isValidReport ? reportID : '', quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID), false);
selectOption(() => startOutCreateTaskQuickAction(currentUserAccountID, isValidReport ? reportID : '', quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID), false);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
case CONST.QUICK_ACTIONS.TRACK_SCAN:
Expand Down
84 changes: 52 additions & 32 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ type ShareDestination = {
shouldUseFullTitleToDisplay: boolean;
};

let currentUserEmail = '';
let currentUserAccountID = -1;

Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
},
});
type CreateTaskAndNavigateParams = {
parentReportID: string | undefined;
title: string;
description: string;
assigneeEmail: string;
currentUserAccountID: number;
currentUserEmail: string;
assigneeAccountID?: number;
assigneeChatReport?: OnyxEntry<OnyxTypes.Report>;
policyID?: string;
isCreatedUsingMarkdown?: boolean;
quickAction?: OnyxEntry<OnyxTypes.QuickAction>;
};

let allPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
Onyx.connect({
Expand Down Expand Up @@ -108,17 +111,20 @@ function clearOutTaskInfo(skipConfirmation = false) {
* 3a. The CreatedReportAction for the assignee chat report
* 3b. The TaskReportAction on the assignee chat report
*/
function createTaskAndNavigate(
parentReportID: string | undefined,
title: string,
description: string,
assigneeEmail: string,
assigneeAccountID = 0,
assigneeChatReport?: OnyxEntry<OnyxTypes.Report>,
policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE,
isCreatedUsingMarkdown = false,
quickAction: OnyxEntry<OnyxTypes.QuickAction> = {},
) {
function createTaskAndNavigate(params: CreateTaskAndNavigateParams) {
const {
parentReportID,
title,
description,
assigneeEmail,
currentUserAccountID,
currentUserEmail,
assigneeAccountID = 0,
assigneeChatReport,
policyID = CONST.POLICY.OWNER_EMAIL_FAKE,
isCreatedUsingMarkdown = false,
quickAction = {},
} = params;
if (!parentReportID) {
return;
}
Expand Down Expand Up @@ -465,7 +471,7 @@ function completeTask(taskReport: OnyxEntry<OnyxTypes.Report>, reportIDFromActio
/**
* Reopen a closed task
*/
function reopenTask(taskReport: OnyxEntry<OnyxTypes.Report>, reportIDFromAction?: string) {
function reopenTask(taskReport: OnyxEntry<OnyxTypes.Report>, currentUserAccountID: number, reportIDFromAction?: string) {
const taskReportID = taskReport?.reportID ?? reportIDFromAction;
if (!taskReportID) {
return;
Expand Down Expand Up @@ -628,7 +634,14 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task
API.write(WRITE_COMMANDS.EDIT_TASK, parameters, {optimisticData, successData, failureData});
}

function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, assigneeEmail: string, assigneeAccountID: number | null = 0, assigneeChatReport?: OnyxEntry<OnyxTypes.Report>) {
function editTaskAssignee(
report: OnyxTypes.Report,
sessionAccountID: number,
assigneeEmail: string,
currentUserAccountID: number,
assigneeAccountID: number | null = 0,
assigneeChatReport?: OnyxEntry<OnyxTypes.Report>,
) {
// Create the EditedReportAction on the task
const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? CONST.DEFAULT_NUMBER_ID);
const reportName = report.reportName?.trim();
Expand Down Expand Up @@ -814,7 +827,7 @@ function setAssigneeChatReport(chatReport: OnyxTypes.Report, isOptimisticReport
}
}

function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: number) {
function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: number, currentUserAccountID: number) {
const report: ReportUtils.OptimisticChatReport = ReportUtils.buildOptimisticChatReport({
participantList: [assigneeAccountID, currentUserAccountID],
reportName: '',
Expand Down Expand Up @@ -843,6 +856,7 @@ function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: numb
function setAssigneeValue(
assigneeEmail: string,
assigneeAccountID: number,
currentUserAccountID: number,
shareToReportID?: string,
chatReport?: OnyxEntry<OnyxTypes.Report>,
isCurrentUser = false,
Expand All @@ -863,7 +877,7 @@ function setAssigneeValue(
}
// If chat report is still not found we need to build new optimistic chat report
if (!report) {
report = setNewOptimisticAssignee(assigneeEmail, assigneeAccountID).assigneeReport;
report = setNewOptimisticAssignee(assigneeEmail, assigneeAccountID, currentUserAccountID).assigneeReport;
}
const reportMetadata = ReportUtils.getReportMetadata(report?.reportID);

Expand Down Expand Up @@ -905,27 +919,27 @@ function setParentReportID(parentReportID: string) {
/**
* Clears out the task info from the store and navigates to the NewTaskDetails page
*/
function clearOutTaskInfoAndNavigate(reportID?: string, chatReport?: OnyxEntry<OnyxTypes.Report>, accountID = 0, skipConfirmation = false) {
function clearOutTaskInfoAndNavigate(currentUserAccountID: number, reportID?: string, chatReport?: OnyxEntry<OnyxTypes.Report>, accountID = 0, skipConfirmation = false) {
clearOutTaskInfo(skipConfirmation);
if (reportID && reportID !== '0') {
setParentReportID(reportID);
}
if (accountID > 0) {
const accountLogin = allPersonalDetails?.[accountID]?.login ?? '';
setAssigneeValue(accountLogin, accountID, reportID, chatReport, accountID === currentUserAccountID, skipConfirmation);
setAssigneeValue(accountLogin, accountID, currentUserAccountID, reportID, chatReport, accountID === currentUserAccountID, skipConfirmation);
}
Navigation.navigate(ROUTES.NEW_TASK_DETAILS.getRoute(Navigation.getReportRHPActiveRoute()));
}

/**
* Start out create task action quick action step
*/
function startOutCreateTaskQuickAction(reportID: string, targetAccountID: number) {
function startOutCreateTaskQuickAction(currentUserAccountID: number, reportID: string, targetAccountID: number) {
// 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(reportID, undefined, targetAccountID, true);
clearOutTaskInfoAndNavigate(currentUserAccountID, reportID, undefined, targetAccountID, true);
}

/**
Expand Down Expand Up @@ -1049,7 +1063,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>): stri
/**
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
*/
function deleteTask(report: OnyxEntry<OnyxTypes.Report>, isReportArchived: boolean) {
function deleteTask(report: OnyxEntry<OnyxTypes.Report>, isReportArchived: boolean, currentUserAccountID: number) {
if (!report) {
return;
}
Expand Down Expand Up @@ -1292,7 +1306,12 @@ function clearTaskErrors(reportID: string | undefined) {
});
}

function getFinishOnboardingTaskOnyxData(taskReport: OnyxEntry<OnyxTypes.Report>, taskParentReport: OnyxEntry<OnyxTypes.Report>, isParentReportArchived: boolean): OnyxData {
function getFinishOnboardingTaskOnyxData(
taskReport: OnyxEntry<OnyxTypes.Report>,
taskParentReport: OnyxEntry<OnyxTypes.Report>,
isParentReportArchived: boolean,
currentUserAccountID: number,
): OnyxData {
if (taskReport && canActionTask(taskReport, currentUserAccountID, taskParentReport, isParentReportArchived)) {
if (taskReport) {
if (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED) {
Expand All @@ -1307,10 +1326,11 @@ function completeTestDriveTask(
viewTourTaskReport: OnyxEntry<OnyxTypes.Report>,
viewTourTaskParentReport: OnyxEntry<OnyxTypes.Report>,
isViewTourTaskParentReportArchived: boolean,
currentUserAccountID: number,
shouldUpdateSelfTourViewedOnlyLocally = false,
) {
setSelfTourViewed(shouldUpdateSelfTourViewedOnlyLocally);
getFinishOnboardingTaskOnyxData(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived);
getFinishOnboardingTaskOnyxData(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserAccountID);
}

export {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function startTestDrive(
viewTourTaskReport: OnyxEntry<OnyxTypes.Report>,
viewTourTaskParentReport: OnyxEntry<OnyxTypes.Report>,
isViewTourTaskParentReportArchived: boolean,
currentUserAccountID: number,
) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
Expand All @@ -26,7 +27,7 @@ function startTestDrive(
introSelected?.choice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE ||
(introSelected?.choice === CONST.ONBOARDING_CHOICES.SUBMIT && introSelected.inviteType === CONST.ONBOARDING_INVITE_TYPES.WORKSPACE)
) {
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, shouldUpdateSelfTourViewedOnlyLocally);
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserAccountID, shouldUpdateSelfTourViewedOnlyLocally);
Navigation.navigate(ROUTES.TEST_DRIVE_DEMO_ROOT);
} else {
Navigation.navigate(ROUTES.TEST_DRIVE_MODAL_ROOT.route);
Expand Down
Loading
Loading