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
8 changes: 2 additions & 6 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
import {
getDefaultApprover,
getMemberAccountIDsForWorkspace,
getPolicy,
isInstantSubmitEnabled,
isPaidGroupPolicy,
isPolicyAdmin as isPolicyAdminPolicyUtils,
Expand Down Expand Up @@ -277,7 +276,7 @@
let currentUserAccountID = -1;
let currentUserEmail: string | undefined;

Onyx.connect({

Check warning on line 279 in src/libs/actions/Report.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 @@ -290,7 +289,7 @@
},
});

Onyx.connect({

Check warning on line 292 in src/libs/actions/Report.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) => (conciergeReportID = value),
});
Expand All @@ -298,7 +297,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 300 in src/libs/actions/Report.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,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -310,14 +309,14 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 312 in src/libs/actions/Report.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_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
});

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

Check warning on line 319 in src/libs/actions/Report.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 All @@ -326,7 +325,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 328 in src/libs/actions/Report.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) => {
allPersonalDetails = value ?? {};
Expand All @@ -341,7 +340,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 343 in src/libs/actions/Report.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.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -352,20 +351,20 @@
});

let introSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({

Check warning on line 354 in src/libs/actions/Report.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.NVP_INTRO_SELECTED,
callback: (val) => (introSelected = val),
});

let allReportDraftComments: Record<string, string | undefined> = {};
Onyx.connect({

Check warning on line 360 in src/libs/actions/Report.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_COMMENT,
waitForCollectionCallback: true,
callback: (value) => (allReportDraftComments = value),
});

let allTransactions: OnyxCollection<Transaction> = {};
Onyx.connect({

Check warning on line 367 in src/libs/actions/Report.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 Down Expand Up @@ -3037,13 +3036,10 @@
creatorPersonalDetails: CurrentUserPersonalDetails,
hasViolationsParam: boolean,
isASAPSubmitBetaEnabled: boolean,
policyID?: string,
policy: OnyxEntry<Policy>,
shouldNotifyNewAction = false,
shouldDismissEmptyReportsConfirmation?: boolean,
) {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(policyID);
const optimisticReportID = generateReportID();
const reportActionID = rand64();
const reportPreviewReportActionID = rand64();
Expand All @@ -3067,7 +3063,7 @@
{
reportName: optimisticReportName,
type: CONST.REPORT.TYPE.EXPENSE,
policyID,
policyID: policy?.id,
reportID: optimisticReportID,
reportActionID,
reportPreviewReportActionID,
Expand Down
9 changes: 8 additions & 1 deletion src/pages/NewReportWorkspaceSelectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag

const createReport = useCallback(
(policyID: string, shouldDismissEmptyReportsConfirmation?: boolean) => {
const optimisticReport = createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policyID, false, shouldDismissEmptyReportsConfirmation);
const optimisticReport = createNewReport(
currentUserPersonalDetails,
isASAPSubmitBetaEnabled,
hasViolations,
policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
false,
shouldDismissEmptyReportsConfirmation,
);
const selectedTransactionsKeys = Object.keys(selectedTransactions);

if (isMovingExpenses && (!!selectedTransactionsKeys.length || !!selectedTransactionIDs.length)) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ function EmptySearchViewContent({

const handleCreateWorkspaceReport = useCallback(
(shouldDismissEmptyReportsConfirmation?: boolean) => {
if (!defaultChatEnabledPolicyID) {
if (!defaultChatEnabledPolicy?.id) {
return;
}

const {reportID: createdReportID} = createNewReport(
currentUserPersonalDetails,
hasViolations,
isASAPSubmitBetaEnabled,
defaultChatEnabledPolicyID,
defaultChatEnabledPolicy,
false,
shouldDismissEmptyReportsConfirmation,
);
Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: createdReportID, backTo: Navigation.getActiveRoute()}));
});
},
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicyID, isASAPSubmitBetaEnabled],
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled],
);

const {openCreateReportConfirmation: openCreateReportFromSearch, CreateReportConfirmationModal} = useCreateEmptyReportConfirmation({
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Search/SearchTransactionsChangeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function SearchTransactionsChangeReport() {
}, [selectedTransactions, selectedTransactionsKeys]);

const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => {
const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForMovingExpensesID, false, shouldDismissEmptyReportsConfirmation);
const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForMovingExpenses, false, shouldDismissEmptyReportsConfirmation);
const reportNextStep = allReportNextSteps?.[`${ONYXKEYS.COLLECTION.NEXT_STEP}${optimisticReport.reportID}`];
setNavigationActionToMicrotaskQueue(() => {
changeTransactionsReport(
Expand All @@ -82,7 +82,7 @@ function SearchTransactionsChangeReport() {
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
session?.email ?? '',
optimisticReport,
policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined,
policyForMovingExpenses,
reportNextStep,
allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyForMovingExpensesID}`],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function AttachmentPickerWithMenuItems({
policyID: report?.policyID,
policyName: policy?.name ?? '',
onConfirm: (shouldDismissEmptyReportsConfirmation) =>
selectOption(() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, true, shouldDismissEmptyReportsConfirmation), true),
selectOption(() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, true, shouldDismissEmptyReportsConfirmation), true),
});

const openCreateReportConfirmationRef = useRef(openCreateReportConfirmation);
Expand All @@ -208,9 +208,9 @@ function AttachmentPickerWithMenuItems({
if (shouldShowEmptyReportConfirmation) {
openCreateReportConfirmationRef.current();
} else {
createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, true, false);
createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, true, false);
}
}, [currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, report?.policyID, shouldShowEmptyReportConfirmation]);
}, [currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, shouldShowEmptyReportConfirmation]);

const teacherUnitePolicyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID;
const isTeachersUniteReport = report?.policyID === teacherUnitePolicyID;
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref

const handleCreateWorkspaceReport = useCallback(
(shouldDismissEmptyReportsConfirmation?: boolean) => {
if (!defaultChatEnabledPolicyID) {
if (!defaultChatEnabledPolicy?.id) {
return;
}

Expand All @@ -236,7 +236,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
currentUserPersonalDetails,
hasViolations,
isASAPSubmitBetaEnabled,
defaultChatEnabledPolicyID,
defaultChatEnabledPolicy,
false,
shouldDismissEmptyReportsConfirmation,
);
Expand All @@ -249,7 +249,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
);
});
},
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicyID, isASAPSubmitBetaEnabled, isReportInSearch],
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, isReportInSearch],
);

const {openCreateReportConfirmation: openFabCreateReportConfirmation, CreateReportConfirmationModal: FabCreateReportConfirmationModal} = useCreateEmptyReportConfirmation({
Expand Down
8 changes: 5 additions & 3 deletions src/pages/iou/request/step/IOURequestEditReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const [allPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}`, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const selectedReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${selectedReport?.policyID}`];

const hasPerDiemTransactions = useHasPerDiemTransactions(selectedTransactionIDs);

const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions);
Expand Down Expand Up @@ -91,12 +93,12 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
};

const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => {
if (!hasPerDiemTransactions && !policyForMovingExpensesID) {
if (!hasPerDiemTransactions && !policyForMovingExpenses?.id) {
return;
}

const policyForNewReportID = hasPerDiemTransactions ? selectedReport?.policyID : policyForMovingExpensesID;
const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReportID, false, shouldDismissEmptyReportsConfirmation);
const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;
const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReport, false, shouldDismissEmptyReportsConfirmation);
selectReport({value: optimisticReport.reportID}, optimisticReport);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, reportActionID, reportOrDraftReport, transaction);

const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => {
if (!isPerDiemTransaction && !policyForMovingExpensesID) {
if (!isPerDiemTransaction && !policyForMovingExpenses?.id) {
return;
}

const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy.id : policyForMovingExpensesID;
const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy : policyForMovingExpenses;
const optimisticReport = createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReport, false, shouldDismissEmptyReportsConfirmation);
handleRegularReportSelection({value: optimisticReport.reportID}, optimisticReport);
};
Expand Down
17 changes: 9 additions & 8 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8314,17 +8314,18 @@ describe('actions/IOU', () => {
const creatorPersonalDetails = personalDetailsList?.[CARLOS_ACCOUNT_ID] ?? {accountID: CARLOS_ACCOUNT_ID};

const policyID = generatePolicyID();
createWorkspace({
policyOwnerEmail: CARLOS_EMAIL,
makeMeAdmin: true,
policyName: "Carlos's Workspace",
policyID,
currency: CONST.CURRENCY.USD,
});
const mockPolicy: Policy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM, "Carlos's Workspace"),
id: policyID,
outputCurrency: CONST.CURRENCY.USD,
owner: CARLOS_EMAIL,
ownerAccountID: CARLOS_ACCOUNT_ID,
pendingAction: undefined,
};

await waitForBatchedUpdates();

createNewReport(creatorPersonalDetails, true, false, policyID);
createNewReport(creatorPersonalDetails, true, false, mockPolicy);
// Create a tracked expense
const selfDMReport: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM),
Expand Down
6 changes: 3 additions & 3 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ describe('actions/Report', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy);

mockFetchData.pause();
const {reportID} = Report.createNewReport({accountID}, true, false, policyID);
const {reportID} = Report.createNewReport({accountID}, true, false, policy);
const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID);

const reportPreviewAction = await new Promise<OnyxEntry<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW>>>((resolve) => {
Expand Down Expand Up @@ -1834,7 +1834,7 @@ describe('actions/Report', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy);

mockFetchData.pause();
Report.createNewReport({accountID}, true, false, policyID);
Report.createNewReport({accountID}, true, false, policy);
const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID);

await new Promise<void>((resolve) => {
Expand Down Expand Up @@ -1872,7 +1872,7 @@ describe('actions/Report', () => {
}

// When create new report
Report.createNewReport({accountID}, true, false, policyID);
Report.createNewReport({accountID}, true, false, policy);

// Then the parent report's hasOutstandingChildRequest property should remain unchanged
await new Promise<void>((resolve) => {
Expand Down
Loading