Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import Avatar from './Avatar';
import Button from './Button';
import Text from './Text';

type AccountManagerBookCallButtonProps = {
/** The account manager's calendar link to open when the button is pressed */
type BookCallButtonProps = {
/** The calendar link to open when the button is pressed */
calendarLink: string;

/** When provided, the account manager's avatar is displayed instead of a phone icon */
accountManagerAccountID?: string;
/** When provided, this account's avatar is displayed instead of a phone icon */
avatarAccountID?: number;

/** Whether this button is nested inside another pressable element */
isNested?: boolean;
Expand All @@ -33,12 +33,12 @@ type AccountManagerBookCallButtonProps = {
style?: StyleProp<ViewStyle>;
};

function AccountManagerBookCallButton({calendarLink, accountManagerAccountID, isNested = false, style}: AccountManagerBookCallButtonProps) {
function BookCallButton({calendarLink, avatarAccountID, isNested = false, style}: BookCallButtonProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const icons = useMemoizedLazyExpensifyIcons(['Phone']);
const [accountManagerDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
selector: (personalDetails: PersonalDetailsList | undefined) => (accountManagerAccountID ? personalDetails?.[accountManagerAccountID] : undefined),
const [avatarDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
selector: (personalDetails: PersonalDetailsList | undefined) => (avatarAccountID ? personalDetails?.[avatarAccountID] : undefined),
});

if (!calendarLink) {
Expand All @@ -56,7 +56,7 @@ function AccountManagerBookCallButton({calendarLink, accountManagerAccountID, is
style,
};

if (!accountManagerAccountID) {
if (!avatarAccountID) {
return (
<Button
text={label}
Expand All @@ -70,9 +70,9 @@ function AccountManagerBookCallButton({calendarLink, accountManagerAccountID, is
<Button {...commonProps}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentCenter, styles.gap2]}>
<Avatar
source={accountManagerDetails?.avatar}
avatarID={accountManagerAccountID}
name={accountManagerDetails?.displayName ?? accountManagerDetails?.login}
source={avatarDetails?.avatar}
avatarID={avatarAccountID}
name={avatarDetails?.displayName ?? avatarDetails?.login}
type={CONST.ICON_TYPE_AVATAR}
size={CONST.AVATAR_SIZE.XXX_SMALL}
/>
Expand All @@ -82,4 +82,4 @@ function AccountManagerBookCallButton({calendarLink, accountManagerAccountID, is
);
}

export default AccountManagerBookCallButton;
export default BookCallButton;
10 changes: 5 additions & 5 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,21 +930,21 @@ function getExcludedUsers(employeeList?: PolicyEmployeeList): Record<string, boo
* Used for filtering Guide/AM from contact lists while allowing manual entry.
*
* @param policy - The policy to get the assigned guide from
* @param accountManagerAccountID - The account manager's account ID from the account object (string from ONYXKEYS.ACCOUNT)
* @param accountManagerAccountID - The account manager's account ID from the account object
* @param personalDetails - Personal details collection to look up account manager login
* @returns Object containing extracted emails/logins and exclusions record
*/
function getGuideAndAccountManagerInfo(
policy: OnyxEntry<Policy>,
accountManagerAccountID: string | undefined,
accountManagerAccountID: number | undefined,
personalDetails: OnyxEntry<PersonalDetailsList>,
): {
assignedGuideEmail: string | undefined;
accountManagerLogin: string | undefined;
exclusions: Record<string, boolean>;
} {
const assignedGuideEmail = policy?.assignedGuide?.email?.toLowerCase();
const accountManagerLogin = accountManagerAccountID ? personalDetails?.[Number(accountManagerAccountID)]?.login?.toLowerCase() : undefined;
const accountManagerLogin = accountManagerAccountID ? personalDetails?.[accountManagerAccountID]?.login?.toLowerCase() : undefined;

const exclusions: Record<string, boolean> = {};
if (assignedGuideEmail) {
Expand Down Expand Up @@ -1010,13 +1010,13 @@ function getExpensifyTeamExclusions(personalDetails: OnyxEntry<PersonalDetailsLi
* but can still be manually entered by the user.
*
* @param policy - The policy to get the assigned guide from
* @param accountManagerAccountID - The account manager's account ID from the account object (string from ONYXKEYS.ACCOUNT)
* @param accountManagerAccountID - The account manager's account ID from the account object
* @param personalDetails - Personal details collection to look up account manager login
* @returns Record mapping lowercase emails to true for Guide and Account Manager
*/
function getSoftExclusionsForGuideAndAccountManager(
policy: OnyxEntry<Policy>,
accountManagerAccountID: string | undefined,
accountManagerAccountID: number | undefined,
personalDetails: OnyxEntry<PersonalDetailsList>,
): Record<string, boolean> {
return getGuideAndAccountManagerInfo(policy, accountManagerAccountID, personalDetails).exclusions;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/AccountManagerBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function AccountManagerBanner({reportID}: AccountManagerBannerProps) {
}),
});
const accountManagerReportID = accountManagerData?.accountManagerReportID;
const accountManagerAccountID = Number(accountManagerData?.accountManagerAccountID ?? CONST.DEFAULT_MISSING_ID);
const accountManagerAccountID = accountManagerData?.accountManagerAccountID ?? CONST.DEFAULT_MISSING_ID;
const [participantPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
selector: personalDetailsSelector(accountManagerAccountID),
});
Expand Down
77 changes: 57 additions & 20 deletions src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AccountManagerBookCallButton from '@components/AccountManagerBookCallButton';
import BookCallButton from '@components/BookCallButton';
import Button from '@components/ButtonComposed';
import CaretWrapper from '@components/CaretWrapper';
import ChronosTimerHeaderButton from '@components/ChronosTimerHeaderButton';
Expand Down Expand Up @@ -36,6 +36,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import Parser from '@libs/Parser';
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
import {getHumanAgentAccountIDFromReportAction, getHumanAgentFirstName} from '@libs/ReportActionsUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {
Expand Down Expand Up @@ -123,10 +124,12 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL);
const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL);
const [accountGuideDetails] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountGuideDetailsSelector});
const [accountManagerBookingDetails] = useOnyx(ONYXKEYS.ACCOUNT, {
const [bookCallDetails] = useOnyx(ONYXKEYS.ACCOUNT, {
selector: (account) => ({
accountManagerAccountID: account?.accountManagerAccountID,
accountManagerCalendarLink: account?.accountManagerCalendarLink,
partnerManagerAccountID: account?.partnerManagerAccountID,
partnerManagerCalendarLink: account?.partnerManagerCalendarLink,
}),
});
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
Expand Down Expand Up @@ -218,26 +221,60 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
introSelected?.companySize !== CONST.ONBOARDING_COMPANY_SIZE.MICRO &&
introSelected?.companySize !== CONST.ONBOARDING_COMPANY_SIZE.MICRO_SMALL;

const accountManagerAccountID = accountManagerBookingDetails?.accountManagerAccountID;
const accountManagerAccountID = bookCallDetails?.accountManagerAccountID;
const partnerManagerAccountID = bookCallDetails?.partnerManagerAccountID;
const guideAccountID = accountGuideDetails?.email ? getPersonalDetailByEmail(accountGuideDetails.email)?.accountID : undefined;

// Show the "Book a call" button in the 1:1 DM with the assigned account manager
const shouldShowAccountManagerBookCallInDM =
!!accountManagerAccountID &&
!!accountManagerBookingDetails?.accountManagerCalendarLink &&
isOneOnOneChat(report) &&
!!report?.participants?.[Number(accountManagerAccountID)] &&
!!canUserPerformWriteAction(report, isReportArchived) &&
!isChatThread;
const shouldShowAccountManagerBookCallInConcierge = isConciergeChat && !!accountManagerAccountID && !!accountManagerBookingDetails?.accountManagerCalendarLink;
const shouldShowAccountManagerBookCall = shouldShowAccountManagerBookCallInDM || shouldShowAccountManagerBookCallInConcierge;
// The guide book-call button is only shown before an account manager has been assigned, mirroring the #admins onboarding flow's guide-then-AM handoff
const isGuideEligibleForBooking =
!accountManagerAccountID &&
!!accountGuideDetails?.calendarLink &&
accountGuideDetails?.email !== CONST.EMAIL.CONCIERGE &&
introSelected?.companySize !== CONST.ONBOARDING_COMPANY_SIZE.MICRO &&
introSelected?.companySize !== CONST.ONBOARDING_COMPANY_SIZE.MICRO_SMALL;

// Show the "Book a call" button in the 1:1 DM with the assigned support person, or in the Concierge chat
const getBookCallVisibility = (supportAccountID: number | undefined, calendarLink: string | undefined) => {
const canBookCall = !!supportAccountID && !!calendarLink;
return {
inDM: canBookCall && isOneOnOneChat(report) && !!report?.participants?.[supportAccountID] && !!canUserPerformWriteAction(report, isReportArchived) && !isChatThread,
inConcierge: canBookCall && isConciergeChat,
};
};

Comment thread
c3024 marked this conversation as resolved.
Resolved
const bookCallVisibility = {
accountManager: getBookCallVisibility(accountManagerAccountID, bookCallDetails?.accountManagerCalendarLink),
partnerManager: getBookCallVisibility(partnerManagerAccountID, bookCallDetails?.partnerManagerCalendarLink),
guide: getBookCallVisibility(isGuideEligibleForBooking ? guideAccountID : undefined, accountGuideDetails?.calendarLink),
};

const shouldShowAccountManagerBookCall = bookCallVisibility.accountManager.inDM || bookCallVisibility.accountManager.inConcierge;
const shouldShowPartnerManagerBookCall = bookCallVisibility.partnerManager.inDM || bookCallVisibility.partnerManager.inConcierge;
const shouldShowGuideBookCall = bookCallVisibility.guide.inDM || bookCallVisibility.guide.inConcierge;

const shouldShowBookCall = shouldShowAccountManagerBookCall || shouldShowPartnerManagerBookCall || shouldShowGuideBookCall;

// Render the button full width below the header whenever the available space is narrow, which includes the side panel (e.g. Concierge third-panel)
const shouldStackAccountManagerBookCall = shouldUseNarrowLayout || isInSidePanel;
const shouldStackBookCall = shouldUseNarrowLayout || isInSidePanel;

// A single 1:1 chat can only match one of these roles, and in Concierge only one button is shown at a time, so precedence (account manager, then partner manager, then guide) resolves any overlap
let bookCallCalendarLink: string | undefined;
let bookCallAvatarAccountID: number | undefined;
if (shouldShowAccountManagerBookCall) {
bookCallCalendarLink = bookCallDetails?.accountManagerCalendarLink;
bookCallAvatarAccountID = bookCallVisibility.accountManager.inConcierge ? accountManagerAccountID : undefined;
} else if (shouldShowPartnerManagerBookCall) {
bookCallCalendarLink = bookCallDetails?.partnerManagerCalendarLink;
bookCallAvatarAccountID = bookCallVisibility.partnerManager.inConcierge ? partnerManagerAccountID : undefined;
} else if (shouldShowGuideBookCall) {
bookCallCalendarLink = accountGuideDetails?.calendarLink;
bookCallAvatarAccountID = bookCallVisibility.guide.inConcierge ? guideAccountID : undefined;
}

const accountManagerBookCallButton = (
<AccountManagerBookCallButton
calendarLink={accountManagerBookingDetails?.accountManagerCalendarLink ?? ''}
accountManagerAccountID={shouldShowAccountManagerBookCallInConcierge ? accountManagerBookingDetails?.accountManagerAccountID : undefined}
const bookCallButton = (
<BookCallButton
calendarLink={bookCallCalendarLink ?? ''}
avatarAccountID={bookCallAvatarAccountID}
/>
);

Expand Down Expand Up @@ -434,7 +471,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
)}
</PressableWithoutFeedback>
<View style={[styles.reportOptions, styles.flexRow, styles.alignItemsCenter, styles.gap2]}>
{shouldShowAccountManagerBookCall && !shouldStackAccountManagerBookCall && accountManagerBookCallButton}
{shouldShowBookCall && !shouldStackBookCall && bookCallButton}
{shouldShowOnBoardingHelpDropdownButton && !shouldUseNarrowLayout && onboardingHelpDropdownButton}
{!shouldUseNarrowLayout && !shouldShowDiscount && isChatUsedForOnboarding && (
<FreeTrial
Expand Down Expand Up @@ -469,7 +506,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
)}
</View>
{!isParentReportLoading && !isLoading && canJoin && shouldUseNarrowLayout && <View style={[styles.ph5, styles.pb2]}>{joinButton}</View>}
{shouldShowAccountManagerBookCall && shouldStackAccountManagerBookCall && <View style={[styles.ph5, styles.pb3]}>{accountManagerBookCallButton}</View>}
{shouldShowBookCall && shouldStackBookCall && <View style={[styles.ph5, styles.pb3]}>{bookCallButton}</View>}
<View style={shouldShowOnBoardingHelpDropdownButton && [styles.flexRow, styles.alignItemsCenter, styles.gap1, styles.ph5]}>
{!shouldShowEarlyDiscountBanner && shouldShowOnBoardingHelpDropdownButton && shouldUseNarrowLayout && (
<View style={[styles.flex1, styles.pb3]}>{onboardingHelpDropdownButton}</View>
Expand Down
34 changes: 27 additions & 7 deletions src/pages/settings/HelpPage/HelpPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AccountManagerBookCallButton from '@components/AccountManagerBookCallButton';
import BookCallButton from '@components/BookCallButton';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItemList from '@components/MenuItemList';
import ScreenWrapper from '@components/ScreenWrapper';
Expand Down Expand Up @@ -51,6 +51,11 @@ function HelpPage() {
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const {openConciergeAnywhere} = useOpenConciergeAnywhere();

// Remove the row's accessibility grouping so native (iOS/Android) screen readers can announce the nested
// Book a call button as its own element; on web this prop is a no-op and the button is reached via keyboard Tab instead
const shouldBeAccessibleWithBookCallButton = (calendarLink: string | undefined) => !calendarLink;

const partnerManagerCalendarLink = account?.partnerManagerCalendarLink;
const partnerManagerItem = partnerManagerDetails
? {
key: partnerManagerDetails.login,
Expand All @@ -68,12 +73,21 @@ function HelpPage() {
betas,
personalDetails,
),
shouldShowRightIcon: true,
shouldShowRightIcon: !partnerManagerCalendarLink,
shouldShowRightComponent: !!partnerManagerCalendarLink,
shouldBeAccessible: shouldBeAccessibleWithBookCallButton(partnerManagerCalendarLink),
rightComponent: partnerManagerCalendarLink ? (
<BookCallButton
calendarLink={partnerManagerCalendarLink}
isNested
/>
) : undefined,
wrapperStyle: [styles.sectionMenuItemTopDescription],
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_HELP.PARTNER_MANAGER,
}
: null;

const guideCalendarLink = account?.guideDetails?.calendarLink;
const guideItem = guideDetails
? {
key: guideDetails.login,
Expand All @@ -91,7 +105,15 @@ function HelpPage() {
betas,
personalDetails,
),
shouldShowRightIcon: true,
shouldShowRightIcon: !guideCalendarLink,
shouldShowRightComponent: !!guideCalendarLink,
shouldBeAccessible: shouldBeAccessibleWithBookCallButton(guideCalendarLink),
rightComponent: guideCalendarLink ? (
<BookCallButton
calendarLink={guideCalendarLink}
isNested
/>
) : undefined,
wrapperStyle: [styles.sectionMenuItemTopDescription],
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_HELP.GUIDE,
}
Expand All @@ -117,11 +139,9 @@ function HelpPage() {
),
shouldShowRightIcon: !accountManagerCalendarLink,
shouldShowRightComponent: !!accountManagerCalendarLink,

// Disable the row's accessibility grouping so screen readers can reach the nested Book a call button as its own element
shouldBeAccessible: !accountManagerCalendarLink,
shouldBeAccessible: shouldBeAccessibleWithBookCallButton(accountManagerCalendarLink),
rightComponent: accountManagerCalendarLink ? (
<AccountManagerBookCallButton
<BookCallButton
calendarLink={accountManagerCalendarLink}
isNested
/>
Expand Down
5 changes: 4 additions & 1 deletion src/types/onyx/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Account = {
adminsRoomReportID?: string;

/** The Account ID of the account manager */
accountManagerAccountID?: string;
accountManagerAccountID?: number;

/** The Report ID of the account manager */
accountManagerReportID?: string;
Expand All @@ -124,6 +124,9 @@ type Account = {
/** The email of the partner manager */
partnerManagerEmail?: string;

/** The calendar link of the partner manager */
partnerManagerCalendarLink?: string;

/** The message to be displayed when code requested */
message?: string;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/HelpPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('HelpPage', () => {

it('shows the Book a call button on the account manager row and opens the calendar link when pressed', async () => {
// Given an account manager with a calendar link
await Onyx.merge(ONYXKEYS.ACCOUNT, {accountManagerAccountID: String(ACCOUNT_MANAGER_ACCOUNT_ID), accountManagerCalendarLink: CALENDAR_LINK});
await Onyx.merge(ONYXKEYS.ACCOUNT, {accountManagerAccountID: ACCOUNT_MANAGER_ACCOUNT_ID, accountManagerCalendarLink: CALENDAR_LINK});
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[ACCOUNT_MANAGER_ACCOUNT_ID]: {accountID: ACCOUNT_MANAGER_ACCOUNT_ID, login: 'am@example.com', displayName: ACCOUNT_MANAGER_NAME}});
await waitForBatchedUpdates();

Expand Down
Loading
Loading