Skip to content

Commit

Permalink
Merge pull request #50039 from truph01/fix/49804
Browse files Browse the repository at this point in the history
fix: Expensify card link navigates to wallet
  • Loading branch information
iwiznia authored Oct 7, 2024
2 parents 2859dc2 + 015e07d commit 1fb0d01
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,18 @@ const ROUTES = {
route: 'settings/wallet/card/:cardID?',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}` as const,
},
SETTINGS_DOMAINCARD_DETAIL: {
route: 'settings/card/:cardID?',
getRoute: (cardID: string) => `settings/card/${cardID}` as const,
},
SETTINGS_REPORT_FRAUD: {
route: 'settings/wallet/card/:cardID/report-virtual-fraud',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}/report-virtual-fraud` as const,
},
SETTINGS_DOMAINCARD_REPORT_FRAUD: {
route: 'settings/card/:cardID/report-virtual-fraud',
getRoute: (cardID: string) => `settings/card/${cardID}/report-virtual-fraud` as const,
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME: {
route: 'settings/wallet/card/:domain/get-physical/name',
getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/name` as const,
Expand Down Expand Up @@ -1015,18 +1023,34 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/expensify-card/:cardID',
getRoute: (policyID: string, cardID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/expensify-card/${cardID}`, backTo),
},
EXPENSIFY_CARD_DETAILS: {
route: 'settings/:policyID/expensify-card/:cardID',
getRoute: (policyID: string, cardID: string, backTo?: string) => getUrlWithBackToParam(`settings/${policyID}/expensify-card/${cardID}`, backTo),
},
WORKSPACE_EXPENSIFY_CARD_NAME: {
route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/name',
getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/name` as const,
},
EXPENSIFY_CARD_NAME: {
route: 'settings/:policyID/expensify-card/:cardID/edit/name',
getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/name` as const,
},
WORKSPACE_EXPENSIFY_CARD_LIMIT: {
route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/limit',
getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/limit` as const,
},
EXPENSIFY_CARD_LIMIT: {
route: 'settings/:policyID/expensify-card/:cardID/edit/limit',
getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/limit` as const,
},
WORKSPACE_EXPENSIFY_CARD_LIMIT_TYPE: {
route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/limit-type',
getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/limit-type` as const,
},
EXPENSIFY_CARD_LIMIT_TYPE: {
route: 'settings/:policyID/expensify-card/:cardID/edit/limit-type',
getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/limit-type` as const,
},
WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW: {
route: 'settings/workspaces/:policyID/expensify-card/issue-new',
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/expensify-card/issue-new`, backTo),
Expand Down
12 changes: 12 additions & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const SCREENS = {
SEARCH_ADVANCED_FILTERS: 'SearchAdvancedFilters',
SEARCH_SAVED_SEARCH: 'SearchSavedSearch',
SETTINGS_CATEGORIES: 'SettingsCategories',
EXPENSIFY_CARD: 'ExpensifyCard',
DOMAIN_CARD: 'DomainCard',
RESTRICTED_ACTION: 'RestrictedAction',
REPORT_EXPORT: 'Report_Export',
MISSING_PERSONAL_DETAILS: 'MissingPersonalDetails',
Expand Down Expand Up @@ -244,6 +246,16 @@ const SCREENS = {
SETTINGS_CATEGORY_EDIT: 'Settings_Category_Edit',
SETTINGS_CATEGORIES_ROOT: 'Settings_Categories',
},
EXPENSIFY_CARD: {
EXPENSIFY_CARD_DETAILS: 'Expensify_Card_Details',
EXPENSIFY_CARD_NAME: 'Expensify_Card_Name',
EXPENSIFY_CARD_LIMIT: 'Expensify_Card_Limit',
EXPENSIFY_CARD_LIMIT_TYPE: 'Expensify_Card_Limit_Type',
},
DOMAIN_CARD: {
DOMAIN_CARD_DETAIL: 'Domain_Card_Detail',
DOMAIN_CARD_REPORT_FRAUD: 'Domain_Card_Report_Fraud',
},

SETTINGS_TAGS_ROOT: 'Settings_Tags',

Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/IssueCardMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';

type IssueCardMessageProps = {
action: OnyxEntry<ReportAction>;
policyID: string | undefined;
};

function IssueCardMessage({action}: IssueCardMessageProps) {
function IssueCardMessage({action, policyID}: IssueCardMessageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);
Expand All @@ -40,7 +41,7 @@ function IssueCardMessage({action}: IssueCardMessageProps) {

return (
<>
<RenderHTML html={`<muted-text>${ReportActionsUtils.getCardIssuedMessage(action, true)}</muted-text>`} />
<RenderHTML html={`<muted-text>${ReportActionsUtils.getCardIssuedMessage(action, true, policyID)}</muted-text>`} />
{shouldShowAddMissingDetailsButton && (
<Button
onPress={() => Navigation.navigate(ROUTES.MISSING_PERSONAL_DETAILS)}
Expand Down
14 changes: 14 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ const CategoriesModalStackNavigator = createModalStackNavigator({
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/CategorySettingsPage').default,
});

const ExpensifyCardModalStackNavigator = createModalStackNavigator({
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_DETAILS]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage').default,
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_NAME]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceEditCardNamePage').default,
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceEditCardLimitPage').default,
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT_TYPE]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceEditCardLimitTypePage').default,
});

const DomainCardModalStackNavigator = createModalStackNavigator({
[SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage').default,
[SCREENS.DOMAIN_CARD.DOMAIN_CARD_REPORT_FRAUD]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ReportVirtualCardFraudPage').default,
});

const ReportParticipantsModalStackNavigator = createModalStackNavigator<ParticipantsNavigatorParamList>({
[SCREENS.REPORT_PARTICIPANTS.ROOT]: () => require<ReactComponentModule>('../../../../pages/ReportParticipantsPage').default,
[SCREENS.REPORT_PARTICIPANTS.INVITE]: () => require<ReactComponentModule>('../../../../pages/InviteReportParticipantsPage').default,
Expand Down Expand Up @@ -612,6 +624,8 @@ export {
SettingsModalStackNavigator,
SignInModalStackNavigator,
CategoriesModalStackNavigator,
ExpensifyCardModalStackNavigator,
DomainCardModalStackNavigator,
SplitDetailsModalStackNavigator,
TaskModalStackNavigator,
WalletStatementStackNavigator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ function RightModalNavigator({navigation, route}: RightModalNavigatorProps) {
name={SCREENS.RIGHT_MODAL.SETTINGS_CATEGORIES}
component={ModalStackNavigators.CategoriesModalStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.EXPENSIFY_CARD}
component={ModalStackNavigators.ExpensifyCardModalStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.DOMAIN_CARD}
component={ModalStackNavigators.DomainCardModalStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.PARTICIPANTS}
component={ModalStackNavigators.ReportParticipantsModalStackNavigator}
Expand Down
26 changes: 26 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,32 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
},
},
},
[SCREENS.RIGHT_MODAL.EXPENSIFY_CARD]: {
screens: {
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_DETAILS]: {
path: ROUTES.EXPENSIFY_CARD_DETAILS.route,
},
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_NAME]: {
path: ROUTES.EXPENSIFY_CARD_NAME.route,
},
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT]: {
path: ROUTES.EXPENSIFY_CARD_LIMIT.route,
},
[SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT_TYPE]: {
path: ROUTES.EXPENSIFY_CARD_LIMIT_TYPE.route,
},
},
},
[SCREENS.RIGHT_MODAL.DOMAIN_CARD]: {
screens: {
[SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL]: {
path: ROUTES.SETTINGS_DOMAINCARD_DETAIL.route,
},
[SCREENS.DOMAIN_CARD.DOMAIN_CARD_REPORT_FRAUD]: {
path: ROUTES.SETTINGS_DOMAINCARD_REPORT_FRAUD.route,
},
},
},
[SCREENS.RIGHT_MODAL.REPORT_DESCRIPTION]: {
screens: {
[SCREENS.REPORT_DESCRIPTION_ROOT]: ROUTES.REPORT_DESCRIPTION.route,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@ type RightModalNavigatorParamList = {
[SCREENS.RIGHT_MODAL.REPORT_DETAILS]: NavigatorScreenParams<ReportDetailsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REPORT_SETTINGS]: NavigatorScreenParams<ReportSettingsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.SETTINGS_CATEGORIES]: NavigatorScreenParams<SettingsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.EXPENSIFY_CARD]: NavigatorScreenParams<SettingsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.DOMAIN_CARD]: NavigatorScreenParams<SettingsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REPORT_DESCRIPTION]: NavigatorScreenParams<ReportDescriptionNavigatorParamList>;
[SCREENS.RIGHT_MODAL.PARTICIPANTS]: NavigatorScreenParams<ParticipantsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.ROOM_MEMBERS]: NavigatorScreenParams<RoomMembersNavigatorParamList>;
Expand Down
22 changes: 17 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {OnyxInputOrEntry, PrivatePersonalDetails} from '@src/types/onyx';
import type {IssueNewCardOriginalMessage, JoinWorkspaceResolution, OriginalMessageChangeLog, OriginalMessageExportIntegration} from '@src/types/onyx/OriginalMessage';
import type {JoinWorkspaceResolution, OriginalMessageChangeLog, OriginalMessageExportIntegration} from '@src/types/onyx/OriginalMessage';
import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {Message, OldDotReportAction, OriginalMessage, ReportActions} from '@src/types/onyx/ReportAction';
Expand All @@ -25,6 +25,7 @@ import Log from './Log';
import type {MessageElementBase, MessageTextElement} from './MessageElement';
import Parser from './Parser';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import * as PolicyUtils from './PolicyUtils';
import * as ReportConnection from './ReportConnection';
import type {OptimisticIOUReportAction, PartialReportAction} from './ReportUtils';
import StringUtils from './StringUtils';
Expand Down Expand Up @@ -1733,13 +1734,24 @@ function isCardIssuedAction(reportAction: OnyxEntry<ReportAction>) {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS);
}

function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRenderHTML = false) {
const assigneeAccountID = (getOriginalMessage(reportAction) as IssueNewCardOriginalMessage)?.assigneeAccountID;
function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRenderHTML = false, policyID = '-1') {
const cardIssuedActionOriginalMessage = isActionOfType(
reportAction,
CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED,
CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL,
CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
)
? getOriginalMessage(reportAction)
: undefined;

const assigneeAccountID = cardIssuedActionOriginalMessage?.assigneeAccountID ?? -1;
const cardID = cardIssuedActionOriginalMessage?.cardID ?? -1;
const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1).at(0);

const isPolicyAdmin = PolicyUtils.isPolicyAdmin(PolicyUtils.getPolicy(policyID));
const assignee = shouldRenderHTML ? `<mention-user accountID="${assigneeAccountID}"/>` : assigneeDetails?.firstName ?? assigneeDetails?.login ?? '';
const navigateRoute = isPolicyAdmin ? ROUTES.EXPENSIFY_CARD_DETAILS.getRoute(policyID, String(cardID)) : ROUTES.SETTINGS_DOMAINCARD_DETAIL.getRoute(String(cardID));
const link = shouldRenderHTML
? `<a href='${environmentURL}/${ROUTES.SETTINGS_WALLET}'>${Localize.translateLocal('cardPage.expensifyCard')}</a>`
? `<a href='${environmentURL}/${navigateRoute}'>${Localize.translateLocal('cardPage.expensifyCard')}</a>`
: Localize.translateLocal('cardPage.expensifyCard');

const missingDetails =
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ const ContextMenuActions: ContextMenuAction[] = [
const {label, errorMessage} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {label: '', errorMessage: ''};
setClipboardMessage(Localize.translateLocal('report.actions.type.integrationSyncFailed', {label, errorMessage}));
} else if (ReportActionsUtils.isCardIssuedAction(reportAction)) {
setClipboardMessage(ReportActionsUtils.getCardIssuedMessage(reportAction, true));
const report = ReportUtils.getReport(reportID);
setClipboardMessage(ReportActionsUtils.getCardIssuedMessage(reportAction, true, report?.policyID));
} else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_INTEGRATION)) {
setClipboardMessage(ReportActionsUtils.getRemovedConnectionMessage(reportAction));
} else if (content) {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,12 @@ function ReportActionItem({
} else if (
ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS)
) {
children = <IssueCardMessage action={action} />;
children = (
<IssueCardMessage
action={action}
policyID={report?.policyID}
/>
);
} else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION)) {
children = <ExportIntegration action={action} />;
} else if (ReportActionsUtils.isRenamedAction(action)) {
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ type OriginalMessageIntegrationSyncFailed = {
type OriginalMessageExpensifyCard = {
/** The id of the user the card was assigned to */
assigneeAccountID: number;

/** The id of the card */
cardID: number;
};

/**
Expand Down

0 comments on commit 1fb0d01

Please sign in to comment.