@planningcenter/chat-react-native 4.9.1 → 4.9.2-qa-staging.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/build/components/display/version_footer.d.ts.map +1 -1
  2. package/build/components/display/version_footer.js +12 -7
  3. package/build/components/display/version_footer.js.map +1 -1
  4. package/build/contexts/session_context.d.ts.map +1 -1
  5. package/build/contexts/session_context.js +118 -115
  6. package/build/contexts/session_context.js.map +1 -1
  7. package/build/navigation/index.d.ts +9 -0
  8. package/build/navigation/index.d.ts.map +1 -1
  9. package/build/navigation/index.js +11 -0
  10. package/build/navigation/index.js.map +1 -1
  11. package/build/screens/settings_screen.d.ts.map +1 -1
  12. package/build/screens/settings_screen.js +101 -73
  13. package/build/screens/settings_screen.js.map +1 -1
  14. package/build/screens/update_channel_screen.d.ts +4 -0
  15. package/build/screens/update_channel_screen.d.ts.map +1 -0
  16. package/build/screens/update_channel_screen.js +370 -0
  17. package/build/screens/update_channel_screen.js.map +1 -0
  18. package/build/utils/native_adapters/updates.d.ts +19 -0
  19. package/build/utils/native_adapters/updates.d.ts.map +1 -1
  20. package/build/utils/native_adapters/updates.js +5 -0
  21. package/build/utils/native_adapters/updates.js.map +1 -1
  22. package/package.json +3 -3
  23. package/src/__tests__/contexts/session_context.tsx +11 -7
  24. package/src/__tests__/screens/settings_screen.test.tsx +21 -0
  25. package/src/components/display/version_footer.tsx +5 -0
  26. package/src/contexts/session_context.tsx +11 -13
  27. package/src/navigation/index.tsx +9 -0
  28. package/src/screens/settings_screen.tsx +10 -0
  29. package/src/screens/update_channel_screen.tsx +150 -0
  30. package/src/utils/native_adapters/updates.ts +16 -0
@@ -87,6 +87,7 @@ import {
87
87
  SystemMessagePeopleScreenOptions,
88
88
  } from '../screens/system_message_people_screen'
89
89
  import { TeamConversationScreen } from '../screens/team_conversation_screen'
90
+ import { UpdateChannelScreen } from '../screens/update_channel_screen'
90
91
  import { isLiquidGlassEnabled } from '../utils/liquid_glass'
91
92
  import { ScreenLayoutWithChatAccessGate } from './screenLayout'
92
93
 
@@ -286,6 +287,14 @@ export const ChatStack = createNativeStackNavigator({
286
287
  withMinimalBack({ onPress: navigation.goBack })
287
288
  ),
288
289
  },
290
+ UpdateChannel: {
291
+ screen: UpdateChannelScreen,
292
+ options: ({ navigation }) =>
293
+ composeOptions(
294
+ { title: 'Update channel' },
295
+ withMinimalBack({ onPress: navigation.goBack })
296
+ ),
297
+ },
289
298
  PreferredAppSelection: {
290
299
  screen: PreferredAppSelectionScreen,
291
300
  options: ({ navigation }) =>
@@ -8,6 +8,7 @@ import { Switch } from '../components/display/switch'
8
8
  import { useTheme } from '../hooks'
9
9
  import { useAppName } from '../hooks/use_app_name'
10
10
  import { usePersonSettings } from '../hooks/use_person_settings'
11
+ import { Updates } from '../utils/native_adapters'
11
12
 
12
13
  export type SettingsScreenProps = StaticScreenProps<{}>
13
14
 
@@ -17,11 +18,19 @@ export function SettingsScreen({}: SettingsScreenProps) {
17
18
  usePersonSettings()
18
19
  const appName = useAppName()
19
20
  const navigation = useNavigation()
21
+ const canSwitchChannel = Updates.useCanSwitchChannel()
22
+ const updateChannel = Updates.useChannel()
23
+ const showsUpdateChannel =
24
+ canSwitchChannel && updateChannel !== undefined && updateChannel.embedded !== 'production'
20
25
 
21
26
  const handleNotificationSettings = useCallback(() => {
22
27
  navigation.navigate('NotificationSettings', {})
23
28
  }, [navigation])
24
29
 
30
+ const handleUpdateChannel = useCallback(() => {
31
+ navigation.navigate('UpdateChannel', {})
32
+ }, [navigation])
33
+
25
34
  const handleGetHelp = useCallback(() => {
26
35
  navigation.navigate('GetHelp', { type: 'chat' })
27
36
  }, [navigation])
@@ -51,6 +60,7 @@ export function SettingsScreen({}: SettingsScreenProps) {
51
60
  )}
52
61
  <NavRow label="Notification settings" onPress={handleNotificationSettings} />
53
62
  {appName !== 'services' && <NavRow label="Get help" onPress={handleGetHelp} />}
63
+ {showsUpdateChannel && <NavRow label="Update channel" onPress={handleUpdateChannel} />}
54
64
  </View>
55
65
  </ScrollView>
56
66
  <View style={styles.footer}>
@@ -0,0 +1,150 @@
1
+ import { StaticScreenProps } from '@react-navigation/native'
2
+ import { useMutation } from '@tanstack/react-query'
3
+ import React, { useState } from 'react'
4
+ import { Keyboard, ScrollView, StyleSheet, TextInput, View } from 'react-native'
5
+ import { Button, Heading, Text } from '../components'
6
+ import { PressableRow } from '../components/display/pressable_row'
7
+ import { TextButton } from '../components/display/text_button'
8
+ import { useTheme } from '../hooks'
9
+ import dayjs from '../utils/dayjs'
10
+ import { ChannelCheck, Updates } from '../utils/native_adapters'
11
+
12
+ export type UpdateChannelScreenProps = StaticScreenProps<{}>
13
+
14
+ const PRESET_CHANNELS = ['chat-staging', 'production']
15
+ const CHANNEL_NAME = /^[a-z0-9-]+$/
16
+
17
+ export function UpdateChannelScreen({}: UpdateChannelScreenProps) {
18
+ const styles = useStyles()
19
+ const { colors } = useTheme()
20
+ const channel = Updates.useChannel()
21
+ const [customChannel, setCustomChannel] = useState('')
22
+
23
+ const { mutate, variables, data, error, isPending } = useMutation({
24
+ mutationFn: (name: string | null) => Updates.setChannel(name),
25
+ })
26
+
27
+ const active = channel?.active
28
+ const channels =
29
+ active && !PRESET_CHANNELS.includes(active) ? [...PRESET_CHANNELS, active] : PRESET_CHANNELS
30
+ const isCustomValid = CHANNEL_NAME.test(customChannel)
31
+ const checkedChannel = variables === null ? channel?.embedded : variables
32
+
33
+ const switchToCustom = () => {
34
+ Keyboard.dismiss()
35
+ mutate(customChannel)
36
+ setCustomChannel('')
37
+ }
38
+
39
+ return (
40
+ <ScrollView contentInsetAdjustmentBehavior="automatic" keyboardShouldPersistTaps="handled">
41
+ <View style={styles.sectionHeader}>
42
+ <Heading variant="h2">Channel</Heading>
43
+ {channel && <Text variant="tertiary">This build's channel is {channel.embedded}.</Text>}
44
+ </View>
45
+ {channels.map(name => (
46
+ <PressableRow
47
+ key={name}
48
+ text={name}
49
+ isActive={name === active}
50
+ iconColor={colors.statusSuccessIcon}
51
+ onPress={() => mutate(name)}
52
+ />
53
+ ))}
54
+ <View style={styles.custom}>
55
+ <TextInput
56
+ style={styles.input}
57
+ value={customChannel}
58
+ onChangeText={setCustomChannel}
59
+ placeholder="pr-1234"
60
+ placeholderTextColor={colors.textColorDefaultPlaceholder}
61
+ autoCapitalize="none"
62
+ autoCorrect={false}
63
+ returnKeyType="go"
64
+ onSubmitEditing={() => isCustomValid && switchToCustom()}
65
+ accessibilityLabel="Custom channel"
66
+ />
67
+ <Button
68
+ title="Switch"
69
+ variant="outline"
70
+ disabled={!isCustomValid || isPending}
71
+ onPress={switchToCustom}
72
+ />
73
+ </View>
74
+ {channel && channel.active !== channel.embedded && (
75
+ <View style={styles.reset}>
76
+ <TextButton disabled={isPending} onPress={() => mutate(null)}>
77
+ Reset to {channel.embedded}
78
+ </TextButton>
79
+ </View>
80
+ )}
81
+ <View style={styles.result}>
82
+ {isPending && <Text variant="tertiary">Checking {checkedChannel}…</Text>}
83
+ {!isPending && error && <Text style={styles.error}>{error.message}</Text>}
84
+ {!isPending && data && checkedChannel && active && (
85
+ <Text variant="tertiary">{describeCheck(data, checkedChannel, active)}</Text>
86
+ )}
87
+ </View>
88
+ </ScrollView>
89
+ )
90
+ }
91
+
92
+ const describeCheck = (check: ChannelCheck, checkedChannel: string, activeChannel: string) => {
93
+ const stillOn = `Still on ${activeChannel}.`
94
+
95
+ switch (check.status) {
96
+ case 'available': {
97
+ const published = check.createdAt ? `, published ${dayjs(check.createdAt).fromNow()}` : ''
98
+ return `Found update ${check.updateId.slice(0, 8)} on ${checkedChannel}${published}. Chat offers a restart once it downloads.`
99
+ }
100
+ case 'not-newer':
101
+ return checkedChannel === activeChannel
102
+ ? `Back on ${checkedChannel}. Its latest update is older than the one running, so its next one will load.`
103
+ : `${checkedChannel}'s latest update isn't newer than the one running. ${stillOn}`
104
+ case 'no-update':
105
+ return checkedChannel === activeChannel
106
+ ? `Back on ${checkedChannel}. It has no update for this build yet.`
107
+ : `No update on ${checkedChannel} for this build. ${stillOn}`
108
+ }
109
+ }
110
+
111
+ const useStyles = () => {
112
+ const { colors } = useTheme()
113
+ return StyleSheet.create({
114
+ sectionHeader: {
115
+ gap: 4,
116
+ paddingHorizontal: 16,
117
+ paddingTop: 24,
118
+ paddingBottom: 12,
119
+ },
120
+ custom: {
121
+ flexDirection: 'row',
122
+ alignItems: 'center',
123
+ gap: 12,
124
+ paddingHorizontal: 16,
125
+ paddingTop: 16,
126
+ },
127
+ input: {
128
+ flex: 1,
129
+ color: colors.textColorDefaultPrimary,
130
+ fontSize: 16,
131
+ borderWidth: 1,
132
+ borderColor: colors.borderColorDefaultBase,
133
+ borderRadius: 8,
134
+ paddingHorizontal: 12,
135
+ paddingVertical: 10,
136
+ },
137
+ reset: {
138
+ alignItems: 'flex-start',
139
+ paddingHorizontal: 16,
140
+ paddingTop: 16,
141
+ },
142
+ result: {
143
+ paddingHorizontal: 16,
144
+ paddingVertical: 16,
145
+ },
146
+ error: {
147
+ color: colors.statusErrorText,
148
+ },
149
+ })
150
+ }
@@ -1,16 +1,32 @@
1
1
  import { noop } from 'lodash'
2
2
 
3
+ export type UpdateChannel = { active: string; embedded: string }
4
+
5
+ export type ChannelCheck =
6
+ | { status: 'available'; updateId: string; createdAt?: Date }
7
+ | { status: 'no-update' }
8
+ | { status: 'not-newer' }
9
+
3
10
  interface Updates {
4
11
  useDownloadedUpdateId: () => string | undefined
5
12
  restart: () => void
13
+ useCanSwitchChannel?: () => boolean
14
+ useChannel?: () => UpdateChannel | undefined
15
+ setChannel?: (name: string | null) => Promise<ChannelCheck>
6
16
  }
7
17
 
8
18
  export class UpdatesAdapter {
9
19
  useDownloadedUpdateId: () => string | undefined
10
20
  restart: () => void
21
+ useCanSwitchChannel: () => boolean
22
+ useChannel: () => UpdateChannel | undefined
23
+ setChannel: (name: string | null) => Promise<ChannelCheck>
11
24
 
12
25
  constructor(methods?: Updates) {
13
26
  this.useDownloadedUpdateId = methods?.useDownloadedUpdateId ?? (() => undefined)
14
27
  this.restart = methods?.restart ?? noop
28
+ this.useCanSwitchChannel = methods?.useCanSwitchChannel ?? (() => false)
29
+ this.useChannel = methods?.useChannel ?? (() => undefined)
30
+ this.setChannel = methods?.setChannel ?? (async () => ({ status: 'no-update' }))
15
31
  }
16
32
  }