Skip to content
Draft
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
10 changes: 8 additions & 2 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
import type {PersonalDetailsList, Report} from '@src/types/onyx';
import {getButtonRole} from './Button/utils';
import DisplayNames from './DisplayNames';
import type DisplayNamesProps from './DisplayNames/types';
Expand Down Expand Up @@ -81,6 +81,9 @@ type AvatarWithDisplayNameProps = {

/** The style of the parent navigation status container */
parentNavigationStatusContainerStyles?: StyleProp<ViewStyle>;

/** Optional personal details list override */
personalDetailsList?: PersonalDetailsList;
};

function getCustomDisplayName(
Expand Down Expand Up @@ -173,10 +176,12 @@ function AvatarWithDisplayName({
customDisplayNameStyle = {},
parentNavigationSubtitleTextStyles,
parentNavigationStatusContainerStyles = {},
personalDetailsList,
}: AvatarWithDisplayNameProps) {
const {localeCompare, formatPhoneNumber} = useLocalize();
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`, {canEvict: false, canBeMissing: !report?.parentReportID});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}) ?? CONST.EMPTY_OBJECT;
const [personalDetailsOnyx] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}) ?? CONST.EMPTY_OBJECT;
const personalDetails = personalDetailsList ?? personalDetailsOnyx ?? CONST.EMPTY_OBJECT;
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -255,6 +260,7 @@ function AvatarWithDisplayName({
size={size}
secondaryAvatarContainerStyle={StyleUtils.getBackgroundAndBorderStyle(avatarBorderColor)}
reportID={report?.reportID}
personalDetailsList={personalDetails}
/>
);

Expand Down
7 changes: 6 additions & 1 deletion src/components/ReportActionAvatars/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {ValueOf} from 'type-fest';
import useOnyx from '@hooks/useOnyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CompanyCardFeed, InvitedEmailsToAccountIDs, Policy, Report, ReportAction} from '@src/types/onyx';
import type {CompanyCardFeed, InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx';
import type {HorizontalStacking} from './ReportActionAvatar';
import ReportActionAvatar from './ReportActionAvatar';
import useReportActionAvatars from './useReportActionAvatars';
Expand Down Expand Up @@ -72,6 +72,9 @@ type ReportActionAvatarsProps = {

/** chatReportID needed for the avatars logic. When provided, this will be used as a fallback if the snapshot is undefined */
chatReportID?: string;

/** Optional personal details map to use instead of the global Onyx personal details */
personalDetailsList?: PersonalDetailsList;
};

/**
Expand Down Expand Up @@ -105,6 +108,7 @@ function ReportActionAvatars({
invitedEmailsToAccountIDs,
shouldUseCustomFallbackAvatar = false,
chatReportID,
personalDetailsList,
}: ReportActionAvatarsProps) {
const accountIDs = passedAccountIDs.filter((accountID) => accountID !== CONST.DEFAULT_NUMBER_ID);

Expand Down Expand Up @@ -140,6 +144,7 @@ function ReportActionAvatars({
invitedEmailsToAccountIDs,
shouldUseCustomFallbackAvatar,
chatReportID,
personalDetailsList,
});

let avatarType: ValueOf<typeof CONST.REPORT_ACTION_AVATARS.TYPE> = notPreciseAvatarType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import {FallbackAvatar} from '@components/Icon/Expensicons';

Check warning on line 3 in src/components/ReportActionAvatars/useReportActionAvatars.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 3 in src/components/ReportActionAvatars/useReportActionAvatars.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -24,7 +24,7 @@
import {getDefaultAvatar} from '@libs/UserAvatarUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {InvitedEmailsToAccountIDs, OnyxInputOrEntry, Policy, Report, ReportAction} from '@src/types/onyx';
import type {InvitedEmailsToAccountIDs, OnyxInputOrEntry, PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx';
import type {Icon as IconType} from '@src/types/onyx/OnyxCommon';
import useReportPreviewSenderID from './useReportPreviewSenderID';

Expand All @@ -40,6 +40,7 @@
invitedEmailsToAccountIDs,
shouldUseCustomFallbackAvatar = false,
chatReportID: passedChatReportID,
personalDetailsList,
}: {
report: OnyxEntry<Report>;
action: OnyxEntry<ReportAction>;
Expand All @@ -52,16 +53,17 @@
invitedEmailsToAccountIDs?: InvitedEmailsToAccountIDs;
shouldUseCustomFallbackAvatar?: boolean;
chatReportID?: string;
personalDetailsList?: PersonalDetailsList;
}) {
/* Get avatar type */
const allPersonalDetails = usePersonalDetails();
const {formatPhoneNumber} = useLocalize();
const [personalDetailsFromSnapshot] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
const [personalDetailsFromOnyx] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
canBeMissing: true,
});
// When the search hash changes, personalDetails from the snapshot will be undefined if it hasn't been fetched yet.
// Therefore, we will fall back to allPersonalDetails while the data is being fetched.
const personalDetails = personalDetailsFromSnapshot ?? allPersonalDetails;
const personalDetails = personalDetailsList ?? personalDetailsFromOnyx ?? allPersonalDetails;

const isReportAChatReport = report?.type === CONST.REPORT.TYPE.CHAT && report?.chatType !== CONST.REPORT.CHAT_TYPE.TRIP_ROOM;

Expand Down
17 changes: 15 additions & 2 deletions src/components/ReportSearchHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import type ReportSearchHeaderProps from './types';

function ReportSearchHeader({report, style, transactions, avatarBorderColor}: ReportSearchHeaderProps) {
function ReportSearchHeader({report, style, transactions, avatarBorderColor, personalDetailsList}: ReportSearchHeaderProps) {
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();

Expand All @@ -19,12 +19,25 @@ function ReportSearchHeader({report, style, transactions, avatarBorderColor}: Re
shouldEnableDetailPageNavigation={false}
shouldEnableAvatarNavigation={false}
avatarBorderColor={avatarBorderColor}
personalDetailsList={personalDetailsList}
customDisplayNameStyle={styles.fontWeightNormal}
parentNavigationSubtitleTextStyles={[styles.textLineHeightNormal, styles.minHeight4, styles.mt1, !isLargeScreenWidth && styles.textMicro]}
parentNavigationStatusContainerStyles={isLargeScreenWidth ? styles.mt1 : styles.mt0Half}
/>
);
}, [report, transactions, avatarBorderColor, styles.fontWeightNormal, styles.textLineHeightNormal, styles.minHeight4, styles.mt1, isLargeScreenWidth, styles.textMicro, styles.mt0Half]);
}, [
report,
transactions,
avatarBorderColor,
personalDetailsList,
styles.fontWeightNormal,
styles.textLineHeightNormal,
styles.minHeight4,
styles.mt1,
isLargeScreenWidth,
styles.textMicro,
styles.mt0Half,
]);

return (
<View
Expand Down
5 changes: 4 additions & 1 deletion src/components/ReportSearchHeader/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {ColorValue, StyleProp, ViewStyle} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {TransactionListItemType} from '@components/SelectionListWithSections/types';
import type {Report} from '@src/types/onyx';
import type {PersonalDetailsList, Report} from '@src/types/onyx';

type ReportSearchHeaderProps = {
/** Report, if we're showing the details for one and using AvatarWithDisplay */
Expand All @@ -15,6 +15,9 @@ type ReportSearchHeaderProps = {

/** Color of the secondary avatar border, usually should match the container background */
avatarBorderColor?: ColorValue;

/** Optional personal details list to use instead of the global collection */
personalDetailsList?: PersonalDetailsList;
};

export default ReportSearchHeaderProps;
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
const expensifyIcons = useMemoizedLazyExpensifyIcons(['DotIndicator']);

const snapshotData = snapshot?.data;
const personalDetailsList = snapshotData?.personalDetailsList;

const snapshotReport = useMemo(() => {
return (snapshotData?.[`${ONYXKEYS.COLLECTION.REPORT}${reportItem.reportID}`] ?? {}) as Report;
Expand Down Expand Up @@ -191,6 +192,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
isDisabledCheckbox={isDisabledCheckbox}
isHovered={hovered}
isFocused={isFocused}
personalDetailsList={personalDetailsList}
/>
{getDescription}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import getBase62ReportID from '@libs/getBase62ReportID';
import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {Policy} from '@src/types/onyx';
import type {PersonalDetailsList, Policy} from '@src/types/onyx';
import ActionCell from './ActionCell';
import DateCell from './DateCell';
import ExportedIconCell from './ExportedIconCell';
Expand All @@ -43,6 +43,7 @@ type ExpenseReportListItemRowProps = {
isHovered?: boolean;
isFocused?: boolean;
columns?: SearchColumnType[];
personalDetailsList?: PersonalDetailsList;
};

function ExpenseReportListItemRow({
Expand All @@ -61,6 +62,7 @@ function ExpenseReportListItemRow({
columns = [],
isHovered = false,
isFocused = false,
personalDetailsList,
}: ExpenseReportListItemRowProps) {
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
Expand Down Expand Up @@ -250,6 +252,7 @@ function ExpenseReportListItemRow({
style={[{maxWidth: variables.reportSearchHeaderMaxWidth}]}
transactions={item.transactions}
avatarBorderColor={finalAvatarBorderColor}
personalDetailsList={personalDetailsList}
/>
</View>
</View>
Expand Down Expand Up @@ -286,6 +289,7 @@ function ExpenseReportListItemRow({
policy={policy}
shouldShowTooltip={showTooltip}
subscriptAvatarBorderColor={finalAvatarBorderColor}
personalDetailsList={personalDetailsList}
/>
</View>

Expand Down
Loading