|
| 1 | +/* @flow strict-local */ |
| 2 | + |
| 3 | +import React, { useContext } from 'react'; |
| 4 | +import { View, Pressable } from 'react-native'; |
| 5 | +import Color from 'color'; |
| 6 | +import { SafeAreaView } from 'react-native-safe-area-context'; |
| 7 | + |
| 8 | +import { createStyleSheet, HALF_COLOR, ThemeContext } from '../styles'; |
| 9 | +import { useSelector, useDispatch } from '../react-redux'; |
| 10 | +import Label from './Label'; |
| 11 | +import RawLabel from './RawLabel'; |
| 12 | +import { Icon } from './Icons'; |
| 13 | +import { getActiveAccount } from '../account/accountsSelectors'; |
| 14 | +import WebLink from './WebLink'; |
| 15 | +import { getIsAdmin, getSession } from '../directSelectors'; |
| 16 | +import { dismissCompatNotice } from '../session/sessionActions'; |
| 17 | + |
| 18 | +const styles = createStyleSheet({ |
| 19 | + wrapper: { |
| 20 | + flexDirection: 'row', |
| 21 | + justifyContent: 'flex-start', |
| 22 | + alignItems: 'center', |
| 23 | + backgroundColor: HALF_COLOR, |
| 24 | + }, |
| 25 | +}); |
| 26 | + |
| 27 | +type Props = $ReadOnly<{||}>; |
| 28 | + |
| 29 | +/** |
| 30 | + * A "nag banner" saying that the server version is unsupported. |
| 31 | + * |
| 32 | + * Currently just checks if it's less than 2.1.0, since that's the |
| 33 | + * marker that was put down in zulip/zulip@d7d79b57b. In the future, |
| 34 | + * this won't have to be so hard-coded; we may use a timer or |
| 35 | + * something. |
| 36 | + */ |
| 37 | +export default function ServerCompatNotice(props: Props) { |
| 38 | + const dispatch = useDispatch(); |
| 39 | + const hasDismissedServerCompatNotice = useSelector( |
| 40 | + state => getSession(state).hasDismissedServerCompatNotice, |
| 41 | + ); |
| 42 | + const zulipVersion = useSelector(state => getActiveAccount(state).zulipVersion); |
| 43 | + const realm = useSelector(state => getActiveAccount(state).realm); |
| 44 | + const isAdmin = useSelector(getIsAdmin); |
| 45 | + |
| 46 | + const { color } = useContext(ThemeContext); |
| 47 | + |
| 48 | + if (zulipVersion && !zulipVersion.isAtLeast('2.1.0') && !hasDismissedServerCompatNotice) { |
| 49 | + return ( |
| 50 | + <SafeAreaView mode="padding" edges={['right', 'left']} style={styles.wrapper}> |
| 51 | + <Pressable |
| 52 | + onPress={() => { |
| 53 | + dispatch(dismissCompatNotice()); |
| 54 | + }} |
| 55 | + hitSlop={12} |
| 56 | + style={{ margin: 12 }} |
| 57 | + > |
| 58 | + {({ pressed }) => ( |
| 59 | + <Icon |
| 60 | + size={24} |
| 61 | + color={Color(color) |
| 62 | + .fade(pressed ? 0.75 : 0) |
| 63 | + .toString()} |
| 64 | + name="x" |
| 65 | + /> |
| 66 | + )} |
| 67 | + </Pressable> |
| 68 | + <View style={{ flex: 1, paddingVertical: 4, paddingRight: 4 }}> |
| 69 | + <RawLabel> |
| 70 | + {isAdmin ? ( |
| 71 | + <Label |
| 72 | + text={{ |
| 73 | + text: |
| 74 | + '{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. We work hard to make the upgrade process as easy as possible.', |
| 75 | + values: { realm: realm.toString(), serverVersionRaw: zulipVersion.raw() }, |
| 76 | + }} |
| 77 | + /> |
| 78 | + ) : ( |
| 79 | + <Label |
| 80 | + text={{ |
| 81 | + text: |
| 82 | + '{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. Please contact your administrator about upgrading.', |
| 83 | + values: { realm: realm.toString(), serverVersionRaw: zulipVersion.raw() }, |
| 84 | + }} |
| 85 | + /> |
| 86 | + )} |
| 87 | + {' '} |
| 88 | + <WebLink |
| 89 | + label="Learn more" |
| 90 | + url={ |
| 91 | + new URL( |
| 92 | + 'https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading', |
| 93 | + ) |
| 94 | + } |
| 95 | + /> |
| 96 | + </RawLabel> |
| 97 | + </View> |
| 98 | + </SafeAreaView> |
| 99 | + ); |
| 100 | + } else { |
| 101 | + return null; |
| 102 | + } |
| 103 | +} |
0 commit comments