Skip to content

Commit

Permalink
Merge pull request Expensify#52682 from mkzie2/mkzie2-issue/51433
Browse files Browse the repository at this point in the history
Update chat with account manager banner
  • Loading branch information
marcaaron authored Nov 28, 2024
2 parents d7aeb7f + f7dfcf3 commit 10a7be8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
19 changes: 18 additions & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import getButtonState from '@libs/getButtonState';
import CONST from '@src/CONST';
import type IconAsset from '@src/types/utils/IconAsset';
import Button from './Button';
import Hoverable from './Hoverable';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
Expand Down Expand Up @@ -46,6 +47,12 @@ type BannerProps = {

/** Styles to be assigned to the Banner text */
textStyles?: StyleProp<TextStyle>;

/** Whether to display button in the banner */
shouldShowButton?: boolean;

/** Callback called when pressing the button */
onButtonPress?: () => void;
};

function Banner({
Expand All @@ -54,11 +61,13 @@ function Banner({
icon = Expensicons.Exclamation,
onClose,
onPress,
onButtonPress,
containerStyles,
textStyles,
shouldRenderHTML = false,
shouldShowIcon = false,
shouldShowCloseButton = false,
shouldShowButton = false,
}: BannerProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -68,7 +77,7 @@ function Banner({
return (
<Hoverable>
{(isHovered) => {
const isClickable = onClose ?? onPress;
const isClickable = onClose && onPress;
const shouldHighlight = isClickable && isHovered;
return (
<View
Expand Down Expand Up @@ -106,6 +115,14 @@ function Banner({
</Text>
))}
</View>
{shouldShowButton && (
<Button
success
style={[styles.pr3]}
text={translate('common.chatNow')}
onPress={onButtonPress}
/>
)}
{shouldShowCloseButton && !!onClose && (
<Tooltip text={translate('common.close')}>
<PressableWithFeedback
Expand Down
3 changes: 3 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
ChangeTypeParams,
CharacterLengthLimitParams,
CharacterLimitParams,
ChatWithAccountManagerParams,
CompanyCardBankName,
CompanyCardFeedNameParams,
CompanyNameParams,
Expand Down Expand Up @@ -475,6 +476,8 @@ const translations = {
links: 'Links',
days: 'days',
rename: 'Rename',
chatWithAccountManager: ({accountManagerDisplayName}: ChatWithAccountManagerParams) => `Need something specific? Chat with your account manager, ${accountManagerDisplayName}.`,
chatNow: 'Chat now',
},
location: {
useCurrent: 'Use current location',
Expand Down
3 changes: 3 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
ChangeTypeParams,
CharacterLengthLimitParams,
CharacterLimitParams,
ChatWithAccountManagerParams,
CompanyCardBankName,
CompanyCardFeedNameParams,
CompanyNameParams,
Expand Down Expand Up @@ -466,6 +467,8 @@ const translations = {
sent: 'Enviado',
links: 'Enlaces',
days: 'días',
chatWithAccountManager: ({accountManagerDisplayName}: ChatWithAccountManagerParams) => `¿Necesitas algo específico? Habla con tu gerente de cuenta, ${accountManagerDisplayName}.`,
chatNow: 'Chatear ahora',
},
connectionComplete: {
title: 'Conexión completa',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ type CompanyNameParams = {
companyName: string;
};

type ChatWithAccountManagerParams = {
accountManagerDisplayName: string;
};

export type {
AuthenticationErrorParams,
ImportMembersSuccessfullDescriptionParams,
Expand Down Expand Up @@ -766,4 +770,5 @@ export type {
CurrencyCodeParams,
WorkspaceLockedPlanTypeParams,
CompanyNameParams,
ChatWithAccountManagerParams,
};
30 changes: 26 additions & 4 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {useOnyx} from 'react-native-onyx';
import Banner from '@components/Banner';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import DragAndDropProvider from '@components/DragAndDrop/Provider';
import * as Expensicons from '@components/Icon/Expensicons';
import MoneyReportHeader from '@components/MoneyReportHeader';
import MoneyRequestHeader from '@components/MoneyRequestHeader';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand All @@ -32,6 +33,7 @@ import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import clearReportNotifications from '@libs/Notification/clearReportNotifications';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -113,6 +115,9 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const [modal] = useOnyx(ONYXKEYS.MODAL);
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false});
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {initialValue: ''});
// If accountManagerReportID is an empty string, using ?? can crash the app.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${accountManagerReportID || '-1'}`);
const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false});
const [reportOnyx, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {initialValue: defaultReportMetadata});
Expand Down Expand Up @@ -157,6 +162,21 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
navigation.setParams({reportID: lastAccessedReportID});
}, [activeWorkspaceID, canUseDefaultRooms, navigation, route, finishedLoadingApp]);

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const chatWithAccountManagerText = useMemo(() => {
if (accountManagerReportID) {
const participants = ReportUtils.getParticipantsAccountIDsForDisplay(accountManagerReport, false, true);
const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs([participants?.at(0) ?? -1], personalDetails);
const participantPersonalDetail = Object.values(participantPersonalDetails).at(0);
const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(participantPersonalDetail);
const login = participantPersonalDetail?.login;
if (displayName && login) {
return translate('common.chatWithAccountManager', {accountManagerDisplayName: `${displayName} (${login})`});
}
}
return '';
}, [accountManagerReportID, accountManagerReport, personalDetails, translate]);

/**
* Create a lightweight Report so as to keep the re-rendering as light as possible by
* passing in only the required props.
Expand Down Expand Up @@ -760,12 +780,14 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
</OfflineWithFeedback>
{!!accountManagerReportID && ReportUtils.isConciergeChatReport(report) && isBannerVisible && (
<Banner
containerStyles={[styles.mh4, styles.mt4, styles.p4, styles.bgDark]}
textStyles={[styles.colorReversed]}
text={translate('reportActionsView.chatWithAccountManager')}
containerStyles={[styles.mh4, styles.mt4, styles.p4, styles.br2]}
text={chatWithAccountManagerText}
onClose={dismissBanner}
onPress={chatWithAccountManager}
onButtonPress={chatWithAccountManager}
shouldShowCloseButton
icon={Expensicons.Lightbulb}
shouldShowIcon
shouldShowButton
/>
)}
<DragAndDropProvider isDisabled={!isCurrentReportLoadedFromOnyx || !ReportUtils.canUserPerformWriteAction(report)}>
Expand Down
8 changes: 0 additions & 8 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,6 @@ const styles = (theme: ThemeColors) =>
lineHeight: variables.lineHeightNormal,
},

colorReversed: {
color: theme.textReversed,
},

colorMutedReversed: {
color: theme.textMutedReversed,
},
Expand All @@ -541,10 +537,6 @@ const styles = (theme: ThemeColors) =>
backgroundColor: 'transparent',
},

bgDark: {
backgroundColor: theme.inverse,
},

opacity0: {
opacity: 0,
},
Expand Down

0 comments on commit 10a7be8

Please sign in to comment.