Skip to content

Commit 8981a37

Browse files
chrisbobbegnprice
authored andcommitted
NotificationsScreen: Show server-setup alert like other per-account alerts
I.e., as a NavRow with a warning icon in PerAccountNotificationSettingsGroup. And leave ServerPushSetupBanner as a "nag banner" on the home screen.
1 parent d496e94 commit 8981a37

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

src/settings/NotificationsScreen.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import type { RouteProp } from '../react-navigation';
99
import type { AppNavigationProp } from '../nav/AppNavigator';
1010
import { useGlobalSelector, useSelector } from '../react-redux';
1111
import Screen from '../common/Screen';
12-
import ServerPushSetupBanner from '../common/ServerPushSetupBanner';
1312
import NavRow from '../common/NavRow';
1413
import { IconAlertTriangle } from '../common/Icons';
1514
import type { LocalizableText } from '../types';
1615
import { TranslationContext } from '../boot/TranslationProvider';
1716
import { kWarningColor } from '../styles/constants';
1817
import { getIdentities, getIdentity, getIsActiveAccount } from '../account/accountsSelectors';
19-
import { getRealm } from '../directSelectors';
2018
import { openSystemNotificationSettings } from '../utils/openLink';
2119
import {
2220
useNotificationReportsByIdentityKey,
@@ -62,8 +60,6 @@ export default function NotificationsScreen(props: Props): Node {
6260
const otherAccounts = useGlobalSelector(state =>
6361
getIdentities(state).filter(identity_ => !getIsActiveAccount(state, identity_)),
6462
);
65-
const pushNotificationsEnabled = useSelector(state => getRealm(state).pushNotificationsEnabled);
66-
6763
const systemSettingsWarnings = notificationReport.problems
6864
.map(systemSettingsWarning)
6965
.filter(Boolean);
@@ -98,7 +94,6 @@ export default function NotificationsScreen(props: Props): Node {
9894

9995
return (
10096
<Screen title="Notifications">
101-
<ServerPushSetupBanner isDismissable={false} />
10297
<NavRow
10398
leftElement={
10499
systemSettingsWarnings.length > 0
@@ -125,9 +120,7 @@ export default function NotificationsScreen(props: Props): Node {
125120
/>
126121
{!notificationReport.problems.includes(NotificationProblem.SystemSettingsDisabled) && (
127122
<>
128-
{pushNotificationsEnabled && (
129-
<PerAccountNotificationSettingsGroup navigation={navigation} />
130-
)}
123+
<PerAccountNotificationSettingsGroup navigation={navigation} />
131124
{otherAccounts.length > 0 && (
132125
<NavRow
133126
{...(() => {

src/settings/PerAccountNotificationSettingsGroup.js

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import type { Node } from 'react';
55
import invariant from 'invariant';
66

77
import type { AppNavigationMethods } from '../nav/AppNavigator';
8-
import { useSelector } from '../react-redux';
8+
import { useGlobalSelector, useSelector } from '../react-redux';
99
import { getAuth, getSettings } from '../selectors';
1010
import SwitchRow from '../common/SwitchRow';
1111
import * as api from '../api';
1212
import NavRow from '../common/NavRow';
1313
import { IconAlertTriangle } from '../common/Icons';
1414
import { kWarningColor } from '../styles/constants';
1515
import { getIdentity } from '../account/accountsSelectors';
16-
import { getRealmName } from '../directSelectors';
16+
import { getGlobalSettings, getRealm, getRealmName } from '../directSelectors';
1717
import ZulipText from '../common/ZulipText';
1818
import SettingsGroup from './SettingsGroup';
19+
import { openLinkWithUserPreference } from '../utils/openLink';
1920
import { useNotificationReportsByIdentityKey } from './NotifTroubleshootingScreen';
2021
import { keyOfIdentity } from '../account/accountMisc';
22+
import { getOwnUserRole, roleIsAtLeast } from '../permissionSelectors';
23+
import { Role } from '../api/permissionsTypes';
2124

2225
type Props = $ReadOnly<{|
2326
navigation: AppNavigationMethods,
@@ -38,10 +41,14 @@ export default function PerAccountNotificationSettingsGroup(props: Props): Node
3841
'NotificationsScreen: expected notificationReport for current account',
3942
);
4043
const realmName = useSelector(getRealmName);
44+
const pushNotificationsEnabled = useSelector(state => getRealm(state).pushNotificationsEnabled);
45+
const isAtLeastAdmin = useSelector(state => roleIsAtLeast(getOwnUserRole(state), Role.Admin));
4146
const offlineNotification = useSelector(state => getSettings(state).offlineNotification);
4247
const onlineNotification = useSelector(state => getSettings(state).onlineNotification);
4348
const streamNotification = useSelector(state => getSettings(state).streamNotification);
4449

50+
const globalSettings = useGlobalSelector(getGlobalSettings);
51+
4552
const handleTroubleshootingPress = useCallback(() => {
4653
navigation.push('notif-troubleshooting');
4754
}, [navigation]);
@@ -73,44 +80,76 @@ export default function PerAccountNotificationSettingsGroup(props: Props): Node
7380
});
7481
}, [streamNotification, auth]);
7582

76-
return (
77-
<SettingsGroup
78-
title={{
79-
text: 'Notification settings for this account ({email} in {realmName}):',
80-
values: {
81-
email: <ZulipText style={{ fontWeight: 'bold' }} text={identity.email} />,
82-
realmName: <ZulipText style={{ fontWeight: 'bold' }} text={realmName} />,
83-
},
84-
}}
85-
>
83+
const children = pushNotificationsEnabled
84+
? [
8685
<SwitchRow
86+
key="offlineNotification"
8787
label="Notifications when offline"
8888
value={offlineNotification}
8989
onValueChange={handleOfflineNotificationChange}
90-
/>
90+
/>,
9191
<SwitchRow
92+
key="onlineNotification"
9293
label="Notifications when online"
9394
value={onlineNotification}
9495
onValueChange={handleOnlineNotificationChange}
95-
/>
96+
/>,
9697
<SwitchRow
98+
key="streamNotification"
9799
label="Stream notifications"
98100
value={streamNotification}
99101
onValueChange={handleStreamNotificationChange}
100-
/>
102+
/>,
101103
<NavRow
104+
key="troubleshooting"
102105
{...(() =>
103-
notificationReport.problems.length > 0 && {
104-
leftElement: {
105-
type: 'icon',
106-
Component: IconAlertTriangle,
107-
color: kWarningColor,
108-
},
109-
subtitle: 'Notifications for this account may not arrive.',
110-
})()}
106+
notificationReport.problems.length > 0 && {
107+
leftElement: {
108+
type: 'icon',
109+
Component: IconAlertTriangle,
110+
color: kWarningColor,
111+
},
112+
subtitle: 'Notifications for this account may not arrive.',
113+
})()}
111114
title="Troubleshooting"
112115
onPress={handleTroubleshootingPress}
113-
/>
116+
/>,
117+
]
118+
: [
119+
<NavRow
120+
key="not-enabled"
121+
type="external"
122+
leftElement={{ type: 'icon', Component: IconAlertTriangle, color: kWarningColor }}
123+
title={{
124+
text: isAtLeastAdmin
125+
? '{realmName} is not set up to deliver push notifications.'
126+
: '{realmName} is not set up to deliver push notifications. Please contact your administrator.',
127+
values: {
128+
realmName: <ZulipText style={{ fontWeight: 'bold' }} text={realmName} />,
129+
},
130+
}}
131+
onPress={() => {
132+
openLinkWithUserPreference(
133+
new URL(
134+
'https://zulip.readthedocs.io/en/stable/production/mobile-push-notifications.html',
135+
),
136+
globalSettings,
137+
);
138+
}}
139+
/>,
140+
];
141+
142+
return (
143+
<SettingsGroup
144+
title={{
145+
text: 'Notification settings for this account ({email} in {realmName}):',
146+
values: {
147+
email: <ZulipText style={{ fontWeight: 'bold' }} text={identity.email} />,
148+
realmName: <ZulipText style={{ fontWeight: 'bold' }} text={realmName} />,
149+
},
150+
}}
151+
>
152+
{children}
114153
</SettingsGroup>
115154
);
116155
}

static/translations/messages_en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@
253253
"Notifications are disabled.": "Notifications are disabled.",
254254
"Multiple issues. Tap to learn more.": "Multiple issues. Tap to learn more.",
255255
"Notification settings for this account ({email} in {realmName}):": "Notification settings for this account ({email} in {realmName}):",
256+
"{realmName} is not set up to deliver push notifications. Please contact your administrator.": "{realmName} is not set up to deliver push notifications. Please contact your administrator.",
257+
"{realmName} is not set up to deliver push notifications.": "{realmName} is not set up to deliver push notifications.",
256258
"Other accounts": "Other accounts",
257259
"Notifications when online": "Notifications when online",
258260
"Notifications when offline": "Notifications when offline",

0 commit comments

Comments
 (0)