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
1 change: 1 addition & 0 deletions src/hooks/useExpensifyCardRulesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function useExpensifyCardRules(policyID: string) {
actionLabel,
cardSummary,
summaryParts,
formValues,
accessibilityLabel,
created: cardRule.created,
currencyCode: selectedCurrency,
Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Vorheriges Jahr',
nextYear: 'Nächstes Jahr',
avatar: 'Avatar',
restrictions: 'Beschränkungen',
},
socials: {
podcast: 'Folgen Sie uns auf Podcast',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ const translations = {
week: 'Week',
year: 'Year',
quarter: 'Quarter',
restrictions: 'Restrictions',
concierge: {
sidePanelGreeting: 'Hi there, how can I help?',
showHistory: 'Show history',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ const translations: TranslationDeepObject<typeof en> = {
expensifyLogo: 'Logo de Expensify',
approver: 'Aprobador',
enterDigitLabel: ({digitIndex, totalDigits}: {digitIndex: number; totalDigits: number}) => `introducir dígito ${digitIndex} de ${totalDigits}`,
restrictions: 'Restricciones',
},
socials: {
podcast: 'Síguenos en Podcast',
Expand Down
5 changes: 3 additions & 2 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Année précédente',
nextYear: 'L’an prochain',
avatar: 'Avatar',
restrictions: 'Restrictions',
},
socials: {
podcast: 'Suivez-nous sur Podcast',
Expand Down Expand Up @@ -2814,9 +2815,9 @@ ${amount} pour ${merchant} - ${date}`,
title: 'Modifier l’agent',
agentName: 'Nom de l’agent',
instructions: 'Écrire des instructions personnalisées',
chatWithAgent: 'Discuter avec l\u2019agent',
chatWithAgent: 'Discuter avec l’agent',
copilotIntoAccount: 'Copilote dans le compte',
deleteAgent: 'Supprimer l\u2019agent',
deleteAgent: 'Supprimer l’agent',
Comment thread
JS00001 marked this conversation as resolved.
Resolved
deleteAgentTitle: 'Supprimer l’agent ?',
deleteAgentMessage: 'Voulez-vous vraiment supprimer cet agent ? Cette action est irréversible.',
},
Expand Down
5 changes: 3 additions & 2 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Anno precedente',
nextYear: "L'anno prossimo",
avatar: 'Avatar',
restrictions: 'Restrizioni',
},
socials: {
podcast: 'Seguici su Podcast',
Expand Down Expand Up @@ -2802,8 +2803,8 @@ ${amount} per ${merchant} - ${date}`,
title: 'Modifica agente',
agentName: 'Nome agente',
instructions: 'Scrivi istruzioni personalizzate',
chatWithAgent: 'Chatta con l\u2019agente',
copilotIntoAccount: 'Copilot nell\u2019account',
chatWithAgent: 'Chatta con l’agente',
copilotIntoAccount: 'Copilot nell’account',
deleteAgent: 'Elimina agente',
deleteAgentTitle: 'Eliminare agente?',
deleteAgentMessage: 'Sei sicuro di voler eliminare questo agente? Questa azione non può essere annullata.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: '前年',
nextYear: '来年',
avatar: 'アバター',
restrictions: '制限',
},
socials: {
podcast: 'ポッドキャストでフォロー',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Vorig jaar',
nextYear: 'Volgend jaar',
avatar: 'Avatar',
restrictions: 'Beperkingen',
},
socials: {
podcast: 'Volg ons op Podcast',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Poprzedni rok',
nextYear: 'W przyszłym roku',
avatar: 'Avatar',
restrictions: 'Ograniczenia',
},
socials: {
podcast: 'Śledź nas na Podcast',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: 'Ano anterior',
nextYear: 'Ano que vem',
avatar: 'Avatar',
restrictions: 'Restrições',
},
socials: {
podcast: 'Siga-nos no Podcast',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ const translations: TranslationDeepObject<typeof en> = {
previousYear: '上一年',
nextYear: '明年',
avatar: '头像',
restrictions: '限制',
},
socials: {
podcast: '在播客上关注我们',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {usePersonalDetails} from '@components/OnyxListItemProvider';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useDefaultFundID from '@hooks/useDefaultFundID';
import useExpensifyCardRules from '@hooks/useExpensifyCardRulesList';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -28,7 +29,7 @@ import type {IssueNewCardStep} from '@src/types/onyx/Card';

type ConfirmationStepProps = {
/** ID of the policy that the card will be issued under */
policyID: string | undefined;
policyID: string;

/** Array of step names */
stepNames: readonly string[];
Expand All @@ -46,9 +47,12 @@ function ConfirmationStep({policyID, stepNames, startStepIndex}: ConfirmationSte
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const defaultFundID = useDefaultFundID(policyID);
const {isBetaEnabled} = usePermissions();
const {cardRules} = useExpensifyCardRules(policyID);

const data = issueNewCard?.data;
const isSuccessful = issueNewCard?.isSuccessful;
const hasApprovalError = !!policy?.errorFields?.approvalMode;
const isSpendRuleApplied = !!issueNewCard?.data.spendRuleEnabled;
const isAddApprovalEnabled = policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && !hasApprovalError;
const shouldDisableSubmitButton = !isAddApprovalEnabled && data?.limitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART;
const personalDetails = usePersonalDetails();
Expand Down Expand Up @@ -123,6 +127,33 @@ function ConfirmationStep({policyID, stepNames, startStepIndex}: ConfirmationSte

const shouldShowExpirationDate = !isPhysicalCard;

const cardRuleRestrictionsTitle = (() => {
if (!data?.spendRuleEnabled) {
return '';
}

const fields: string[] = [];
const spendRuleOption = data?.spendRuleOption ?? CONST.EXPENSIFY_CARD.SPEND_RULE_OPTION.COPY_EXISTING;
const isCopyingExistingRule = spendRuleOption === CONST.EXPENSIFY_CARD.SPEND_RULE_OPTION.COPY_EXISTING;
const spendRuleForm = isCopyingExistingRule ? cardRules.find((rule) => rule.ruleID === data.spendRuleID)?.formValues : data?.spendRuleValue;

if (spendRuleForm?.categories?.length) {
fields.push(translate('workspace.rules.spendRules.categories'));
}

if (spendRuleForm?.maxAmount) {
const translation = !fields.length ? translate('workspace.rules.spendRules.maxAmount') : translate('workspace.rules.spendRules.maxAmount').toLowerCase();
fields.push(translation);
}

if (spendRuleForm?.merchantNames?.length) {
const translation = !fields.length ? translate('workspace.rules.spendRules.merchants') : translate('workspace.rules.spendRules.merchants').toLowerCase();
fields.push(translation);
}

return fields.join(', ');
})();

return (
<InteractiveStepWrapper
wrapperID="ConfirmationStep"
Expand Down Expand Up @@ -175,6 +206,14 @@ function ConfirmationStep({policyID, stepNames, startStepIndex}: ConfirmationSte
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.SPEND_RULES)}
/>
)}
{isSpendRuleApplied && (
<MenuItemWithTopDescription
description={translate('common.restrictions')}
title={cardRuleRestrictionsTitle}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.SPEND_RULES)}
/>
)}
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.cardName')}
title={data?.cardTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ function SetSpendRulesStep({policyID, stepNames, startStepIndex}: SetSpendRulesS
shouldHideFixErrorsAlert
validate={validate}
>
<Text style={[styles.textHeadlineLineHeightXXL, styles.mv3]}>{translate('workspace.card.issueNewCard.setCardRules')}</Text>
{isSpendRuleVisible && (
<>
<Text style={[styles.textHeadlineLineHeightXXL, styles.mv3]}>{translate('workspace.card.issueNewCard.setCardRules')}</Text>
<ToggleSettingOptionRow
title={translate('workspace.card.issueNewCard.addSpendRule')}
isActive={spendRuleEnabled}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import ActivityIndicator from '@components/ActivityIndicator';
import GenericEmptyStateComponent from '@components/EmptyStateComponent/GenericEmptyStateComponent';
Expand All @@ -18,15 +18,17 @@ import useSearchResults from '@hooks/useSearchResults';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {setIssueNewCardData} from '@libs/actions/Card';
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import tokenizedSearch from '@libs/tokenizedSearch';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type SpendRuleSelectionPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DYNAMIC_WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW_SPEND_RULE_SELECTION>;

Expand All @@ -38,12 +40,22 @@ function SpendRuleSelectionPage({route}: SpendRuleSelectionPageProps) {
const {translate} = useLocalize();
const illustrations = useMemoizedLazyIllustrations(['EmptyShelves']);
const {cardRules, isLoadingCardRules} = useExpensifyCardRules(policyID);
const [issueCardForm] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`);
const [issueCardForm, issueCardFormMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`);

const [shouldShowError, setShouldShowError] = useState(false);
const [cardRuleID, setCardRuleID] = useState(issueCardForm?.data?.spendRuleID);

const isLoadingIssueCardForm = isLoadingOnyxValue(issueCardFormMetadata);
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW_SPEND_RULE_SELECTION.path);

useEffect(() => {
if (issueCardForm?.data || isLoadingIssueCardForm) {
return;
}

Navigation.goBack(createDynamicRoute(DYNAMIC_ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.path, ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID)));
}, [isLoadingIssueCardForm, issueCardForm?.data, policyID]);

// We only allow cards that share the same currency to be on a spend rule
const availableCardRules = cardRules.filter((cardRule) => cardRule.currencyCode === issueCardForm?.data?.currency);
const cardRuleListItems: SpendRuleListItemType[] = availableCardRules.map((cardRule) => ({
Expand Down
Loading