forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notifs: Add snoozable banner for notifs-soon-to-expire
- Loading branch information
1 parent
c63ed60
commit 6058c75
Showing
11 changed files
with
231 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* @flow strict-local */ | ||
|
||
import React from 'react'; | ||
import type { Node } from 'react'; | ||
import subWeeks from 'date-fns/subWeeks'; | ||
|
||
import ZulipBanner from './ZulipBanner'; | ||
import { useSelector, useDispatch, useGlobalSelector } from '../react-redux'; | ||
import { getAccount, getSilenceServerPushSetupWarnings } from '../account/accountsSelectors'; | ||
import { dismissServerNotifsExpiringBanner } from '../account/accountActions'; | ||
import { | ||
kPushNotificationsEnabledEndDoc, | ||
pushNotificationsEnabledEndTimestampWarning, | ||
} from '../settings/NotifTroubleshootingScreen'; | ||
import { useDateRefreshedAtInterval } from '../reactUtils'; | ||
import { openLinkWithUserPreference } from '../utils/openLink'; | ||
import { getGlobalSettings } from '../directSelectors'; | ||
|
||
type Props = $ReadOnly<{||}>; | ||
|
||
/** | ||
* A "nag banner" saying the server will soon disable notifications, if so. | ||
* | ||
* Offers a dismiss button. If this notice is dismissed, it sleeps for a | ||
* week, then reappears if the warning still applies. | ||
*/ | ||
export default function ServerNotifsExpiringBanner(props: Props): Node { | ||
const dispatch = useDispatch(); | ||
|
||
const globalSettings = useGlobalSelector(getGlobalSettings); | ||
|
||
const lastDismissedServerNotifsExpiringBanner = useSelector( | ||
state => getAccount(state).lastDismissedServerNotifsExpiringBanner, | ||
); | ||
|
||
const perAccountState = useSelector(state => state); | ||
const dateNow = useDateRefreshedAtInterval(60_000); | ||
|
||
const expiryWarning = pushNotificationsEnabledEndTimestampWarning(perAccountState, dateNow); | ||
|
||
const silenceServerPushSetupWarnings = useSelector(getSilenceServerPushSetupWarnings); | ||
|
||
let visible = false; | ||
let text = ''; | ||
if (expiryWarning == null) { | ||
// don't show | ||
} else if (silenceServerPushSetupWarnings) { | ||
// don't show | ||
} else if ( | ||
lastDismissedServerNotifsExpiringBanner !== null | ||
&& lastDismissedServerNotifsExpiringBanner >= subWeeks(dateNow, 1) | ||
) { | ||
// don't show | ||
} else { | ||
visible = true; | ||
text = expiryWarning.reactText; | ||
} | ||
|
||
const buttons = []; | ||
buttons.push({ | ||
id: 'dismiss', | ||
label: 'Dismiss', | ||
onPress: () => { | ||
dispatch(dismissServerNotifsExpiringBanner()); | ||
}, | ||
}); | ||
buttons.push({ | ||
id: 'learn-more', | ||
label: 'Learn more', | ||
onPress: () => { | ||
openLinkWithUserPreference(kPushNotificationsEnabledEndDoc, globalSettings); | ||
}, | ||
}); | ||
|
||
return <ZulipBanner visible={visible} text={text} buttons={buttons} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.