Skip to content

Commit ab115d9

Browse files
author
MargeBot
committed
Merge branch 'fix/byoe-spotlight-modal' into 'main'
Stabilize BYOE modal trigger logic See merge request web/clients!25484
2 parents 80785b5 + 8aba65a commit ab115d9

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

applications/mail/src/app/containers/globalModals/GlobalBYOESpotlightModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

33
import { c, msgid } from 'ttag';
44

@@ -19,6 +19,7 @@ import { ModalType } from './inteface';
1919

2020
export const GlobalBYOESpotlightModal = () => {
2121
const { subscribe } = useMailGlobalModals();
22+
const renderOnceRef = useRef(false);
2223

2324
const [modalProps, setOpen, shouldRender] = useModalState();
2425
const [byoeSpotlightModalProps, setBYOESpotlightModalProps] = useState<BYOESpotlightModalPayload['value'] | null>(
@@ -37,7 +38,8 @@ export const GlobalBYOESpotlightModal = () => {
3738

3839
const onDisplayed = byoeSpotlightModalProps?.onDisplayed;
3940
useEffect(() => {
40-
if (shouldRender) {
41+
if (shouldRender && !renderOnceRef.current) {
42+
renderOnceRef.current = true;
4143
onDisplayed?.();
4244
}
4345
}, [shouldRender, onDisplayed]);

applications/mail/src/app/hooks/useShowBYOESpotlightModal.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, useMemo, useRef } from 'react';
22

33
import { differenceInDays, fromUnixTime } from 'date-fns';
44

@@ -16,27 +16,30 @@ import { useMailGlobalModals } from '../containers/globalModals/GlobalModalProvi
1616
import { ModalType } from '../containers/globalModals/inteface';
1717

1818
const useShowBYOESpotlightModal = () => {
19+
const notifiedRef = useRef(false);
1920
const [user] = useUser();
2021
const [addresses = []] = useAddresses();
2122
const allSyncs = useEasySwitchSelector(getAllSync);
2223
const syncListLoaded = useEasySwitchSelector(selectSyncListLoadingState);
23-
const { feature, update } = useFeature(FeatureCode.BYOESpotlightModal);
24+
const { feature, update, loading: loadingFeature } = useFeature(FeatureCode.BYOESpotlightModal);
2425
const { notify } = useMailGlobalModals();
2526

2627
const [hasAccessToBYOE, loadingBYOEFeatureStatus] = useBYOEFeatureStatus(false);
2728

28-
const emailsFromAddresses = new Set(addresses.map((address) => address.Email));
29-
const { forwardingSyncs, byoeSyncs } = allSyncs.reduce<{ forwardingSyncs: Sync[]; byoeSyncs: Sync[] }>(
30-
(acc, sync) => {
31-
if (emailsFromAddresses.has(sync.account)) {
32-
acc.byoeSyncs.push(sync);
33-
} else {
34-
acc.forwardingSyncs.push(sync);
35-
}
36-
return acc;
37-
},
38-
{ forwardingSyncs: [], byoeSyncs: [] }
39-
);
29+
const { forwardingSyncs, byoeSyncs } = useMemo(() => {
30+
const emailsFromAddresses = new Set(addresses.map((address) => address.Email));
31+
return allSyncs.reduce<{ forwardingSyncs: Sync[]; byoeSyncs: Sync[] }>(
32+
(acc, sync) => {
33+
if (emailsFromAddresses.has(sync.account)) {
34+
acc.byoeSyncs.push(sync);
35+
} else {
36+
acc.forwardingSyncs.push(sync);
37+
}
38+
return acc;
39+
},
40+
{ forwardingSyncs: [], byoeSyncs: [] }
41+
);
42+
}, [addresses, allSyncs]);
4043

4144
// Show the modal if:
4245
// - User has access to BYOE (feature flag ON && not b2b sub user)
@@ -45,17 +48,20 @@ const useShowBYOESpotlightModal = () => {
4548
// - User never seen the modal before (old feature flag system)
4649
// - User is not busy
4750
const canShowBYOESpotlightModal =
51+
!notifiedRef.current &&
4852
!loadingBYOEFeatureStatus &&
4953
hasAccessToBYOE &&
5054
!getIsBYOEOnlyAccount(addresses) &&
5155
byoeSyncs.length === 0 &&
5256
syncListLoaded === 'success' &&
5357
differenceInDays(new Date(), fromUnixTime(user.CreateTime)) >= 30 &&
58+
!loadingFeature &&
5459
!!feature?.Value &&
5560
!domIsBusy();
5661

5762
useEffect(() => {
5863
if (canShowBYOESpotlightModal) {
64+
notifiedRef.current = true; // We only want to notify once
5965
notify({
6066
type: ModalType.BYOESpotlight,
6167
value: {

0 commit comments

Comments
 (0)