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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Icon from '@components/Icon';
import {loadExpensifyIconsChunk} from '@components/Icon/ExpensifyIconLoader';
import {loadIllustrationsChunk} from '@components/Icon/IllustrationLoader';
import {PressableWithoutFeedback} from '@components/Pressable';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useTheme from '@hooks/useTheme';
Expand All @@ -20,7 +21,6 @@ import Tab from '@userActions/Tab';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {sessionEmailAndAccountIDSelector} from '@src/selectors/Session';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand All @@ -34,6 +34,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {
const {textLight} = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const {accountID} = useCurrentUserPersonalDetails();

useEffect(() => {
loadIllustrationsChunk().catch(() => {});
Expand All @@ -42,7 +43,6 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {

const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: sessionEmailAndAccountIDSelector});
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
Expand All @@ -53,7 +53,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {
if (isEmptyObject(activePolicy) || !activePolicy?.isPolicyExpenseChatEnabled) {
return undefined;
}
const policyChatsForActivePolicy = getWorkspaceChats(activePolicyID, [session?.accountID ?? CONST.DEFAULT_NUMBER_ID], reports);
const policyChatsForActivePolicy = getWorkspaceChats(activePolicyID, [accountID], reports);
return policyChatsForActivePolicy.at(0);
};
const [policyChatForActivePolicy] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: policyChatForActivePolicySelector});
Expand All @@ -62,7 +62,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {
interceptAnonymousUser(() => {
if (
policyChatForActivePolicy?.policyID &&
shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)
shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, accountID)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policyChatForActivePolicy.policyID));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useEffect} from 'react';
import {View} from 'react-native';
import type {LayoutChangeEvent} from 'react-native';
import EmptyStateComponent from '@components/EmptyStateComponent';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -21,6 +22,7 @@ import type * as OnyxTypes from '@src/types/onyx';
const minModalHeight = 380;

function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report: OnyxTypes.Report; policy?: OnyxTypes.Policy; onLayout?: (event: LayoutChangeEvent) => void}) {
const {accountID} = useCurrentUserPersonalDetails();
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
Expand All @@ -44,7 +46,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -59,7 +61,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -71,7 +73,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
text: translate('iou.addUnreportedExpense'),
icon: icons.ReceiptPlus,
onSelected: () => {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
21 changes: 19 additions & 2 deletions src/components/Navigation/QuickCreationActionsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,30 @@ function QuickCreationActionsBar() {

if (
!workspaceIDForReportCreation ||
(shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultChatEnabledPolicy) &&
(shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
defaultChatEnabledPolicy,
currentUserPersonalDetails.accountID,
) &&
groupPoliciesWithChatEnabled.length > 1)
) {
Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute());
return;
}

if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultChatEnabledPolicy)) {
if (
!shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
defaultChatEnabledPolicy,
currentUserPersonalDetails.accountID,
)
) {
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
} else {
Expand All @@ -208,6 +224,7 @@ function QuickCreationActionsBar() {
shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy,
openCreateReportConfirmation,
handleCreateWorkspaceReport,
currentUserPersonalDetails.accountID,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,31 @@ function SearchActionsBarCreateButton() {
// No default or restricted with multiple workspaces → workspace selector
if (
!workspaceIDForReportCreation ||
(shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed) &&
(shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
undefined,
currentUserPersonalDetails.accountID,
) &&
groupPoliciesWithChatEnabled.length > 1)
) {
Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute());
return;
}

// Default workspace is not restricted → create report directly
if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (
!shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
undefined,
currentUserPersonalDetails.accountID,
)
) {
// Check if empty report confirmation should be shown
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
Expand Down Expand Up @@ -223,6 +239,7 @@ function SearchActionsBarCreateButton() {
openCreateReportConfirmation,
handleCreateWorkspaceReport,
amountOwed,
currentUserPersonalDetails.accountID,
],
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function SettlementButton({
return true;
}

if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReceiptScanDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function useReceiptScanDrop() {
if (
isPaidGroupPolicy(activePolicy) &&
activePolicy?.isPolicyExpenseChatEnabled &&
!shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)
!shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, currentUserPersonalDetails.accountID)
) {
const shouldAutoReport = !!activePolicy?.autoReporting || !!personalPolicy?.autoReporting;
const report = shouldAutoReport ? getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id) : selfDMReport;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
};

let deprecatedCurrentUserAccountID = -1;
Onyx.connect({

Check warning on line 56 in src/libs/SubscriptionUtils.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) => {
deprecatedCurrentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
Expand All @@ -61,7 +61,7 @@
});

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

Check warning on line 64 in src/libs/SubscriptionUtils.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,
callback: (value) => (deprecatedAllPolicies = value),
waitForCollectionCallback: true,
Expand Down Expand Up @@ -459,6 +459,7 @@
userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number>,
policy: OnyxEntry<Policy> = deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
currentUserAccountID: number = deprecatedCurrentUserAccountID,
): boolean {
const currentDate = new Date();

Expand All @@ -481,7 +482,7 @@
// If it reached here it means that the user is actually the workspace's owner.
// We should restrict the workspace's owner actions if it's past its grace period end date and it's owing some amount.
if (
isPolicyOwner(policy, deprecatedCurrentUserAccountID) &&
isPolicyOwner(policy, currentUserAccountID) &&
ownerBillingGracePeriodEnd &&
amountOwed !== undefined &&
amountOwed > 0 &&
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/components/SearchActionsBarCreateButtonTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {getUnixTime, subDays} from 'date-fns';
import React from 'react';
import Onyx from 'react-native-onyx';
import ComposeProviders from '@components/ComposeProviders';
import {CurrentUserPersonalDetailsProvider} from '@components/CurrentUserPersonalDetailsProvider';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxListItemProvider from '@components/OnyxListItemProvider';
import SearchActionsBarCreateButton from '@components/Search/SearchPageHeader/SearchActionsBarCreateButton';
Expand Down Expand Up @@ -76,7 +77,7 @@ const MOCK_POLICY = {

function renderComponent() {
return render(
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
<ComposeProviders components={[OnyxListItemProvider, CurrentUserPersonalDetailsProvider, LocaleContextProvider]}>
<SearchActionsBarCreateButton />
</ComposeProviders>,
);
Expand Down
Loading