diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index 3c0e50b2c940..2f8b7b26197e 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -9,7 +9,6 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import SpacerView from '@components/SpacerView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import usePermissions from '@hooks/usePermissions'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -42,7 +41,6 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); - const {canUseReportFields} = usePermissions(); const isSettled = ReportUtils.isSettled(report.reportID); const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(report); @@ -68,7 +66,7 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont - {canUseReportFields && + {ReportUtils.reportFieldsEnabled(report) && sortedPolicyReportFields.map((reportField) => { const isTitleField = ReportUtils.isReportFieldOfTypeTitle(reportField); const fieldValue = isTitleField ? report.reportName : reportField.value ?? reportField.defaultValue; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 568ce49ff961..7e707c15771b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1895,6 +1895,13 @@ function isReportFieldOfTypeTitle(reportField: OnyxEntry): bo return reportField?.type === 'formula' && reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; } +/** + * Check if report fields are available to use in a report + */ +function reportFieldsEnabled(report: Report) { + return Permissions.canUseReportFields(allBetas ?? []) && isPaidGroupPolicyExpenseReport(report); +} + /** * Given a report field, check if the field can be edited or not. * For title fields, its considered disabled if `deletable` prop is `true` (https://github.com/Expensify/App/issues/35043#issuecomment-1911275433) @@ -1952,7 +1959,7 @@ function getMoneyRequestReportName(report: OnyxEntry, policy: OnyxEntry< const reportFields = isReportSettled ? report?.reportFields : getReportFieldsByPolicyID(report?.policyID ?? ''); const titleReportField = getFormulaTypeReportField(reportFields ?? {}); - if (titleReportField && report?.reportName && Permissions.canUseReportFields(allBetas ?? [])) { + if (titleReportField && report?.reportName && reportFieldsEnabled(report)) { return report.reportName; } @@ -4948,6 +4955,7 @@ export { isReportFieldOfTypeTitle, isReportFieldDisabled, getAvailableReportFields, + reportFieldsEnabled, getAllAncestorReportActionIDs, };