Skip to content

Commit

Permalink
Merge pull request Expensify#53240 from Kalydosos/fix-53003-on-room-i…
Browse files Browse the repository at this point in the history
…nvite-sms-shown

Fix 53003 on room invite sms shown
  • Loading branch information
luacmartins authored Dec 12, 2024
2 parents 9cdd9d7 + d8cf634 commit ff419fe
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 90 deletions.
30 changes: 7 additions & 23 deletions src/components/ArchivedReportFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import lodashEscape from 'lodash/escape';
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {getCurrentUserAccountID} from '@libs/actions/Report';
Expand All @@ -10,26 +9,20 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Report, ReportAction} from '@src/types/onyx';
import type {Report} from '@src/types/onyx';
import Banner from './Banner';

type ArchivedReportFooterOnyxProps = {
/** The reason this report was archived */
reportClosedAction: OnyxEntry<ReportAction>;

/** Personal details of all users */
personalDetails: OnyxEntry<PersonalDetailsList>;
};

type ArchivedReportFooterProps = ArchivedReportFooterOnyxProps & {
type ArchivedReportFooterProps = {
/** The archived report */
report: Report;
};

function ArchivedReportFooter({report, reportClosedAction, personalDetails = {}}: ArchivedReportFooterProps) {
function ArchivedReportFooter({report}: ArchivedReportFooterProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {initialValue: {}});
const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, selector: ReportActionsUtils.getLastClosedReportAction});
const originalMessage = ReportActionsUtils.isClosedAction(reportClosedAction) ? ReportActionsUtils.getOriginalMessage(reportClosedAction) : null;
const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT;
const actorPersonalDetails = personalDetails?.[reportClosedAction?.actorAccountID ?? -1];
Expand Down Expand Up @@ -78,13 +71,4 @@ function ArchivedReportFooter({report, reportClosedAction, personalDetails = {}}

ArchivedReportFooter.displayName = 'ArchivedReportFooter';

export default withOnyx<ArchivedReportFooterProps, ArchivedReportFooterOnyxProps>({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
reportClosedAction: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
canEvict: false,
selector: ReportActionsUtils.getLastClosedReportAction,
},
})(ArchivedReportFooter);
export default ArchivedReportFooter;
12 changes: 6 additions & 6 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function getParticipantsOption(participant: ReportUtils.OptionData | Participant
const detail = getPersonalDetailsForAccountIDs([participant.accountID ?? -1], personalDetails)[participant.accountID ?? -1];
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const login = detail?.login || participant.login || '';
const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(detail, LocalePhoneNumber.formatPhoneNumber(login) || participant.text);
const displayName = LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(detail, login || participant.text));

return {
keyForList: String(detail?.accountID),
Expand Down Expand Up @@ -401,7 +401,7 @@ function uniqFast(items: string[]): string[] {
function getLastActorDisplayName(lastActorDetails: Partial<PersonalDetails> | null, hasMultipleParticipants: boolean) {
return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID
? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
lastActorDetails.firstName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails)
lastActorDetails.firstName || LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails))
: '';
}

Expand Down Expand Up @@ -499,7 +499,7 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY:
case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: {
lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, {
displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails),
displayName: LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails)),
policyName: ReportUtils.getPolicyName(report, false, policy),
});
break;
Expand Down Expand Up @@ -1351,10 +1351,10 @@ function getShareLogOptions(options: OptionList, betas: Beta[] = []): Options {
* Build the IOUConfirmation options for showing the payee personalDetail
*/
function getIOUConfirmationOptionsFromPayeePersonalDetail(personalDetail: OnyxEntry<PersonalDetails>, amountText?: string): PayeePersonalDetails {
const formattedLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '');
const login = personalDetail?.login ?? '';
return {
text: PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, formattedLogin),
alternateText: formattedLogin || PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false),
text: LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, login)),
alternateText: LocalePhoneNumber.formatPhoneNumber(login || PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false)),
icons: [
{
source: personalDetail?.avatar ?? FallbackAvatar,
Expand Down
4 changes: 3 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import DateUtils from './DateUtils';
import * as Environment from './Environment/Environment';
import getBase62ReportID from './getBase62ReportID';
import isReportMessageAttachment from './isReportMessageAttachment';
import {formatPhoneNumber} from './LocalePhoneNumber';
import * as Localize from './Localize';
import Log from './Log';
import type {MessageElementBase, MessageTextElement} from './MessageElement';
Expand Down Expand Up @@ -1705,7 +1706,8 @@ function getPolicyChangeLogAddEmployeeMessage(reportAction: OnyxInputOrEntry<Rep
const originalMessage = getOriginalMessage(reportAction);
const email = originalMessage?.email ?? '';
const role = originalMessage?.role ?? '';
return Localize.translateLocal('report.actions.type.addEmployee', {email, role});
const formattedEmail = formatPhoneNumber(email);
return Localize.translateLocal('report.actions.type.addEmployee', {email: formattedEmail, role});
}

function isPolicyChangeLogChangeRoleMessage(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE> {
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ function getDisplayNameForParticipant(

// If the user's personal details (first name) should be hidden, make sure we return "hidden" instead of the short name
if (shouldFallbackToHidden && longName === hiddenTranslation) {
return longName;
return LocalePhoneNumber.formatPhoneNumber(longName);
}

const shortName = personalDetails.firstName ? personalDetails.firstName : longName;
Expand Down Expand Up @@ -2378,7 +2378,7 @@ function getIcons(
const actorIcon = {
id: actorAccountID,
source: personalDetails?.[actorAccountID ?? -1]?.avatar ?? FallbackAvatar,
name: actorDisplayName,
name: LocalePhoneNumber.formatPhoneNumber(actorDisplayName),
type: CONST.ICON_TYPE_AVATAR,
fallbackIcon: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.fallbackIcon,
};
Expand Down Expand Up @@ -3840,7 +3840,7 @@ function getInvoicePayerName(report: OnyxEntry<Report>, invoiceReceiverPolicy?:
const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL;

if (isIndividual) {
return PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiver.accountID]);
return LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiver.accountID]));
}

return getPolicyName(report, false, invoiceReceiverPolicy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiver?.policyID}`]);
Expand Down Expand Up @@ -3932,7 +3932,7 @@ function getInvoicesChatName(report: OnyxEntry<Report>, receiverPolicy: OnyxEntr
}

if (isIndividual) {
return PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiverAccountID]);
return LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiverAccountID]));
}

return getPolicyName(report, false, invoiceReceiverPolicy);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ function getAssignee(assigneeAccountID: number, personalDetails: OnyxEntry<OnyxT

return {
icons: ReportUtils.getIconsForParticipants([details.accountID], personalDetails),
displayName: PersonalDetailsUtils.getDisplayNameOrDefault(details),
displayName: LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
subtitle: details.login ?? '',
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function ProfilePage({route}: ProfilePageProps) {
return {accountID: optimisticAccountID, login: loginParams, displayName: loginParams};
}, [personalDetails, accountID, loginParams, isValidAccountID]);

const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(details, undefined, undefined, isCurrentUser);
const displayName = formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details, undefined, undefined, isCurrentUser));
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const fallbackIcon = details?.fallbackIcon ?? '';
const login = details?.login ?? '';
Expand Down
29 changes: 8 additions & 21 deletions src/pages/ReportParticipantDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import Avatar from '@components/Avatar';
import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
Expand All @@ -26,24 +25,18 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx';
import type {PersonalDetails} from '@src/types/onyx';
import NotFoundPage from './ErrorPage/NotFoundPage';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound';

type ReportParticipantDetailsOnyxProps = {
/** Personal details of all users */
personalDetails: OnyxEntry<PersonalDetailsList>;
};
type ReportParticipantDetailsPageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ParticipantsNavigatorParamList, typeof SCREENS.REPORT_PARTICIPANTS.DETAILS>;

type ReportParticipantDetailsPageProps = WithReportOrNotFoundProps &
PlatformStackScreenProps<ParticipantsNavigatorParamList, typeof SCREENS.REPORT_PARTICIPANTS.DETAILS> &
ReportParticipantDetailsOnyxProps;

function ReportParticipantDetails({personalDetails, report, route}: ReportParticipantDetailsPageProps) {
function ReportParticipantDetails({report, route}: ReportParticipantDetailsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {formatPhoneNumber, translate} = useLocalize();
const StyleUtils = useStyleUtils();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = React.useState(false);
Expand All @@ -54,7 +47,7 @@ function ReportParticipantDetails({personalDetails, report, route}: ReportPartic
const member = report?.participants?.[accountID];
const details = personalDetails?.[accountID] ?? ({} as PersonalDetails);
const fallbackIcon = details.fallbackIcon ?? '';
const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(details);
const displayName = formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details));
const isCurrentUserAdmin = ReportUtils.isGroupChatAdmin(report, currentUserPersonalDetails?.accountID);
const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID;
const removeUser = useCallback(() => {
Expand Down Expand Up @@ -149,10 +142,4 @@ function ReportParticipantDetails({personalDetails, report, route}: ReportPartic

ReportParticipantDetails.displayName = 'ReportParticipantDetails';

export default withReportOrNotFound()(
withOnyx<ReportParticipantDetailsPageProps, ReportParticipantDetailsOnyxProps>({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(ReportParticipantDetails),
);
export default withReportOrNotFound()(ReportParticipantDetails);
2 changes: 1 addition & 1 deletion src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) {
onCancel={() => setRemoveMembersConfirmModalVisible(false)}
prompt={translate('workspace.people.removeMembersPrompt', {
count: selectedMembers.length,
memberName: PersonalDetailsUtils.getPersonalDetailsByIDs(selectedMembers, currentUserAccountID).at(0)?.displayName ?? '',
memberName: formatPhoneNumber(PersonalDetailsUtils.getPersonalDetailsByIDs(selectedMembers, currentUserAccountID).at(0)?.displayName ?? ''),
})}
confirmText={translate('common.remove')}
cancelText={translate('common.cancel')}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/RoomMemberDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import * as Report from '@libs/actions/Report';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {RoomMembersNavigatorParamList} from '@libs/Navigation/types';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
Expand All @@ -33,7 +34,7 @@ type RoomMemberDetailsPagePageProps = WithReportOrNotFoundProps & PlatformStackS

function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {formatPhoneNumber, translate} = useLocalize();
const StyleUtils = useStyleUtils();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
Expand All @@ -47,7 +48,7 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps)
const member = report?.participants?.[accountID];
const details = personalDetails?.[accountID] ?? ({} as PersonalDetails);
const fallbackIcon = details.fallbackIcon ?? '';
const displayName = details.displayName ?? '';
const displayName = formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details));
const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID;
const isSelectedMemberOwner = accountID === report.ownerAccountID;
const shouldDisableRemoveUser = (ReportUtils.isPolicyExpenseChat(report) && PolicyUtils.isUserPolicyAdmin(policy, details.login)) || isSelectedMemberCurrentUser || isSelectedMemberOwner;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function RoomMembersPage({report, policies}: RoomMembersPageProps) {
onCancel={() => setRemoveMembersConfirmModalVisible(false)}
prompt={translate('roomMembersPage.removeMembersPrompt', {
count: selectedMembers.length,
memberName: PersonalDetailsUtils.getPersonalDetailsByIDs(selectedMembers, currentUserAccountID).at(0)?.displayName ?? '',
memberName: formatPhoneNumber(PersonalDetailsUtils.getPersonalDetailsByIDs(selectedMembers, currentUserAccountID).at(0)?.displayName ?? ''),
})}
confirmText={translate('common.remove')}
cancelText={translate('common.cancel')}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import ControlSelection from '@libs/ControlSelection';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as ErrorUtils from '@libs/ErrorUtils';
import focusComposerWithDelay from '@libs/focusComposerWithDelay';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
import ModifiedExpenseMessage from '@libs/ModifiedExpenseMessage';
import Navigation from '@libs/Navigation/Navigation';
import Permissions from '@libs/Permissions';
Expand Down Expand Up @@ -603,7 +604,7 @@ function ReportActionItem({
);
} else if (ReportActionsUtils.isReimbursementQueuedAction(action)) {
const linkedReport = ReportUtils.isChatThread(report) ? parentReport : report;
const submitterDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails?.[linkedReport?.ownerAccountID ?? -1]);
const submitterDisplayName = LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails?.[linkedReport?.ownerAccountID ?? -1]));
const paymentType = ReportActionsUtils.getOriginalMessage(action)?.paymentType ?? '';

const missingPaymentMethod = ReportUtils.getIndicatedMissingPaymentMethod(userWallet, linkedReport?.reportID ?? '-1', action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
setIsValidateCodeActionModalVisible(false);
}}
sendValidateCode={() => User.requestContactMethodValidateCode(contactMethod)}
descriptionPrimary={translate('contacts.enterMagicCode', {contactMethod})}
descriptionPrimary={translate('contacts.enterMagicCode', {contactMethod: formattedContactMethod})}
/>

{!isValidateCodeActionModalVisible && getMenuItems()}
Expand Down
Loading

0 comments on commit ff419fe

Please sign in to comment.