Skip to content

Commit 6f0ddc3

Browse files
authored
Merge pull request Expensify#84751 from bernhardoj/chore/66456-remove-onyx-connect-shared-billing-grace-period-subscription-utils-7
Expensify#7 - Get the billing grace end period collection with useOnyx
2 parents 4e02280 + 100de38 commit 6f0ddc3

24 files changed

Lines changed: 110 additions & 97 deletions

src/components/MoneyReportHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ function MoneyReportHeader({
12151215
icons: expensifyIcons,
12161216
iouReportID: moneyRequestReport?.reportID,
12171217
policy,
1218-
userBillingGraceEndPeriodCollection: userBillingGraceEndPeriods,
1218+
userBillingGraceEndPeriods,
12191219
draftTransactionIDs,
12201220
amountOwed,
12211221
ownerBillingGraceEndPeriod,

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function MoneyRequestReportTransactionList({
189189
const currentUserDetails = useCurrentUserPersonalDetails();
190190
const isReportArchived = useReportIsArchived(report?.reportID);
191191
const shouldShowAddExpenseButton = canAddTransaction(report, isReportArchived) && isCurrentUserSubmitter(report);
192-
const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
192+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
193193
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
194194
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE);
195195
const [reportLayoutGroupBy] = useOnyx(ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY);
@@ -207,13 +207,13 @@ function MoneyRequestReportTransactionList({
207207
icons: expensifyIcons,
208208
iouReportID: report?.reportID,
209209
policy,
210-
userBillingGraceEndPeriodCollection,
210+
userBillingGraceEndPeriods,
211211
draftTransactionIDs,
212212
amountOwed,
213213
ownerBillingGraceEndPeriod,
214214
lastDistanceExpenseType,
215215
}),
216-
[translate, expensifyIcons, report?.reportID, policy, userBillingGraceEndPeriodCollection, amountOwed, lastDistanceExpenseType, ownerBillingGraceEndPeriod, draftTransactionIDs],
216+
[translate, expensifyIcons, report?.reportID, policy, userBillingGraceEndPeriods, amountOwed, lastDistanceExpenseType, ownerBillingGraceEndPeriod, draftTransactionIDs],
217217
);
218218

219219
const hasPendingAction = useMemo(() => {

src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type * as OnyxTypes from '@src/types/onyx';
2121
const minModalHeight = 380;
2222

2323
function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report: OnyxTypes.Report; policy?: OnyxTypes.Policy; onLayout?: (event: LayoutChangeEvent) => void}) {
24-
const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
24+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
2525
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
2626
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
2727
const {translate} = useLocalize();
@@ -43,7 +43,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
4343
if (!reportId) {
4444
return;
4545
}
46-
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, undefined, ownerBillingGraceEndPeriod)) {
46+
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, undefined, ownerBillingGraceEndPeriod)) {
4747
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
4848
return;
4949
}
@@ -58,7 +58,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
5858
if (!reportId) {
5959
return;
6060
}
61-
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, undefined, ownerBillingGraceEndPeriod)) {
61+
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, undefined, ownerBillingGraceEndPeriod)) {
6262
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
6363
return;
6464
}
@@ -70,7 +70,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
7070
text: translate('iou.addUnreportedExpense'),
7171
icon: icons.ReceiptPlus,
7272
onSelected: () => {
73-
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, undefined, ownerBillingGraceEndPeriod)) {
73+
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, undefined, ownerBillingGraceEndPeriod)) {
7474
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
7575
return;
7676
}

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ function MoneyRequestReportPreviewContent({
717717
icons: expensifyIcons,
718718
iouReportID: iouReport?.reportID,
719719
policy,
720-
userBillingGraceEndPeriodCollection: userBillingGraceEndPeriods,
720+
userBillingGraceEndPeriods,
721721
draftTransactionIDs,
722722
amountOwed,
723723
ownerBillingGraceEndPeriod,

src/components/Search/SearchPageHeader/SearchFiltersBarCreateButton.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function SearchFiltersBarCreateButton() {
5959
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
6060
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
6161
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
62+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
6263
const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses();
6364
const shouldNavigateToUpgradePath = !policyForMovingExpensesID && !shouldSelectPolicy;
6465
const {showConfirmModal} = useConfirmModal();
@@ -184,14 +185,15 @@ function SearchFiltersBarCreateButton() {
184185
// No default or restricted with multiple workspaces → workspace selector
185186
if (
186187
!workspaceIDForReportCreation ||
187-
(shouldRestrictUserBillableActions(workspaceIDForReportCreation, undefined, undefined, ownerBillingGraceEndPeriod) && groupPoliciesWithChatEnabled.length > 1)
188+
(shouldRestrictUserBillableActions(workspaceIDForReportCreation, userBillingGraceEndPeriods, undefined, ownerBillingGraceEndPeriod) &&
189+
groupPoliciesWithChatEnabled.length > 1)
188190
) {
189191
Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute());
190192
return;
191193
}
192194

193195
// Default workspace is not restricted → create report directly
194-
if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, undefined, undefined, ownerBillingGraceEndPeriod)) {
196+
if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, userBillingGraceEndPeriods, undefined, ownerBillingGraceEndPeriod)) {
195197
// Check if empty report confirmation should be shown
196198
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
197199
openCreateReportConfirmation();
@@ -215,6 +217,8 @@ function SearchFiltersBarCreateButton() {
215217
groupPoliciesWithChatEnabled.length,
216218
defaultChatEnabledPolicyID,
217219
shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy,
220+
ownerBillingGraceEndPeriod,
221+
userBillingGraceEndPeriods,
218222
openCreateReportConfirmation,
219223
handleCreateWorkspaceReport,
220224
],

src/components/SelectionListWithSections/Search/ExpenseReportListItem.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
5454
const {translate} = useLocalize();
5555
const {isLargeScreenWidth} = useResponsiveLayout();
5656
const {currentSearchHash, currentSearchKey, currentSearchResults} = useSearchStateContext();
57+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
5758
const [isActionLoading] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportItem.reportID}`, {selector: isActionLoadingSelector});
5859
const expensifyIcons = useMemoizedLazyExpensifyIcons(['DotIndicator']);
5960
const currentUserDetails = useCurrentUserPersonalDetails();
@@ -129,6 +130,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
129130
snapshotReport,
130131
snapshotPolicy,
131132
lastPaymentMethod,
133+
userBillingGraceEndPeriods,
132134
currentSearchKey,
133135
onDEWModalOpen,
134136
isDEWBetaEnabled,
@@ -143,6 +145,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
143145
snapshotReport,
144146
snapshotPolicy,
145147
lastPaymentMethod,
148+
userBillingGraceEndPeriods,
146149
personalPolicyID,
147150
currentSearchKey,
148151
onDEWModalOpen,

src/components/SelectionListWithSections/Search/ReportListItemHeader.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ function ReportListItemHeader<TItem extends ListItem>({
223223
const theme = useTheme();
224224
const {currentSearchHash, currentSearchKey, currentSearchResults: snapshot} = useSearchStateContext();
225225
const {isLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
226+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
226227
const thereIsFromAndTo = !!reportItem?.from && !!reportItem?.to;
227228
const showUserInfo = (reportItem.type === CONST.REPORT.TYPE.IOU && thereIsFromAndTo) || (reportItem.type === CONST.REPORT.TYPE.EXPENSE && !!reportItem?.from);
228229
const snapshotReport = useMemo(() => {
@@ -245,6 +246,7 @@ function ReportListItemHeader<TItem extends ListItem>({
245246
snapshotReport,
246247
snapshotPolicy,
247248
lastPaymentMethod,
249+
userBillingGraceEndPeriods,
248250
currentSearchKey,
249251
onDEWModalOpen,
250252
isDEWBetaEnabled,

src/components/SelectionListWithSections/Search/TransactionListItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function TransactionListItem<TItem extends ListItem>({
6161
const {currentSearchHash, currentSearchKey, currentSearchResults} = useSearchStateContext();
6262
const snapshotReport = (currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`] ?? {}) as Report;
6363

64+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
6465
const [isActionLoading] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`, {selector: isActionLoadingSelector});
6566

6667
// Use active policy (user's current workspace) as fallback for self DM tracking expenses
@@ -158,6 +159,7 @@ function TransactionListItem<TItem extends ListItem>({
158159
snapshotReport,
159160
snapshotPolicy,
160161
lastPaymentMethod,
162+
userBillingGraceEndPeriods,
161163
currentSearchKey,
162164
onDEWModalOpen,
163165
isDEWBetaEnabled,

src/hooks/useSearchBulkActions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
101101
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION);
102102
const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
103103
const personalPolicy = usePersonalPolicy();
104-
const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
104+
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
105105

106106
// Cache the last search results that had data, so the merge option remains available
107107
// while results are temporarily unset (e.g. during sorting/loading).
@@ -379,7 +379,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
379379

380380
const selectedItems = selectedReports.length ? selectedReports : Object.values(selectedTransactions);
381381

382-
const restrictedPolicyID = getRestrictedPolicyID(selectedItems, userBillingGraceEndPeriodCollection);
382+
const restrictedPolicyID = getRestrictedPolicyID(selectedItems, userBillingGraceEndPeriods);
383383
if (restrictedPolicyID) {
384384
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(restrictedPolicyID));
385385
return;
@@ -428,7 +428,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
428428
translate,
429429
hash,
430430
clearSelectedTransactions,
431-
userBillingGraceEndPeriodCollection,
431+
userBillingGraceEndPeriods,
432432
]);
433433

434434
const {expenseCount, uniqueReportCount} = useMemo(() => {
@@ -557,7 +557,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
557557
const selectedOptions = selectedReports.length ? selectedReports : Object.values(selectedTransactions);
558558
const expenseReportBankAccountID = additionalData?.bankAccountID;
559559

560-
const restrictedPolicyID = getRestrictedPolicyID(selectedOptions, userBillingGraceEndPeriodCollection);
560+
const restrictedPolicyID = getRestrictedPolicyID(selectedOptions, userBillingGraceEndPeriods);
561561
if (restrictedPolicyID) {
562562
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(restrictedPolicyID));
563563
return;
@@ -678,7 +678,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
678678
personalPolicyID,
679679
allTransactions,
680680
allReports,
681-
userBillingGraceEndPeriodCollection,
681+
userBillingGraceEndPeriods,
682682
],
683683
);
684684

@@ -962,7 +962,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
962962

963963
const itemList = !selectedReports.length ? Object.values(selectedTransactions).map((transaction) => transaction) : (selectedReports?.filter((report) => !!report) ?? []);
964964

965-
const restrictedPolicyID = getRestrictedPolicyID(itemList, userBillingGraceEndPeriodCollection);
965+
const restrictedPolicyID = getRestrictedPolicyID(itemList, userBillingGraceEndPeriods);
966966
if (restrictedPolicyID) {
967967
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(restrictedPolicyID));
968968
return;
@@ -1222,7 +1222,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
12221222
styles.colorMuted,
12231223
styles.fontWeightNormal,
12241224
styles.textWrap,
1225-
userBillingGraceEndPeriodCollection,
1225+
userBillingGraceEndPeriods,
12261226
currentSearchKey,
12271227
]);
12281228

src/libs/ReportUtils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,7 @@ type GetAddExpenseDropdownOptionsParams = {
30133013
icons: Record<'Location' | 'ReceiptPlus', IconAsset>;
30143014
iouReportID: string | undefined;
30153015
policy: OnyxEntry<Policy>;
3016-
userBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod>;
3016+
userBillingGraceEndPeriods: OnyxCollection<BillingGraceEndPeriod>;
30173017
draftTransactionIDs: string[] | undefined;
30183018
amountOwed: OnyxEntry<number>;
30193019
ownerBillingGraceEndPeriod: OnyxEntry<number>;
@@ -3027,7 +3027,7 @@ function getAddExpenseDropdownOptions({
30273027
icons,
30283028
iouReportID,
30293029
policy,
3030-
userBillingGraceEndPeriodCollection,
3030+
userBillingGraceEndPeriods,
30313031
draftTransactionIDs,
30323032
amountOwed,
30333033
ownerBillingGraceEndPeriod,
@@ -3048,7 +3048,7 @@ function getAddExpenseDropdownOptions({
30483048
if (
30493049
policy &&
30503050
policy.type !== CONST.POLICY.TYPE.PERSONAL &&
3051-
shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)
3051+
shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, amountOwed, ownerBillingGraceEndPeriod)
30523052
) {
30533053
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30543054
return;
@@ -3065,7 +3065,7 @@ function getAddExpenseDropdownOptions({
30653065
if (!iouReportID) {
30663066
return;
30673067
}
3068-
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)) {
3068+
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, amountOwed, ownerBillingGraceEndPeriod)) {
30693069
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30703070
return;
30713071
}
@@ -3078,7 +3078,7 @@ function getAddExpenseDropdownOptions({
30783078
icon: icons.ReceiptPlus,
30793079
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_UNREPORTED,
30803080
onSelected: () => {
3081-
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)) {
3081+
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, amountOwed, ownerBillingGraceEndPeriod)) {
30823082
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30833083
return;
30843084
}
@@ -11245,7 +11245,7 @@ type CreateDraftTransactionParams = {
1124511245
introSelected: OnyxEntry<IntroSelected>;
1124611246
allTransactionDrafts: OnyxCollection<Transaction>;
1124711247
activePolicy: OnyxEntry<Policy>;
11248-
userBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod>;
11248+
userBillingGraceEndPeriods: OnyxCollection<BillingGraceEndPeriod>;
1124911249
amountOwed: OnyxEntry<number>;
1125011250
isRestrictedToPreferredPolicy?: boolean;
1125111251
preferredPolicyID?: string;
@@ -11259,7 +11259,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({
1125911259
introSelected,
1126011260
allTransactionDrafts,
1126111261
activePolicy,
11262-
userBillingGraceEndPeriodCollection,
11262+
userBillingGraceEndPeriods,
1126311263
amountOwed,
1126411264
isRestrictedToPreferredPolicy = false,
1126511265
preferredPolicyID,
@@ -11326,7 +11326,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({
1132611326
}
1132711327

1132811328
if (actionName === CONST.IOU.ACTION.CATEGORIZE) {
11329-
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, userBillingGraceEndPeriodCollection, amountOwed)) {
11329+
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, userBillingGraceEndPeriods, amountOwed)) {
1133011330
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
1133111331
return;
1133211332
}

0 commit comments

Comments
 (0)