Skip to content

[Workspace Chats for All] Default QAB to primary workspace if no value #51836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@
const styles = useThemeStyles();
const {translate} = useLocalize();
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID ?? -1}`);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const policyChatForActivePolicy = useMemo(() => {
if (isEmptyObject(activePolicy) || !activePolicy?.isPolicyExpenseChatEnabled) {
return {} as OnyxTypes.Report;
}
const policyChatsForActivePolicy = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]);
return policyChatsForActivePolicy.length > 0 ? policyChatsForActivePolicy.at(0) : ({} as OnyxTypes.Report);
}, [activePolicy, activePolicyID, session?.accountID]);

const [isCreateMenuActive, setIsCreateMenuActive] = useState(false);
const fabRef = useRef<HTMLDivElement>(null);
const {windowHeight} = useWindowDimensions();
Expand All @@ -190,15 +200,19 @@
const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);

const quickActionAvatars = useMemo(() => {

Check failure on line 203 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an `any` value

Check failure on line 203 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an `any` value
if (quickActionReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
if (!isEmptyObject(policyChatForActivePolicy)) {
return ReportUtils.getIcons(policyChatForActivePolicy, personalDetails);
return avatars;

Check failure on line 210 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe return of an `any` typed value

Check failure on line 210 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe return of an `any` typed value

Check failure on line 210 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 'avatars'.
}
return [];
// Policy is needed as a dependency in order to update the shortcut details when the workspace changes
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [personalDetails, session?.accountID, quickActionReport, quickActionPolicy]);
}, [personalDetails, session?.accountID, quickActionReport, quickActionPolicy, policyChatForActivePolicy]);

const renderQuickActionTooltip = useCallback(
() => (
Expand All @@ -214,8 +228,8 @@
if (isEmptyObject(quickActionReport)) {
return '';
}
if (quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && quickActionAvatars.length > 0) {

Check failure on line 231 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .length on an `any` value

Check failure on line 231 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .length on an `any` value
const name: string = ReportUtils.getDisplayNameForParticipant(+(quickActionAvatars.at(0)?.id ?? -1), true) ?? '';

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe call of an `any` typed value

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .at on an `any` value

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .id on an `any` value

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe call of an `any` typed value

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .at on an `any` value

Check failure on line 232 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .id on an `any` value
return translate('quickAction.paySomeone', {name});
}
const titleKey = getQuickActionTitle(quickAction?.action ?? ('' as QuickActionName));
Expand All @@ -226,23 +240,25 @@
if (isEmptyObject(quickActionReport)) {
return true;
}
if (quickActionAvatars.length === 0) {

Check failure on line 243 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .length on an `any` value

Check failure on line 243 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .length on an `any` value
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Computed name [quickActionAvatars.at(0)?.id ?? -1] resolves to an `any` value

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe call of an `any` typed value

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .at on an `any` value

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Computed name [quickActionAvatars.at(0)?.id ?? -1] resolves to an `any` value

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe call of an `any` typed value

Check failure on line 246 in src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .at on an `any` value
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);

const navigateToQuickAction = () => {
const selectOption = (onSelected: () => void, shouldRestrictAction: boolean) => {
const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
if (shouldRestrictAction && quickActionReport?.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(quickActionReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(quickActionReport.policyID));
return;
}

onSelected();
};
},
[quickActionReport?.policyID],
);

const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

Expand Down Expand Up @@ -282,7 +298,7 @@
break;
default:
}
};
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -413,6 +429,77 @@
];
}, [canUseCombinedTrackSubmit, translate, selfDMReportID, hasSeenTrackTraining, isOffline]);

const quickActionMenuItems = useMemo(() => {
// Define common properties in baseQuickAction
const baseQuickAction = {
label: translate('quickAction.header'),
isLabelHoverable: false,
floatRightAvatars: quickActionAvatars,
floatRightAvatarSize: CONST.AVATAR_SIZE.SMALL,
numberOfLinesDescription: 1,
tooltipAnchorAlignment: {
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
},
tooltipShiftHorizontal: styles.popoverMenuItem.paddingHorizontal,
tooltipShiftVertical: styles.popoverMenuItem.paddingVertical / 2,
renderTooltipContent: renderQuickActionTooltip,
tooltipWrapperStyle: styles.quickActionTooltipWrapper,
};

if (quickAction?.action) {
return [
{
...baseQuickAction,
icon: getQuickActionIcon(quickAction?.action),
text: quickActionTitle,
description: !hideQABSubtitle ? ReportUtils.getReportName(quickActionReport) ?? translate('quickAction.updateDestination') : '',
onSelected: () => interceptAnonymousUser(() => navigateToQuickAction()),
shouldShowSubscriptRightAvatar: ReportUtils.isPolicyExpenseChat(quickActionReport),
shouldRenderTooltip: quickAction.isFirstQuickAction,
},
];
}
if (!isEmptyObject(policyChatForActivePolicy)) {
return [
{
...baseQuickAction,
icon: Expensicons.ReceiptScan,
text: translate('quickAction.scanReceipt'),
description: ReportUtils.getReportName(policyChatForActivePolicy),
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
Comment on lines +456 to +458
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition of this caused You no longer have access to your previous... to be displayed when first expense was submitted via QAB.

}, true);
}),
shouldShowSubscriptRightAvatar: true,
shouldRenderTooltip: false,
},
];
}

return [];
}, [
translate,
quickActionAvatars,
styles.popoverMenuItem.paddingHorizontal,
styles.popoverMenuItem.paddingVertical,
styles.quickActionTooltipWrapper,
renderQuickActionTooltip,
quickAction?.action,
quickAction?.isFirstQuickAction,
policyChatForActivePolicy,
quickActionTitle,
hideQABSubtitle,
quickActionReport,
navigateToQuickAction,
selectOption,
reportNameValuePairs,
]);

return (
<View style={styles.flexGrow1}>
<PopoverMenu
Expand Down Expand Up @@ -468,31 +555,7 @@
},
]
: []),
...(quickAction?.action
? [
{
icon: getQuickActionIcon(quickAction?.action),
text: quickActionTitle,
label: translate('quickAction.header'),
isLabelHoverable: false,
floatRightAvatars: quickActionAvatars,
floatRightAvatarSize: CONST.AVATAR_SIZE.SMALL,
description: !hideQABSubtitle ? ReportUtils.getReportName(quickActionReport) ?? translate('quickAction.updateDestination') : '',
numberOfLinesDescription: 1,
onSelected: () => interceptAnonymousUser(() => navigateToQuickAction()),
shouldShowSubscriptRightAvatar: ReportUtils.isPolicyExpenseChat(quickActionReport),
shouldRenderTooltip: quickAction.isFirstQuickAction,
tooltipAnchorAlignment: {
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
},
tooltipShiftHorizontal: styles.popoverMenuItem.paddingHorizontal,
tooltipShiftVertical: styles.popoverMenuItem.paddingVertical / 2,
renderTooltipContent: renderQuickActionTooltip,
tooltipWrapperStyle: styles.quickActionTooltipWrapper,
},
]
: []),
...quickActionMenuItems,
]}
withoutOverlay
anchorRef={fabRef}
Expand Down
Loading