Skip to content

Commit ad3b837

Browse files
authored
Merge pull request #81223 from ishpaul777/migrate-nextstep-updates-to-auth
Add messageKey handling as fallback
2 parents 9a29054 + 44777d4 commit ad3b837

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

src/components/MoneyReportHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ function MoneyReportHeader({
17461746
betas,
17471747
});
17481748

1749-
const showNextStepBar = shouldShowNextStep && !!optimisticNextStep?.message?.length;
1749+
const showNextStepBar = shouldShowNextStep && !!(optimisticNextStep?.message?.length ?? (optimisticNextStep && 'messageKey' in optimisticNextStep));
17501750
const showNextStepSkeleton = shouldShowNextStep && !optimisticNextStep && !!isLoadingInitialReportActions && !isOffline;
17511751
const shouldShowMoreContent = showNextStepBar || showNextStepSkeleton || !!statusBarProps || isReportInSearch;
17521752

src/components/MoneyReportHeaderStatusBar.tsx

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,41 @@ import {View} from 'react-native';
33
import type {ValueOf} from 'type-fest';
44
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
55
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
6+
import useLocalize from '@hooks/useLocalize';
67
import useTheme from '@hooks/useTheme';
78
import useThemeStyles from '@hooks/useThemeStyles';
8-
import {parseMessage} from '@libs/NextStepUtils';
9+
import {buildNextStepMessage, parseMessage} from '@libs/NextStepUtils';
910
import variables from '@styles/variables';
1011
import CONST from '@src/CONST';
12+
import type {ReportNextStep} from '@src/types/onyx/Report';
1113
import type ReportNextStepDeprecated from '@src/types/onyx/ReportNextStepDeprecated';
1214
import type IconAsset from '@src/types/utils/IconAsset';
1315
import Icon from './Icon';
1416
import RenderHTML from './RenderHTML';
1517

18+
/** Combined type that accepts either the new format or the deprecated format */
19+
type NextStepData = ReportNextStep | ReportNextStepDeprecated;
20+
1621
type MoneyReportHeaderStatusBarProps = {
17-
/** The next step for the report (deprecated old format) */
18-
nextStep: ReportNextStepDeprecated | undefined;
22+
/** The next step for the report (supports both new and deprecated formats) */
23+
nextStep: NextStepData | undefined;
1924
};
2025

2126
type IconName = ValueOf<typeof CONST.NEXT_STEP.ICONS>;
2227
type IconMap = Record<IconName, IconAsset>;
2328

29+
/**
30+
* Type guard to check if the next step is in the deprecated format (has message array)
31+
* We prioritize the old format first for backwards compatibility during migration.
32+
*/
33+
function isDeprecatedFormatNextStep(step: NextStepData): step is ReportNextStepDeprecated {
34+
return 'message' in step && Array.isArray(step.message) && step.message.length > 0;
35+
}
36+
2437
function MoneyReportHeaderStatusBar({nextStep}: MoneyReportHeaderStatusBarProps) {
2538
const styles = useThemeStyles();
2639
const theme = useTheme();
40+
const {translate} = useLocalize();
2741
const icons = useMemoizedLazyExpensifyIcons(['Hourglass', 'Checkmark', 'Stopwatch', 'DotIndicator']);
2842
const iconMap: IconMap = useMemo(
2943
() => ({
@@ -35,11 +49,28 @@ function MoneyReportHeaderStatusBar({nextStep}: MoneyReportHeaderStatusBarProps)
3549
[icons],
3650
);
3751
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
52+
const currentUserAccountID = currentUserPersonalDetails.accountID;
3853
const currentUserEmail = currentUserPersonalDetails.login ?? '';
54+
3955
const messageContent = useMemo(() => {
40-
const messageArray = nextStep?.message;
41-
return parseMessage(messageArray, currentUserEmail);
42-
}, [nextStep?.message, currentUserEmail]);
56+
if (!nextStep) {
57+
return '';
58+
}
59+
60+
// Handle old/deprecated format first (with message array) for backwards compatibility
61+
if (isDeprecatedFormatNextStep(nextStep)) {
62+
return parseMessage(nextStep.message, currentUserEmail);
63+
}
64+
65+
// Fall back to new format (with messageKey)
66+
if ('messageKey' in nextStep && nextStep.messageKey) {
67+
return buildNextStepMessage(nextStep, translate, currentUserAccountID);
68+
}
69+
70+
return '';
71+
}, [nextStep, translate, currentUserAccountID, currentUserEmail]);
72+
73+
const iconFill = nextStep?.iconFill ?? theme.icon;
4374

4475
return (
4576
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.overflowHidden, styles.w100, styles.headerStatusBarContainer]}>
@@ -48,7 +79,7 @@ function MoneyReportHeaderStatusBar({nextStep}: MoneyReportHeaderStatusBarProps)
4879
src={(nextStep?.icon && iconMap?.[nextStep.icon]) ?? icons.Hourglass}
4980
height={variables.iconSizeSmall}
5081
width={variables.iconSizeSmall}
51-
fill={nextStep?.iconFill ?? theme.icon}
82+
fill={iconFill}
5283
/>
5384
</View>
5485
<View style={[styles.dFlex, styles.flexRow, styles.flexShrink1]}>

src/libs/DebugUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePa
544544
icon: 'string',
545545
actorAccountID: 'number',
546546
eta: 'object',
547+
iconFill: 'string',
547548
});
548549
case 'tripData':
549550
return validateObject<ObjectElement<Report, 'tripData'>>(value, {

src/types/onyx/Report.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type ReportNextStep = {
7878
/** The ETA date time */
7979
dateTime?: string;
8080
};
81+
82+
/** The fill color of the icon */
83+
iconFill?: string;
8184
};
8285

8386
/** Model of report data */

0 commit comments

Comments
 (0)