Skip to content

Commit 8086159

Browse files
committed
Revert 'Merge pull request Expensify#66059 from getusha/fix-prevent-snapshot-use-in-settlement-button'
1 parent d42bc14 commit 8086159

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

src/components/SettlementButton/index.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {LockedAccountContext} from '@components/LockedAccountModalProvider';
1212
import useLocalize from '@hooks/useLocalize';
1313
import useNetwork from '@hooks/useNetwork';
1414
import useOnyx from '@hooks/useOnyx';
15-
import usePolicy from '@hooks/usePolicy';
1615
import useThemeStyles from '@hooks/useThemeStyles';
1716
import {isCurrencySupportedForDirectReimbursement} from '@libs/actions/Policy/Policy';
1817
import {getCurrentUserAccountID} from '@libs/actions/Report';
@@ -89,7 +88,6 @@ function SettlementButton({
8988
const styles = useThemeStyles();
9089
const {translate} = useLocalize();
9190
const {isOffline} = useNetwork();
92-
9391
// The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
9492
// eslint-disable-next-line rulesdir/no-default-id-values
9593
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID || CONST.DEFAULT_NUMBER_ID}`, {canBeMissing: true});
@@ -109,18 +107,14 @@ function SettlementButton({
109107
const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
110108
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
111109
const currentUserAccountID = getCurrentUserAccountID().toString();
112-
113-
// Passing `undefined` to ensure we use the Onyx connection from PolicyUtils,
114-
// since `useOnyx` only returns snapshot data on the SearchPage.
115-
// By passing `undefined`, we fall back to the function's default value.
116-
const activeAdminPolicies = getActiveAdminWorkspaces(undefined, currentUserAccountID).sort((a, b) => (a.name || '').localeCompare(b.name || ''));
110+
const activeAdminPolicies = getActiveAdminWorkspaces(policies, currentUserAccountID).sort((a, b) => (a.name || '').localeCompare(b.name || ''));
117111
const reportID = iouReport?.reportID;
118112

119113
const hasPreferredPaymentMethod = !!lastPaymentMethod;
120114
const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
121115
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
122-
const lastPaymentPolicy = usePolicy(lastPaymentMethod);
123-
116+
const isLastPaymentPolicy = !Object.values({...CONST.PAYMENT_METHODS, ...CONST.IOU.PAYMENT_TYPE}).includes(lastPaymentMethod as PaymentMethod);
117+
const lastPaymentPolicy = isLastPaymentPolicy ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${lastPaymentMethod}`] : undefined;
124118
const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
125119
const bankAccount = bankAccountList[lastBankAccountID ?? CONST.DEFAULT_NUMBER_ID];
126120
const isExpenseReport = isExpenseReportUtil(iouReport);

src/libs/PolicyUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ function getPolicy(policyID: string | undefined, policies: OnyxCollection<Policy
755755
}
756756

757757
/** Return active policies where current user is an admin */
758-
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null | undefined, currentUserLogin: string | undefined): Policy[] {
759-
const activePolicies = getActivePolicies(policies === undefined ? allPolicies : policies, currentUserLogin);
758+
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
759+
const activePolicies = getActivePolicies(policies, currentUserLogin);
760760
return activePolicies.filter((policy) => shouldShowPolicy(policy, isOfflineNetworkStore(), currentUserLogin) && isPolicyAdmin(policy, currentUserLogin));
761761
}
762762

0 commit comments

Comments
 (0)