Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@
};

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

Check warning on line 1015 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 @@ -1020,7 +1020,7 @@
});

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

Check warning on line 1023 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 @@ -1038,7 +1038,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1041 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 (currentUserAccountID) {
Expand All @@ -1050,7 +1050,7 @@
});

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

Check warning on line 1053 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 @@ -1059,7 +1059,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1062 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 @@ -1070,7 +1070,7 @@
});

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

Check warning on line 1073 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 @@ -1078,7 +1078,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
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.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1114,14 +1114,14 @@
});

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

Check warning on line 1117 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 allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1124 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 @@ -1147,7 +1147,7 @@
});

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

Check warning on line 1150 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 @@ -11083,6 +11083,7 @@
introSelected: OnyxEntry<IntroSelected>,
allTransactionDrafts: OnyxCollection<Transaction>,
activePolicy: OnyxEntry<Policy>,
userBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod>,
isRestrictedToPreferredPolicy = false,
preferredPolicyID?: string,
): void {
Expand Down Expand Up @@ -11148,7 +11149,7 @@
}

if (actionName === CONST.IOU.ACTION.CATEGORIZE) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id)) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, userBillingGraceEndPeriodCollection)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Users', 'Gear', 'Send', 'Folder', 'UserPlus', 'Pencil', 'Checkmark', 'Building', 'Exit', 'Bug', 'Camera', 'Trashcan']);
const backTo = route.params.backTo;

const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END, {canBeMissing: true});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, {canBeMissing: true});
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
Expand Down Expand Up @@ -458,6 +459,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
introSelected,
allTransactionDrafts,
activePolicy,
undefined,
isRestrictedToPreferredPolicy,
preferredPolicyID,
);
Expand All @@ -479,6 +481,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
introSelected,
allTransactionDrafts,
activePolicy,
userBillingGraceEndPeriodCollection,
);
},
});
Expand All @@ -497,6 +500,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
introSelected,
allTransactionDrafts,
activePolicy,
undefined,
);
},
});
Expand Down Expand Up @@ -623,6 +627,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
activePolicy,
parentReport,
reportActionsForOriginalReportID,
userBillingGraceEndPeriodCollection,
]);

const displayNamesWithTooltips = useMemo(() => {
Expand Down
8 changes: 8 additions & 0 deletions src/pages/inbox/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ type PureReportActionItemProps = {
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
allTransactionDrafts: OnyxCollection<OnyxTypes.Transaction>,
activePolicy: OnyxEntry<OnyxTypes.Policy>,
userBillingGraceEndPeriodCollection: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>,
isRestrictedToPreferredPolicy?: boolean,
preferredPolicyID?: string,
) => void;
Expand Down Expand Up @@ -473,6 +474,8 @@ type PureReportActionItemProps = {

/** Report metadata for the report */
reportMetadata?: OnyxEntry<OnyxTypes.ReportMetadata>;

userBillingGraceEndPeriodCollection: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>;
};

// This is equivalent to returning a negative boolean in normal functions, but we can keep the element return type
Expand Down Expand Up @@ -548,6 +551,7 @@ function PureReportActionItem({
reportNameValuePairsOrigin,
reportNameValuePairsOriginalID,
reportMetadata,
userBillingGraceEndPeriodCollection,
}: PureReportActionItemProps) {
const {transitionActionSheetState} = ActionSheetAwareScrollView.useActionSheetAwareScrollViewActions();
const {translate, formatPhoneNumber, localeCompare, formatTravelDate, getLocalDateFromDatetime, datetimeToCalendarTime} = useLocalize();
Expand Down Expand Up @@ -946,6 +950,7 @@ function PureReportActionItem({
introSelected,
allTransactionDrafts,
activePolicy,
undefined,
isRestrictedToPreferredPolicy,
preferredPolicyID,
);
Expand All @@ -967,6 +972,7 @@ function PureReportActionItem({
introSelected,
allTransactionDrafts,
activePolicy,
userBillingGraceEndPeriodCollection,
);
},
},
Expand All @@ -982,6 +988,7 @@ function PureReportActionItem({
introSelected,
allTransactionDrafts,
activePolicy,
undefined,
);
},
},
Expand Down Expand Up @@ -1126,6 +1133,7 @@ function PureReportActionItem({
report,
originalReport,
personalPolicyID,
userBillingGraceEndPeriodCollection,
]);

/**
Expand Down
4 changes: 3 additions & 1 deletion src/pages/inbox/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import PureReportActionItem from './PureReportActionItem';

type ReportActionItemProps = Omit<
PureReportActionItemProps,
'taskReport' | 'linkedReport' | 'iouReportOfLinkedReport' | 'currentUserAccountID' | 'personalPolicyID' | 'allTransactionDrafts'
'taskReport' | 'linkedReport' | 'iouReportOfLinkedReport' | 'currentUserAccountID' | 'personalPolicyID' | 'allTransactionDrafts' | 'userBillingGraceEndPeriodCollection'
> & {
/** All the data of the report collection */
allReports: OnyxCollection<Report>;
Expand Down Expand Up @@ -110,6 +110,7 @@ function ReportActionItem({
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END, {canBeMissing: true});
const transactionsOnIOUReport = useReportTransactions(iouReport?.reportID);
const transactionID = isMoneyRequestAction(action) && getOriginalMessage(action)?.IOUTransactionID;

Expand Down Expand Up @@ -192,6 +193,7 @@ function ReportActionItem({
isTryNewDotNVPDismissed={isTryNewDotNVPDismissed}
bankAccountList={bankAccountList}
reportMetadata={reportMetadata}
userBillingGraceEndPeriodCollection={userBillingGraceEndPeriodCollection}
/>
);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
{},
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1149,6 +1150,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
{},
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1559,6 +1561,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
allTransactionDrafts,
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1605,6 +1608,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
{},
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1640,6 +1644,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
{},
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1670,6 +1675,7 @@ describe('actions/IOU', () => {
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
{},
undefined,
undefined,
);
await waitForBatchedUpdates();

Expand Down
6 changes: 6 additions & 0 deletions tests/ui/PureReportActionItemTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('PureReportActionItem', () => {
iouReportOfLinkedReport={undefined}
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down Expand Up @@ -292,6 +293,7 @@ describe('PureReportActionItem', () => {
reportMetadata={reportMetadata}
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down Expand Up @@ -350,6 +352,7 @@ describe('PureReportActionItem', () => {
iouReportOfLinkedReport={undefined}
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down Expand Up @@ -420,6 +423,7 @@ describe('PureReportActionItem', () => {
iouReportOfLinkedReport={undefined}
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down Expand Up @@ -485,6 +489,7 @@ describe('PureReportActionItem', () => {
iouReportOfLinkedReport={undefined}
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down Expand Up @@ -537,6 +542,7 @@ describe('PureReportActionItem', () => {
currentUserAccountID={ACTOR_ACCOUNT_ID}
allTransactionDrafts={undefined}
modifiedExpenseMessage={modifiedExpenseMessage}
userBillingGraceEndPeriodCollection={undefined}
/>
</PortalProvider>
</ScreenWrapper>
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12136,7 +12136,7 @@ describe('ReportUtils', () => {
await Onyx.merge(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END, Math.floor(Date.now() / 1000) - 3600);

// When we call createDraftTransactionAndNavigateToParticipantSelector with the restricted policy
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy, undefined);

// Then it should navigate to the restricted action page
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
Expand Down Expand Up @@ -12164,7 +12164,7 @@ describe('ReportUtils', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseReport.reportID}`, policyExpenseReport);

// When we call createDraftTransactionAndNavigateToParticipantSelector
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy, undefined);

// Then it should navigate to the category step
expect(Navigation.navigate).toHaveBeenCalledWith(
Expand Down Expand Up @@ -12194,7 +12194,7 @@ describe('ReportUtils', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseReport.reportID}`, policyExpenseReport);

// When we call createDraftTransactionAndNavigateToParticipantSelector with undefined activePolicy
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '2', CONST.IOU.ACTION.CATEGORIZE, '2', undefined, undefined, undefined);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '2', CONST.IOU.ACTION.CATEGORIZE, '2', undefined, undefined, undefined, undefined);

// Then it should automatically pick the available policy and navigate to the category step
expect(Navigation.navigate).toHaveBeenCalledWith(
Expand All @@ -12211,7 +12211,7 @@ describe('ReportUtils', () => {
await Onyx.setCollection(ONYXKEYS.COLLECTION.POLICY, {});

// When we call createDraftTransactionAndNavigateToParticipantSelector with undefined activePolicy
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, undefined);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, undefined, undefined);

// Then it should navigate to the upgrade page because no policies were found to categorize with
expect(Navigation.navigate).toHaveBeenCalledWith(
Expand Down Expand Up @@ -12249,7 +12249,7 @@ describe('ReportUtils', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policy2.id}`, policy2);

// When we call createDraftTransactionAndNavigateToParticipantSelector with undefined activePolicy
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, undefined);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, undefined, undefined);

// Then it should navigate to the upgrade page because it's ambiguous which policy to use
expect(Navigation.navigate).toHaveBeenCalledWith(
Expand Down Expand Up @@ -12283,7 +12283,7 @@ describe('ReportUtils', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${activePolicy.id}`, activePolicy);

// When we call createDraftTransactionAndNavigateToParticipantSelector
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy);
createDraftTransactionAndNavigateToParticipantSelector(transaction.transactionID, '1', CONST.IOU.ACTION.CATEGORIZE, '1', undefined, undefined, activePolicy, undefined);

// Then it should log a warning and not navigate
expect(logWarnSpy).toHaveBeenCalledWith('policyExpenseReportID is not valid during expense categorizing');
Expand Down
Loading