Skip to content
Merged
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
24 changes: 12 additions & 12 deletions src/pages/workspace/rules/IndividualExpenseRulesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import {openExternalLink} from '@libs/actions/Link';
import {setWorkspaceEReceiptsEnabled} from '@libs/actions/Policy/Policy';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {ThemeStyles} from '@styles/index';
import * as Link from '@userActions/Link';
import * as PolicyActions from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';
Expand All @@ -39,7 +39,7 @@ type IndividualExpenseRulesMenuItem = {
};

function IndividualExpenseRulesSectionSubtitle({policy, translate, styles}: IndividualExpenseRulesSectionSubtitleProps) {
const policyID = policy?.id ?? '-1';
const policyID = policy?.id;

const handleOnPressCategoriesLink = () => {
if (policy?.areCategoriesEnabled) {
Expand Down Expand Up @@ -88,27 +88,27 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
const policyCurrency = policy?.outputCurrency ?? CONST.CURRENCY.USD;

const maxExpenseAmountNoReceiptText = useMemo(() => {
if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt) {
if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE) {
return '';
}

return CurrencyUtils.convertToDisplayString(policy?.maxExpenseAmountNoReceipt, policyCurrency);
return convertToDisplayString(policy?.maxExpenseAmountNoReceipt, policyCurrency);
}, [policy?.maxExpenseAmountNoReceipt, policyCurrency]);

const maxExpenseAmountText = useMemo(() => {
if (policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmount) {
if (policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE) {
return '';
}

return CurrencyUtils.convertToDisplayString(policy?.maxExpenseAmount, policyCurrency);
return convertToDisplayString(policy?.maxExpenseAmount, policyCurrency);
}, [policy?.maxExpenseAmount, policyCurrency]);

const maxExpenseAgeText = useMemo(() => {
if (policy?.maxExpenseAge === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAge) {
if (policy?.maxExpenseAge === CONST.DISABLED_MAX_EXPENSE_VALUE) {
return '';
}

return translate('workspace.rules.individualExpenseRules.maxExpenseAgeDays', {count: policy?.maxExpenseAge});
return translate('workspace.rules.individualExpenseRules.maxExpenseAgeDays', {count: policy?.maxExpenseAge ?? 0});
}, [policy?.maxExpenseAge, translate]);

const billableModeText = translate(`workspace.rules.individualExpenseRules.${policy?.defaultBillable ? 'billable' : 'nonBillable'}`);
Expand Down Expand Up @@ -180,7 +180,7 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
<Switch
isOn={areEReceiptsEnabled}
accessibilityLabel={translate('workspace.rules.individualExpenseRules.eReceipts')}
onToggle={() => PolicyActions.setWorkspaceEReceiptsEnabled(policyID, !areEReceiptsEnabled)}
onToggle={() => setWorkspaceEReceiptsEnabled(policyID, !areEReceiptsEnabled)}
disabled={policyCurrency !== CONST.CURRENCY.USD}
/>
</View>
Expand All @@ -189,7 +189,7 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
<Text style={[styles.textLabel, styles.colorMuted]}>{translate('workspace.rules.individualExpenseRules.eReceiptsHint')}</Text>{' '}
<TextLink
style={[styles.textLabel, styles.link]}
onPress={() => Link.openExternalLink(CONST.DEEP_DIVE_ERECEIPTS)}
onPress={() => openExternalLink(CONST.DEEP_DIVE_ERECEIPTS)}
>
{translate('workspace.rules.individualExpenseRules.eReceiptsHintLink')}
</TextLink>
Expand Down