From 71e37a52c01e10ddfd71f57be7f68f13580f2622 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 1 Nov 2024 02:22:02 +0530 Subject: [PATCH 01/12] v1 changes --- .../FloatingActionButtonAndPopover.tsx | 113 +++++++++++++----- 1 file changed, 82 insertions(+), 31 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index a49b474b185e..c1bf7251ec18 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -179,6 +179,8 @@ function FloatingActionButtonAndPopover( 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 policyChatForActivePolicyID = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]); const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); const fabRef = useRef(null); const {windowHeight} = useWindowDimensions(); @@ -195,10 +197,14 @@ function FloatingActionButtonAndPopover( const avatars = ReportUtils.getIcons(quickActionReport, personalDetails); return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); } + if (policyChatForActivePolicyID.length > 0 && !isEmptyObject(policyChatForActivePolicyID.at(0))) { + const avatars = ReportUtils.getIcons(policyChatForActivePolicyID.at(0), personalDetails); + return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(policyChatForActivePolicyID.at(0)) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); + } 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, policyChatForActivePolicyID]); const renderQuickActionTooltip = useCallback( () => ( @@ -233,16 +239,18 @@ function FloatingActionButtonAndPopover( 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(); @@ -282,7 +290,7 @@ function FloatingActionButtonAndPopover( break; default: } - }; + }, [quickAction, quickActionReport, reportNameValuePairs, selectOption]); /** * Check if LHN status changed from active to inactive. @@ -413,6 +421,73 @@ function FloatingActionButtonAndPopover( ]; }, [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, + }; + + const quickActionItems = []; + if (quickAction?.action) { + quickActionItems.push({ + ...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, + }); + } else if (policyChatForActivePolicyID.length > 0 && !isEmptyObject(policyChatForActivePolicyID.at(0))) { + quickActionItems.push({ + ...baseQuickAction, + icon: Expensicons.ReceiptScan, + text: translate('quickAction.scanReceipt'), + description: ReportUtils.getReportName(policyChatForActivePolicyID.at(0)), + onSelected: () => + interceptAnonymousUser(() => { + selectOption(() => { + const isValidReport = !(isEmptyObject(policyChatForActivePolicyID.at(0)) || ReportUtils.isArchivedRoom(policyChatForActivePolicyID.at(0), reportNameValuePairs)); + const quickActionReportID = isValidReport ? policyChatForActivePolicyID.at(0)?.reportID ?? '-1' : ReportUtils.generateReportID(); + IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true); + }, true); + }), + shouldShowSubscriptRightAvatar: true, + shouldRenderTooltip: false, + }); + } + + return quickActionItems; + }, [ + translate, + quickActionAvatars, + styles.popoverMenuItem.paddingHorizontal, + styles.popoverMenuItem.paddingVertical, + styles.quickActionTooltipWrapper, + renderQuickActionTooltip, + quickAction?.action, + quickAction?.isFirstQuickAction, + policyChatForActivePolicyID, + quickActionTitle, + hideQABSubtitle, + quickActionReport, + navigateToQuickAction, + selectOption, + reportNameValuePairs, + ]); + return ( 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.length > 0 ? quickActionMenuItems : []), ]} withoutOverlay anchorRef={fabRef} From 62fe24c4236d23441644bfed881beabfed41cd9c Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 1 Nov 2024 23:04:01 +0530 Subject: [PATCH 02/12] fixes --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index c1bf7251ec18..ea26786cf14e 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -180,7 +180,10 @@ function FloatingActionButtonAndPopover( const {translate} = useLocalize(); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID ?? -1}`); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); - const policyChatForActivePolicyID = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]); + const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`); + const policyChatForActivePolicyID = useMemo(() => { + return activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; + }, [activePolicy, activePolicyID, session?.accountID]); const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); const fabRef = useRef(null); const {windowHeight} = useWindowDimensions(); From 060c3cc0d3808ac351beb41565f3069018a8ea6f Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 2 Nov 2024 00:29:18 +0530 Subject: [PATCH 03/12] fixes avatar handling --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index ea26786cf14e..51a2675c44b5 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -202,7 +202,7 @@ function FloatingActionButtonAndPopover( } if (policyChatForActivePolicyID.length > 0 && !isEmptyObject(policyChatForActivePolicyID.at(0))) { const avatars = ReportUtils.getIcons(policyChatForActivePolicyID.at(0), personalDetails); - return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(policyChatForActivePolicyID.at(0)) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); + return avatars; } return []; // Policy is needed as a dependency in order to update the shortcut details when the workspace changes From 32aaff86c7c6af795c126c9a078ff28c52e3fece Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 2 Nov 2024 01:03:08 +0530 Subject: [PATCH 04/12] resolve review comments --- .../FloatingActionButtonAndPopover.tsx | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 51a2675c44b5..a784c255a17a 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -181,9 +181,14 @@ function FloatingActionButtonAndPopover( 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 policyChatForActivePolicyID = useMemo(() => { + const policyChatsForActivePolicyID = useMemo(() => { return activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; }, [activePolicy, activePolicyID, session?.accountID]); + + const policyChatForActivePolicy = useMemo(() => { + return policyChatsForActivePolicyID.length > 0 ? policyChatsForActivePolicyID.at(0) : ({} as OnyxTypes.Report); + }, [policyChatsForActivePolicyID]); + const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); const fabRef = useRef(null); const {windowHeight} = useWindowDimensions(); @@ -200,14 +205,14 @@ function FloatingActionButtonAndPopover( const avatars = ReportUtils.getIcons(quickActionReport, personalDetails); return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); } - if (policyChatForActivePolicyID.length > 0 && !isEmptyObject(policyChatForActivePolicyID.at(0))) { - const avatars = ReportUtils.getIcons(policyChatForActivePolicyID.at(0), personalDetails); + if (!isEmptyObject(policyChatForActivePolicy)) { + const avatars = ReportUtils.getIcons(policyChatForActivePolicy, personalDetails); return 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, policyChatForActivePolicyID]); + }, [personalDetails, session?.accountID, quickActionReport, quickActionPolicy, policyChatForActivePolicy]); const renderQuickActionTooltip = useCallback( () => ( @@ -442,37 +447,41 @@ function FloatingActionButtonAndPopover( tooltipWrapperStyle: styles.quickActionTooltipWrapper, }; - const quickActionItems = []; if (quickAction?.action) { - quickActionItems.push({ - ...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, - }); - } else if (policyChatForActivePolicyID.length > 0 && !isEmptyObject(policyChatForActivePolicyID.at(0))) { - quickActionItems.push({ - ...baseQuickAction, - icon: Expensicons.ReceiptScan, - text: translate('quickAction.scanReceipt'), - description: ReportUtils.getReportName(policyChatForActivePolicyID.at(0)), - onSelected: () => - interceptAnonymousUser(() => { - selectOption(() => { - const isValidReport = !(isEmptyObject(policyChatForActivePolicyID.at(0)) || ReportUtils.isArchivedRoom(policyChatForActivePolicyID.at(0), reportNameValuePairs)); - const quickActionReportID = isValidReport ? policyChatForActivePolicyID.at(0)?.reportID ?? '-1' : ReportUtils.generateReportID(); - IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true); - }, true); - }), - shouldShowSubscriptRightAvatar: true, - shouldRenderTooltip: false, - }); + 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); + }, true); + }), + shouldShowSubscriptRightAvatar: true, + shouldRenderTooltip: false, + }, + ]; } - return quickActionItems; + return []; }, [ translate, quickActionAvatars, @@ -482,7 +491,7 @@ function FloatingActionButtonAndPopover( renderQuickActionTooltip, quickAction?.action, quickAction?.isFirstQuickAction, - policyChatForActivePolicyID, + policyChatForActivePolicy, quickActionTitle, hideQABSubtitle, quickActionReport, @@ -546,7 +555,7 @@ function FloatingActionButtonAndPopover( }, ] : []), - ...(quickActionMenuItems.length > 0 ? quickActionMenuItems : []), + ...quickActionMenuItems, ]} withoutOverlay anchorRef={fabRef} From a00c2e2043d6be74127b9ba37423d152083c83d4 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 2 Nov 2024 01:13:23 +0530 Subject: [PATCH 05/12] merge usememos --- .../SidebarScreen/FloatingActionButtonAndPopover.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index a784c255a17a..1ab2926812f4 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -181,13 +181,10 @@ function FloatingActionButtonAndPopover( 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 policyChatsForActivePolicyID = useMemo(() => { - return activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; - }, [activePolicy, activePolicyID, session?.accountID]); - const policyChatForActivePolicy = useMemo(() => { - return policyChatsForActivePolicyID.length > 0 ? policyChatsForActivePolicyID.at(0) : ({} as OnyxTypes.Report); - }, [policyChatsForActivePolicyID]); + const policyChatsForActivePolicy = activePolicy?.isPolicyExpenseChatEnabled ? 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(null); @@ -500,6 +497,7 @@ function FloatingActionButtonAndPopover( reportNameValuePairs, ]); + console.log('quickActionMenuItems', quickActionMenuItems); return ( Date: Sat, 2 Nov 2024 01:13:38 +0530 Subject: [PATCH 06/12] lint --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 1ab2926812f4..1c5921d0e219 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -182,7 +182,7 @@ function FloatingActionButtonAndPopover( const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`); const policyChatForActivePolicy = useMemo(() => { - const policyChatsForActivePolicy = activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; + const policyChatsForActivePolicy = activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; return policyChatsForActivePolicy.length > 0 ? policyChatsForActivePolicy.at(0) : ({} as OnyxTypes.Report); }, [activePolicy, activePolicyID, session?.accountID]); From 0b6e49705ac98c36ab6cc7f75c0a7d9e21382d58 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 2 Nov 2024 01:16:31 +0530 Subject: [PATCH 07/12] fix lint --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 1c5921d0e219..9fd251027258 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -182,7 +182,10 @@ function FloatingActionButtonAndPopover( const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`); const policyChatForActivePolicy = useMemo(() => { - const policyChatsForActivePolicy = activePolicy?.isPolicyExpenseChatEnabled ? ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]) : []; + if (!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]); From 508065a97b047fcbd403ed645a8a1f9a11899e97 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 2 Nov 2024 01:34:23 +0530 Subject: [PATCH 08/12] remove console --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 9fd251027258..3d6a25d9d9c3 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -500,7 +500,6 @@ function FloatingActionButtonAndPopover( reportNameValuePairs, ]); - console.log('quickActionMenuItems', quickActionMenuItems); return ( Date: Sat, 2 Nov 2024 01:36:26 +0530 Subject: [PATCH 09/12] use isEmptyObject --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 3d6a25d9d9c3..56ea54456822 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -182,7 +182,7 @@ function FloatingActionButtonAndPopover( const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`); const policyChatForActivePolicy = useMemo(() => { - if (!activePolicy || !activePolicy?.isPolicyExpenseChatEnabled) { + if (isEmptyObject(activePolicy) || !activePolicy?.isPolicyExpenseChatEnabled) { return {} as OnyxTypes.Report; } const policyChatsForActivePolicy = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1]); From 92bb507cf53b45389ba62ed0e7bafca9663339d4 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:26:35 +0530 Subject: [PATCH 10/12] Update src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx Co-authored-by: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 56ea54456822..4f8f704c8fa6 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -206,7 +206,7 @@ function FloatingActionButtonAndPopover( return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); } if (!isEmptyObject(policyChatForActivePolicy)) { - const avatars = ReportUtils.getIcons(policyChatForActivePolicy, personalDetails); + return ReportUtils.getIcons(policyChatForActivePolicy, personalDetails); return avatars; } return []; From f4992c71c4981b1c27ef227a79e9f624adbe6af1 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:37:19 +0530 Subject: [PATCH 11/12] Update src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 4f8f704c8fa6..d70c0b6a90fd 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -207,7 +207,6 @@ function FloatingActionButtonAndPopover( } if (!isEmptyObject(policyChatForActivePolicy)) { return ReportUtils.getIcons(policyChatForActivePolicy, personalDetails); - return avatars; } return []; // Policy is needed as a dependency in order to update the shortcut details when the workspace changes From ccee92f1d3b8fbbbc0fd2d10621cb5f92bf020a3 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Wed, 6 Nov 2024 04:16:38 +0530 Subject: [PATCH 12/12] minor improvements --- src/libs/ReportUtils.ts | 3 +-- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d8133991d62b..a62716975c01 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7326,8 +7326,7 @@ function canCreateRequest(report: OnyxEntry, policy: OnyxEntry, return requestOptions.includes(iouType); } -function getWorkspaceChats(policyID: string, accountIDs: number[]): Array> { - const allReports = ReportConnection.getAllReports(); +function getWorkspaceChats(policyID: string, accountIDs: number[], allReports: OnyxCollection = ReportConnection.getAllReports()): Array> { return Object.values(allReports ?? {}).filter((report) => isPolicyExpenseChat(report) && (report?.policyID ?? '-1') === policyID && accountIDs.includes(report?.ownerAccountID ?? -1)); } diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index e2446c5a172a..88f0c389ba2e 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -154,14 +154,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl const [quickActionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${quickAction?.chatReportID}`); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID ?? -1}`); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); 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]); + const policyChatsForActivePolicy = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1], allReports); return policyChatsForActivePolicy.length > 0 ? policyChatsForActivePolicy.at(0) : ({} as OnyxTypes.Report); - }, [activePolicy, activePolicyID, session?.accountID]); + }, [activePolicy, activePolicyID, session?.accountID, allReports]); const [quickActionPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${quickActionReport?.policyID}`); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector)}); const [hasSeenTrackTraining] = useOnyx(ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING);