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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {
interceptAnonymousUser(() => {
if (
policyChatForActivePolicy?.policyID &&
shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)
shouldRestrictUserBillableActions(session?.accountID, policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policyChatForActivePolicy.policyID));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import shouldUseDefaultExpensePolicyUtil from '@libs/shouldUseDefaultExpensePoli
import {shouldUpdateGpsNotificationUnit, updateGpsTripNotificationLanguage, updateGpsTripNotificationUnit} from '@pages/iou/request/step/IOURequestStepDistanceGPS/GPSNotifications';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {accountIDSelector} from '@src/selectors/Session';

function useUpdateGpsNotification() {
useUpdateGpsNotificationOnLanguageChange();
Expand Down Expand Up @@ -35,13 +36,21 @@ function useUpdateGpsNotificationOnLanguageChange() {
function useUpdateGpsNotificationOnUnitChange() {
const {translate} = useLocalize();

const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector});
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
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 [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`);

const defaultExpensePolicy = useDefaultExpensePolicy();
const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(CONST.IOU.TYPE.CREATE, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd);
const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(
accountID,
CONST.IOU.TYPE.CREATE,
defaultExpensePolicy,
amountOwed,
userBillingGracePeriodEnds,
ownerBillingGracePeriodEnd,
);

const unit = DistanceRequestUtils.getRate({transaction, policy: shouldUseDefaultExpensePolicy ? defaultExpensePolicy : undefined}).unit;

Expand Down
16 changes: 14 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
const addExpenseDropdownOptions = useMemo(
() =>
getAddExpenseDropdownOptions({
currentUserAccountID: accountID,
translate,
icons: expensifyIcons,
iouReportID: moneyRequestReport?.reportID,
Expand All @@ -1000,7 +1001,18 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
ownerBillingGracePeriodEnd,
lastDistanceExpenseType,
}),
[moneyRequestReport?.reportID, policy, userBillingGracePeriodEnds, amountOwed, lastDistanceExpenseType, expensifyIcons, translate, ownerBillingGracePeriodEnd, draftTransactionIDs],
[
moneyRequestReport?.reportID,
policy,
userBillingGracePeriodEnds,
amountOwed,
lastDistanceExpenseType,
expensifyIcons,
translate,
ownerBillingGracePeriodEnd,
draftTransactionIDs,
accountID,
],
);

const exportSubmenuOptions: Record<string, DropdownOption<string>> = useMemo(() => {
Expand Down Expand Up @@ -1780,7 +1792,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
if (!moneyRequestReport?.reportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(accountID, policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function MoneyRequestReportTransactionList({
const addExpenseDropdownOptions = useMemo(
() =>
getAddExpenseDropdownOptions({
currentUserAccountID: currentUserDetails.accountID,
translate,
icons: expensifyIcons,
iouReportID: report?.reportID,
Expand All @@ -190,7 +191,18 @@ function MoneyRequestReportTransactionList({
ownerBillingGracePeriodEnd,
lastDistanceExpenseType,
}),
[translate, expensifyIcons, report?.reportID, policy, userBillingGracePeriodEnds, amountOwed, lastDistanceExpenseType, ownerBillingGracePeriodEnd, draftTransactionIDs],
[
translate,
expensifyIcons,
report?.reportID,
policy,
userBillingGracePeriodEnds,
amountOwed,
lastDistanceExpenseType,
ownerBillingGracePeriodEnd,
draftTransactionIDs,
currentUserDetails.accountID,
],
);

const hasPendingAction = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 [session] = useOnyx(ONYXKEYS.SESSION);
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 +45,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(session?.accountID, policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -59,7 +60,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(session?.accountID, policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -71,7 +72,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(session?.accountID, policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
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 @@ -176,14 +176,30 @@ function QuickCreationActionsBar() {

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

if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, undefined, defaultChatEnabledPolicy)) {
if (
!shouldRestrictUserBillableActions(
session?.accountID,
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
undefined,
defaultChatEnabledPolicy,
)
) {
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
} else {
Expand All @@ -206,6 +222,7 @@ function QuickCreationActionsBar() {
shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy,
openCreateReportConfirmation,
handleCreateWorkspaceReport,
session?.accountID,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function ReportPreviewActionButton({
shouldAlwaysShowDropdownMenu
customText={translate('iou.addExpense')}
options={getAddExpenseDropdownOptions({
currentUserAccountID: currentUserDetails.accountID,
translate,
icons: expensifyIcons,
iouReportID: iouReport?.reportID,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Search/SearchBulkActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
const {showLockedAccountModal} = useLockedAccountActions();
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [session] = useOnyx(ONYXKEYS.SESSION);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector});
const activeAdminPolicies = useSortedActiveAdminPolicies();
Expand Down Expand Up @@ -156,6 +157,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
userBillingGracePeriodEnds,
amountOwed,
ownerBillingGracePeriodEnd,
currentUserAccountID: session?.accountID,
setPendingPaymentAdditionalData: (data) => {
pendingPaymentAdditionalDataRef.current = data;
},
Expand Down Expand Up @@ -197,6 +199,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
userBillingGracePeriodEnds,
amountOwed,
ownerBillingGracePeriodEnd,
currentUserAccountID: session?.accountID,
setPendingPaymentAdditionalData: (data) => {
pendingPaymentAdditionalDataRef.current = data;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
currentUserAccountID: currentUserDetails.accountID,
});
}, [
currentSearchHash,
Expand All @@ -158,6 +159,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
isDelegateAccessRestricted,
showDelegateNoAccessModal,
ownerBillingGracePeriodEnd,
currentUserDetails.accountID,
]);

const handleCheckboxPress = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function ReportListItemHeader<TItem extends ListItem>({
const theme = useTheme();
const {currentSearchHash, currentSearchKey, currentSearchResults: snapshot} = useSearchStateContext();
const {isLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const [session] = useOnyx(ONYXKEYS.SESSION);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const thereIsFromAndTo = !!reportItem?.from && !!reportItem?.to;
const showUserInfo = (reportItem.type === CONST.REPORT.TYPE.IOU && thereIsFromAndTo) || (reportItem.type === CONST.REPORT.TYPE.EXPENSE && !!reportItem?.from);
Expand Down Expand Up @@ -246,6 +247,7 @@ function ReportListItemHeader<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
currentUserAccountID: session?.accountID,
});
};
return !isLargeScreenWidth ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function TransactionListItem<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
currentUserAccountID: currentUserDetails.accountID,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ function SearchActionsBarCreateButton() {
// No default or restricted with multiple workspaces → workspace selector
if (
!workspaceIDForReportCreation ||
(shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed) &&
(shouldRestrictUserBillableActions(session?.accountID, workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed) &&
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(session?.accountID, workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
// Check if empty report confirmation should be shown
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
Expand Down Expand Up @@ -223,6 +223,7 @@ function SearchActionsBarCreateButton() {
openCreateReportConfirmation,
handleCreateWorkspaceReport,
amountOwed,
session?.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 @@ -224,7 +224,7 @@ function SettlementButton({
return true;
}

if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(currentUserAccountID, policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
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(currentUserPersonalDetails.accountID, activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)
) {
const shouldAutoReport = !!activePolicy?.autoReporting || !!personalPolicy?.autoReporting;
const report = shouldAutoReport ? getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id) : selfDMReport;
Expand Down
Loading
Loading