Skip to content

Commit

Permalink
chore(ui): add enums
Browse files Browse the repository at this point in the history
  • Loading branch information
mavarius committed Nov 3, 2023
1 parent 3bcafec commit 049071b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/homepageExperience/ClickThroughAnnouncementHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import {showOverlay, dismissOverlay} from 'src/overlays/actions/overlays'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
import {event} from 'src/cloud/utils/reporting'

enum AnnouncementID {
MqttEol = 'mqttEolClickThroughAnnouncement',
PriceIncrease = 'pricingClickThroughAnnouncement',
}

enum AnnouncementState {
Dismissed = 'dismissed',
Display = 'display',
}

export const ClickThroughAnnouncementHandler: FC = () => {
const dispatch = useDispatch()
const {account} = useSelector(selectCurrentIdentity)
Expand All @@ -24,7 +34,7 @@ export const ClickThroughAnnouncementHandler: FC = () => {
if (!announcementState[announcementID]) {
setAnnouncementState(prevState => ({
...prevState,
[announcementID]: 'display',
[announcementID]: AnnouncementState.Display,
}))
}
}
Expand All @@ -35,15 +45,15 @@ export const ClickThroughAnnouncementHandler: FC = () => {
setTimeout(() => {
setAnnouncementState(prevState => ({
...prevState,
[announcementID]: 'dismissed',
[announcementID]: AnnouncementState.Dismissed,
}))
}, 1000)
}

const handleDisplayAnnouncement = (announcementID: string): void => {
initAnnouncement(announcementID)

if (announcementState[announcementID] === 'display') {
if (announcementState[announcementID] === AnnouncementState.Display) {
const overlayParams = {
announcementID,
}
Expand All @@ -57,26 +67,25 @@ export const ClickThroughAnnouncementHandler: FC = () => {

useEffect(() => {
// MQTT Audience: Cloud users with MQTT feature flag enabled
const mqttAnnouncementID = 'mqttEolClickThroughAnnouncement'
const isMqttAudience = isFlagEnabled('subscriptionsUI')

// PAYG Pricing Increase Audience: Pay As You Go & Direct Signups
const priceIncreaseAnnouncementID = 'pricingClickThroughAnnouncement'
const isPaygAccount = account.type === 'pay_as_you_go'
const isDirectSignup = account.billingProvider === 'zuora'
const isPriceIncreaseAudience = isPaygAccount && isDirectSignup

// Sequentially display announcements in order of priority
if (
isMqttAudience &&
announcementState[mqttAnnouncementID] !== 'dismissed'
announcementState[AnnouncementID.MqttEol] !== AnnouncementState.Dismissed
) {
handleDisplayAnnouncement(mqttAnnouncementID)
handleDisplayAnnouncement(AnnouncementID.MqttEol)
} else if (
isPriceIncreaseAudience &&
announcementState[priceIncreaseAnnouncementID] !== 'dismissed'
announcementState[AnnouncementID.PriceIncrease] !==
AnnouncementState.Dismissed
) {
handleDisplayAnnouncement(priceIncreaseAnnouncementID)
handleDisplayAnnouncement(AnnouncementID.PriceIncrease)
}
}, [announcementState])

Expand Down

0 comments on commit 049071b

Please sign in to comment.