@planningcenter/chat-react-native 4.8.0-rc.4 → 4.8.0-rc.5

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 (46) hide show
  1. package/build/components/conversations/conversation_actions.d.ts +2 -1
  2. package/build/components/conversations/conversation_actions.d.ts.map +1 -1
  3. package/build/components/conversations/conversation_actions.js +137 -99
  4. package/build/components/conversations/conversation_actions.js.map +1 -1
  5. package/build/components/conversations/conversation_preview.d.ts.map +1 -1
  6. package/build/components/conversations/conversation_preview.js +154 -110
  7. package/build/components/conversations/conversation_preview.js.map +1 -1
  8. package/build/components/conversations/conversations.d.ts.map +1 -1
  9. package/build/components/conversations/conversations.js +50 -48
  10. package/build/components/conversations/conversations.js.map +1 -1
  11. package/build/components/display/checkbox.d.ts +8 -0
  12. package/build/components/display/checkbox.d.ts.map +1 -0
  13. package/build/components/display/checkbox.js +87 -0
  14. package/build/components/display/checkbox.js.map +1 -0
  15. package/build/components/display/index.d.ts +1 -0
  16. package/build/components/display/index.d.ts.map +1 -1
  17. package/build/components/display/index.js +1 -0
  18. package/build/components/display/index.js.map +1 -1
  19. package/build/contexts/conversations_context.d.ts +5 -0
  20. package/build/contexts/conversations_context.d.ts.map +1 -1
  21. package/build/contexts/conversations_context.js +121 -32
  22. package/build/contexts/conversations_context.js.map +1 -1
  23. package/build/navigation/index.d.ts.map +1 -1
  24. package/build/navigation/index.js +5 -7
  25. package/build/navigation/index.js.map +1 -1
  26. package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
  27. package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
  28. package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
  29. package/build/screens/conversations/conversations_screen.d.ts +4 -0
  30. package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
  31. package/build/screens/conversations/conversations_screen.js +102 -31
  32. package/build/screens/conversations/conversations_screen.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/components/conversations/__tests__/conversation_actions.test.tsx +30 -2
  35. package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
  36. package/src/components/conversations/conversation_actions.tsx +13 -6
  37. package/src/components/conversations/conversation_preview.tsx +12 -1
  38. package/src/components/conversations/conversations.tsx +2 -1
  39. package/src/components/display/checkbox.tsx +47 -0
  40. package/src/components/display/index.ts +1 -0
  41. package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
  42. package/src/contexts/conversations_context.tsx +69 -2
  43. package/src/navigation/index.tsx +8 -8
  44. package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
  45. package/src/screens/conversations/__tests__/conversations_screen.test.tsx +5 -0
  46. package/src/screens/conversations/conversations_screen.tsx +49 -3
@@ -1,3 +1,4 @@
1
+ import { fireEvent } from '@testing-library/react-native'
1
2
  import React from 'react'
2
3
  import { renderWithQueryClient } from '../../../__utils__/render_with_query_client'
3
4
  import { ConversationFiltersParams } from '../../../screens/conversation_filters/screen_props'
@@ -6,19 +7,40 @@ import { formatDatePreview } from '../../../utils/date'
6
7
  import { ConversationPreview } from '../conversation_preview'
7
8
 
8
9
  let mockArgs: ConversationFiltersParams = {}
10
+ let mockSelectMode = false
11
+ let mockSelectedIds: number[] = []
12
+ const mockToggleSelected = jest.fn()
9
13
  jest.mock('../../../contexts/conversations_context', () => ({
10
- useConversationsContext: () => ({ args: mockArgs }),
14
+ useConversationsContext: () => ({
15
+ args: mockArgs,
16
+ selectMode: mockSelectMode,
17
+ selectedIds: mockSelectedIds,
18
+ toggleSelected: mockToggleSelected,
19
+ }),
11
20
  }))
12
21
  jest.mock('../conversation_actions', () => ({
13
22
  ConversationActions: ({
14
23
  children,
15
24
  accessibilityLabel,
25
+ onPress,
26
+ selected,
16
27
  }: {
17
28
  children: React.ReactNode
18
29
  accessibilityLabel?: string
30
+ onPress: () => void
31
+ selected?: boolean
19
32
  }) => {
20
- const { View: MockView } = jest.requireActual('react-native')
21
- return <MockView accessibilityLabel={accessibilityLabel}>{children}</MockView>
33
+ const { Pressable: MockPressable } = jest.requireActual('react-native')
34
+ return (
35
+ <MockPressable
36
+ accessibilityLabel={accessibilityLabel}
37
+ accessibilityRole="checkbox"
38
+ accessibilityState={{ checked: selected }}
39
+ onPress={onPress}
40
+ >
41
+ {children}
42
+ </MockPressable>
43
+ )
22
44
  },
23
45
  }))
24
46
 
@@ -131,4 +153,48 @@ describe('ConversationPreview', () => {
131
153
  ).toBeNull()
132
154
  })
133
155
  })
156
+
157
+ describe('select mode', () => {
158
+ const onPress = jest.fn()
159
+ const renderSelectable = () =>
160
+ renderWithQueryClient(
161
+ <ConversationPreview conversation={conversation(messagePreview)} onPress={onPress} />
162
+ )
163
+
164
+ beforeEach(() => {
165
+ mockSelectMode = true
166
+ mockSelectedIds = []
167
+ jest.clearAllMocks()
168
+ })
169
+
170
+ afterAll(() => {
171
+ mockSelectMode = false
172
+ })
173
+
174
+ it('toggles the conversation instead of opening it', () => {
175
+ const view = renderSelectable()
176
+
177
+ fireEvent.press(view.getByText('Worship Team'))
178
+
179
+ expect(mockToggleSelected).toHaveBeenCalledWith(7)
180
+ expect(onPress).not.toHaveBeenCalled()
181
+ })
182
+
183
+ it('marks a selected conversation as checked', () => {
184
+ mockSelectedIds = [7]
185
+ const view = renderSelectable()
186
+
187
+ expect(view.getByRole('checkbox', { checked: true })).toBeTruthy()
188
+ })
189
+
190
+ it('opens the conversation outside select mode', () => {
191
+ mockSelectMode = false
192
+ const view = renderSelectable()
193
+
194
+ fireEvent.press(view.getByText('Worship Team'))
195
+
196
+ expect(onPress).toHaveBeenCalled()
197
+ expect(mockToggleSelected).not.toHaveBeenCalled()
198
+ })
199
+ })
134
200
  })
@@ -32,12 +32,14 @@ export function ConversationActions({
32
32
  style,
33
33
  onPress,
34
34
  accessibilityLabel,
35
+ selected,
35
36
  }: {
36
37
  children: ReactNode
37
38
  conversation: ConversationResource
38
39
  onPress: () => void
39
40
  style?: StyleProp<ViewStyle>
40
41
  accessibilityLabel?: string
42
+ selected?: boolean
41
43
  }) {
42
44
  const swipeableRef = useRef<SwipeableMethods>(null)
43
45
  const navigation = useNavigation()
@@ -67,6 +69,7 @@ export function ConversationActions({
67
69
  const isConversationEmpty = conversation.lastMessageCreatedAt === null
68
70
  const canMute = !isArchivedConversation(conversation)
69
71
  const canHide = hideable && hideConversationsEnabled && !isArchivedConversation(conversation)
72
+ const selectMode = selected !== undefined
70
73
 
71
74
  const handleSwipeableClose = useCallback(() => {
72
75
  setDisabled(false)
@@ -132,11 +135,9 @@ export function ConversationActions({
132
135
  ]
133
136
  : []
134
137
 
135
- const accessibilityActions = [
136
- ...muteAccessibilityAction,
137
- ...hideAccessibilityAction,
138
- ...readAccessibilityAction,
139
- ]
138
+ const accessibilityActions = selectMode
139
+ ? []
140
+ : [...muteAccessibilityAction, ...hideAccessibilityAction, ...readAccessibilityAction]
140
141
 
141
142
  const handleAccessibilityAction = useCallback(
142
143
  (event: AccessibilityActionEvent) => {
@@ -162,6 +163,10 @@ export function ConversationActions({
162
163
  [handleLatestMessageUnread, handleMute, handleHide]
163
164
  )
164
165
 
166
+ useEffect(() => {
167
+ if (selectMode) handleSwipeableClose()
168
+ }, [selectMode, handleSwipeableClose])
169
+
165
170
  useEffect(() => {
166
171
  if (activeConversationId === conversation.id) return
167
172
 
@@ -171,6 +176,7 @@ export function ConversationActions({
171
176
  return (
172
177
  <ReanimatedSwipeable
173
178
  ref={swipeableRef}
179
+ enabled={!selectMode}
174
180
  childrenContainerStyle={styles.swipeableChildContainer}
175
181
  containerStyle={styles.swipeableContainer}
176
182
  overshootFriction={8}
@@ -203,7 +209,8 @@ export function ConversationActions({
203
209
  style={({ pressed }) => [style, pressed && platformPressedOpacityStyle]}
204
210
  android_ripple={{ color: androidRippleColor, borderless: false, foreground: true }}
205
211
  accessibilityLabel={accessibilityLabel}
206
- accessibilityRole="button"
212
+ accessibilityRole={selectMode ? 'checkbox' : 'button'}
213
+ accessibilityState={selectMode ? { checked: selected } : undefined}
207
214
  accessibilityActions={accessibilityActions}
208
215
  onAccessibilityAction={handleAccessibilityAction}
209
216
  >
@@ -19,6 +19,7 @@ import {
19
19
  IconTile,
20
20
  Text,
21
21
  Badge,
22
+ Checkbox,
22
23
  type BadgeProps,
23
24
  } from '../display'
24
25
  import { ConversationActions } from './conversation_actions'
@@ -44,8 +45,12 @@ export const ConversationPreview = ({
44
45
  const styles = useStyles()
45
46
  const {
46
47
  args: { show_hidden: hidden = false },
48
+ selectMode,
49
+ selectedIds,
50
+ toggleSelected,
47
51
  } = useConversationsContext()
48
52
  const {
53
+ id,
49
54
  conversationPreview,
50
55
  lastMessageCreatedAt,
51
56
  title,
@@ -61,6 +66,7 @@ export const ConversationPreview = ({
61
66
  const fallbackIconName = emptyConversation ? 'people.noTextMessage' : 'general.person'
62
67
  const hasMetaContent = lastMessageCreatedAt || unreadCount > 0 || muted || hidden
63
68
  const isUnread = unreadCount > 0 || unreadReaction
69
+ const selected = selectMode ? selectedIds.includes(id) : undefined
64
70
 
65
71
  const numberOfLinesScaledTitle = useScalableNumberOfLines(1)
66
72
  const numberOfLinesScaledPreviewText = useScalableNumberOfLines(2)
@@ -80,9 +86,11 @@ export const ConversationPreview = ({
80
86
  <ConversationActions
81
87
  conversation={conversation}
82
88
  style={[styles.previewRow, disabled && !archived && styles.disabled, style]}
83
- onPress={onPress}
89
+ onPress={selectMode ? () => toggleSelected(id) : onPress}
84
90
  accessibilityLabel={conversationAccessibilityLabel}
91
+ selected={selected}
85
92
  >
93
+ {selected !== undefined && <Checkbox checked={selected} style={styles.checkbox} />}
86
94
  {archived ? (
87
95
  <IconTile
88
96
  icon={faBoxArchive}
@@ -284,6 +292,9 @@ const useStyles = () => {
284
292
  disabled: {
285
293
  opacity: 0.4,
286
294
  },
295
+ checkbox: {
296
+ alignSelf: 'center',
297
+ },
287
298
  title: {
288
299
  fontSize: 16,
289
300
  color: colors.textColorDefaultPrimary,
@@ -32,6 +32,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
32
32
  isRefetching,
33
33
  isFetched,
34
34
  hasNextPage,
35
+ selectMode,
35
36
  args: {
36
37
  chat_group_graph_id,
37
38
  group_source_app_name,
@@ -88,7 +89,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
88
89
  contentInsetAdjustmentBehavior="automatic"
89
90
  onRefresh={refetch}
90
91
  refreshing={!isFetched && isRefetching}
91
- ListHeaderComponent={ListHeaderComponent}
92
+ ListHeaderComponent={selectMode ? null : ListHeaderComponent}
92
93
  ListEmptyComponent={
93
94
  <ConversationsBlankState
94
95
  isFilterApplied={isFilterApplied}
@@ -0,0 +1,47 @@
1
+ import React from 'react'
2
+ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
3
+ import { useTheme } from '../../hooks'
4
+ import { tokens } from '../../vendor/tapestry/tokens'
5
+ import { Icon } from './icon'
6
+
7
+ interface CheckboxProps {
8
+ checked: boolean
9
+ style?: StyleProp<ViewStyle>
10
+ }
11
+
12
+ export function Checkbox({ checked, style }: CheckboxProps) {
13
+ const styles = useStyles()
14
+
15
+ return (
16
+ <View style={[checked ? styles.checkedContainer : styles.uncheckedContainer, style]}>
17
+ {checked && <Icon name="general.thickCheckmark" style={styles.checkedIcon} />}
18
+ </View>
19
+ )
20
+ }
21
+
22
+ const useStyles = () => {
23
+ const { colors } = useTheme()
24
+
25
+ const baseCheckboxStyles: ViewStyle = {
26
+ width: 20,
27
+ height: 20,
28
+ borderRadius: 40,
29
+ alignItems: 'center',
30
+ justifyContent: 'center',
31
+ }
32
+
33
+ return StyleSheet.create({
34
+ checkedContainer: {
35
+ ...baseCheckboxStyles,
36
+ backgroundColor: colors.statusSuccessIcon,
37
+ },
38
+ uncheckedContainer: {
39
+ ...baseCheckboxStyles,
40
+ borderWidth: 2,
41
+ borderColor: colors.borderColorDefaultDarker,
42
+ },
43
+ checkedIcon: {
44
+ color: tokens.colorNeutral100White,
45
+ },
46
+ })
47
+ }
@@ -8,6 +8,7 @@ export * from './icon_tile'
8
8
  export * from './banner_collapsible'
9
9
  export * from './banner'
10
10
  export * from './button'
11
+ export * from './checkbox'
11
12
  export * from './adult_requirement_notice'
12
13
  export * from './child_notice'
13
14
  export * from './heading'
@@ -0,0 +1,86 @@
1
+ import { act, renderHook } from '@testing-library/react-native'
2
+ import React from 'react'
3
+ import { ConversationFiltersParams } from '../../screens/conversation_filters/screen_props'
4
+ import { ConversationsContextProvider, useConversationsContext } from '../conversations_context'
5
+
6
+ let mockHideEnabled = true
7
+ jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
8
+ useHideConversationsEnabled: () => mockHideEnabled,
9
+ }))
10
+ jest.mock('../../hooks/use_conversations', () => ({
11
+ useConversations: () => ({ conversations: [] }),
12
+ }))
13
+
14
+ let mockArgs: ConversationFiltersParams = {}
15
+
16
+ const renderContext = () =>
17
+ renderHook(() => useConversationsContext(), {
18
+ wrapper: ({ children }: { children: React.ReactNode }) => (
19
+ <ConversationsContextProvider args={mockArgs}>{children}</ConversationsContextProvider>
20
+ ),
21
+ })
22
+
23
+ describe('ConversationsContextProvider selection', () => {
24
+ beforeEach(() => {
25
+ mockHideEnabled = true
26
+ mockArgs = {}
27
+ })
28
+
29
+ it('toggles conversations in and out of the selection', () => {
30
+ const { result } = renderContext()
31
+
32
+ act(() => result.current.enterSelectMode(1))
33
+ act(() => result.current.toggleSelected(2))
34
+
35
+ expect(result.current.selectMode).toBe(true)
36
+ expect(result.current.selectedIds).toEqual([1, 2])
37
+
38
+ act(() => result.current.toggleSelected(1))
39
+
40
+ expect(result.current.selectedIds).toEqual([2])
41
+ })
42
+
43
+ it('leaves select mode on clear', () => {
44
+ const { result } = renderContext()
45
+
46
+ act(() => result.current.enterSelectMode(1))
47
+ act(() => result.current.clearSelection())
48
+
49
+ expect(result.current.selectMode).toBe(false)
50
+ expect(result.current.selectedIds).toEqual([])
51
+ })
52
+
53
+ it('clears the selection when the filter changes', () => {
54
+ const { result, rerender } = renderContext()
55
+
56
+ act(() => result.current.enterSelectMode(1))
57
+ mockArgs = { show_unread: true }
58
+ rerender({})
59
+
60
+ expect(result.current.selectMode).toBe(false)
61
+ expect(result.current.selectedIds).toEqual([])
62
+ })
63
+
64
+ it('stays out of select mode when the flag is off', () => {
65
+ mockHideEnabled = false
66
+ const { result } = renderContext()
67
+
68
+ act(() => result.current.enterSelectMode(1))
69
+
70
+ expect(result.current.selectMode).toBe(false)
71
+ expect(result.current.selectedIds).toEqual([])
72
+ })
73
+
74
+ it('does not revive the selection when the flag flips off and back on', () => {
75
+ const { result, rerender } = renderContext()
76
+
77
+ act(() => result.current.enterSelectMode(1))
78
+ mockHideEnabled = false
79
+ rerender({})
80
+ mockHideEnabled = true
81
+ rerender({})
82
+
83
+ expect(result.current.selectMode).toBe(false)
84
+ expect(result.current.selectedIds).toEqual([])
85
+ })
86
+ })
@@ -3,9 +3,18 @@ import {
3
3
  InfiniteQueryObserverResult,
4
4
  InfiniteData,
5
5
  } from '@tanstack/react-query'
6
- import React, { createContext, PropsWithChildren, useContext, useMemo, useState } from 'react'
6
+ import React, {
7
+ createContext,
8
+ PropsWithChildren,
9
+ useCallback,
10
+ useContext,
11
+ useEffect,
12
+ useMemo,
13
+ useState,
14
+ } from 'react'
7
15
  import { ApiGetQueryOptions } from '../hooks'
8
16
  import { useConversations, UseConversationsValue } from '../hooks/use_conversations'
17
+ import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
9
18
  import { ConversationFiltersParams } from '../screens/conversation_filters/screen_props'
10
19
  import { ApiCollection, ConversationResource } from '../types'
11
20
  import { ResponseError } from '../utils/response_error'
@@ -15,6 +24,11 @@ interface ConversationsContextValue extends UseConversationsValue {
15
24
  setActiveConversationId: (_id: number) => void
16
25
  args: ConversationFiltersParams
17
26
  hideable: boolean
27
+ selectMode: boolean
28
+ selectedIds: number[]
29
+ enterSelectMode: (_id?: number) => void
30
+ toggleSelected: (_id: number) => void
31
+ clearSelection: () => void
18
32
  }
19
33
 
20
34
  const defaultQueryValue: UseConversationsValue = {
@@ -35,6 +49,11 @@ const ConversationsContext = createContext<ConversationsContextValue>({
35
49
  activeConversationId: undefined,
36
50
  setActiveConversationId: () => {},
37
51
  hideable: true,
52
+ selectMode: false,
53
+ selectedIds: [],
54
+ enterSelectMode: () => {},
55
+ toggleSelected: () => {},
56
+ clearSelection: () => {},
38
57
  ...defaultQueryValue,
39
58
  })
40
59
 
@@ -49,6 +68,10 @@ export const ConversationsContextProvider = ({
49
68
  hideable?: boolean
50
69
  }>) => {
51
70
  const [activeConversationId, setActiveConversationId] = useState<number | undefined>()
71
+ const hideConversationsEnabled = useHideConversationsEnabled()
72
+ const [selecting, setSelecting] = useState(false)
73
+ const [selectedIds, setSelectedIds] = useState<number[]>([])
74
+ const selectMode = hideConversationsEnabled && selecting
52
75
  const {
53
76
  chat_group_graph_id,
54
77
  group_source_app_name,
@@ -70,15 +93,59 @@ export const ConversationsContextProvider = ({
70
93
  paginatorOptions
71
94
  )
72
95
 
96
+ const enterSelectMode = useCallback((id?: number) => {
97
+ setSelecting(true)
98
+ setSelectedIds(id === undefined ? [] : [id])
99
+ }, [])
100
+
101
+ const toggleSelected = useCallback((id: number) => {
102
+ setSelectedIds(ids =>
103
+ ids.includes(id) ? ids.filter(selectedId => selectedId !== id) : [...ids, id]
104
+ )
105
+ }, [])
106
+
107
+ const clearSelection = useCallback(() => {
108
+ setSelecting(false)
109
+ setSelectedIds([])
110
+ }, [])
111
+
112
+ useEffect(() => {
113
+ clearSelection()
114
+ }, [
115
+ clearSelection,
116
+ hideConversationsEnabled,
117
+ chat_group_graph_id,
118
+ group_source_app_name,
119
+ show_direct_messages,
120
+ show_archived,
121
+ show_hidden,
122
+ show_unread,
123
+ ])
124
+
73
125
  const value = useMemo(
74
126
  () => ({
75
127
  args,
76
128
  activeConversationId,
77
129
  setActiveConversationId,
78
130
  hideable,
131
+ selectMode,
132
+ selectedIds: selectMode ? selectedIds : [],
133
+ enterSelectMode,
134
+ toggleSelected,
135
+ clearSelection,
79
136
  ...query,
80
137
  }),
81
- [args, activeConversationId, hideable, query]
138
+ [
139
+ args,
140
+ activeConversationId,
141
+ hideable,
142
+ selectMode,
143
+ selectedIds,
144
+ enterSelectMode,
145
+ toggleSelected,
146
+ clearSelection,
147
+ query,
148
+ ]
82
149
  )
83
150
 
84
151
  return <ConversationsContext.Provider value={value}>{children}</ConversationsContext.Provider>
@@ -60,7 +60,10 @@ import {
60
60
  ConversationSelectTypeScreen,
61
61
  ConversationSelectTypeScreenOptions,
62
62
  } from '../screens/conversation_select_type_screen'
63
- import { ConversationsScreen } from '../screens/conversations/conversations_screen'
63
+ import {
64
+ ConversationsScreen,
65
+ conversationsScreenOptions,
66
+ } from '../screens/conversations/conversations_screen'
64
67
  import { GetHelpScreen } from '../screens/get_help_screen'
65
68
  import {
66
69
  GroupNotificationLevelSelectScreen,
@@ -181,13 +184,10 @@ export const ChatStack = createNativeStackNavigator({
181
184
  Conversations: {
182
185
  screen: ConversationsScreen,
183
186
  options: ({ route, navigation }) =>
184
- composeOptions(
185
- {
186
- headerTitle: (route.params as { title?: string })?.title ?? 'Chat',
187
- headerBackVisible: false,
188
- },
189
- withRightClose({ onPress: navigation.goBack })
190
- ),
187
+ conversationsScreenOptions({
188
+ title: (route.params as { title?: string })?.title,
189
+ onClose: navigation.goBack,
190
+ }),
191
191
  },
192
192
  ConversationFilters: {
193
193
  screen: ConversationFiltersScreen,
@@ -1,8 +1,7 @@
1
1
  import { type RouteProp, useRoute } from '@react-navigation/native'
2
- import { Pressable, View, StyleSheet, type ViewStyle } from 'react-native'
3
- import { Icon, Text } from '../../../components'
2
+ import { Pressable, StyleSheet, type ViewStyle } from 'react-native'
3
+ import { Checkbox, Text } from '../../../components'
4
4
  import { useTheme } from '../../../hooks'
5
- import { tokens } from '../../../vendor/tapestry/tokens'
6
5
  import { ConversationFilterRecipientsScreenProps, SetTeamFilters, TeamProps } from '../types'
7
6
 
8
7
  interface TeamRowProps {
@@ -43,7 +42,7 @@ export const CheckboxRow = ({
43
42
  accessibilityLabelledBy={accessibilityLabelledBy}
44
43
  accessibilityLabel={`${teamName} team`}
45
44
  >
46
- <CheckboxIcon checked={checked} />
45
+ <Checkbox checked={checked} />
47
46
  <Text style={styles.label} numberOfLines={2}>
48
47
  {teamName}
49
48
  </Text>
@@ -51,28 +50,9 @@ export const CheckboxRow = ({
51
50
  )
52
51
  }
53
52
 
54
- function CheckboxIcon({ checked }: { checked: boolean }) {
55
- const styles = useStyles()
56
- const checkedStyle = checked ? styles.checkedContainer : styles.uncheckedContainer
57
-
58
- return (
59
- <View style={checkedStyle}>
60
- {checked && <Icon name="general.thickCheckmark" style={styles.checkedIcon} />}
61
- </View>
62
- )
63
- }
64
-
65
53
  const useStyles = () => {
66
54
  const { colors } = useTheme()
67
55
 
68
- const baseCheckboxStyles: ViewStyle = {
69
- width: 20,
70
- height: 20,
71
- borderRadius: 40,
72
- alignItems: 'center',
73
- justifyContent: 'center',
74
- }
75
-
76
56
  return StyleSheet.create({
77
57
  checkboxRow: {
78
58
  flexDirection: 'row',
@@ -89,17 +69,5 @@ const useStyles = () => {
89
69
  label: {
90
70
  flex: 1,
91
71
  },
92
- checkedContainer: {
93
- ...baseCheckboxStyles,
94
- backgroundColor: colors.statusSuccessIcon,
95
- },
96
- uncheckedContainer: {
97
- ...baseCheckboxStyles,
98
- borderWidth: 2,
99
- borderColor: colors.borderColorDefaultDarker,
100
- },
101
- checkedIcon: {
102
- color: tokens.colorNeutral100White,
103
- },
104
72
  })
105
73
  }
@@ -12,6 +12,10 @@ import {
12
12
  import { ConversationsScreen } from '../conversations_screen'
13
13
 
14
14
  const mockGet = jest.fn()
15
+ jest.mock('@react-navigation/native', () => ({
16
+ ...jest.requireActual('@react-navigation/native'),
17
+ useNavigation: () => ({ setOptions: jest.fn(), goBack: jest.fn() }),
18
+ }))
15
19
  jest.mock('../../../hooks/use_api_client', () => ({
16
20
  useApiClient: () => ({ chat: { get: mockGet } }),
17
21
  }))
@@ -21,6 +25,7 @@ jest.mock('../../../hooks/use_product_analytics', () => ({
21
25
  }))
22
26
  jest.mock('../../../contexts/conversations_context', () => ({
23
27
  ConversationsContextProvider: ({ children }: { children: React.ReactNode }) => children,
28
+ useConversationsContext: () => ({ selectMode: false, selectedIds: [] }),
24
29
  }))
25
30
  jest.mock('../../../components', () => ({
26
31
  Conversations: ({ ListHeaderComponent }: { ListHeaderComponent: React.ComponentType }) => (
@@ -1,9 +1,17 @@
1
- import { StaticScreenProps } from '@react-navigation/native'
2
- import React from 'react'
1
+ import { StaticScreenProps, useNavigation } from '@react-navigation/native'
2
+ import React, { useLayoutEffect, useRef } from 'react'
3
3
  import { StyleSheet, View } from 'react-native'
4
4
  import { Conversations } from '../../components'
5
+ import {
6
+ composeOptions,
7
+ withRightClose,
8
+ withRightText,
9
+ } from '../../components/display/platform_modal_header_buttons'
5
10
  import { Toast } from '../../components/display/toast'
6
- import { ConversationsContextProvider } from '../../contexts/conversations_context'
11
+ import {
12
+ ConversationsContextProvider,
13
+ useConversationsContext,
14
+ } from '../../contexts/conversations_context'
7
15
  import { useFilterDropdownEnabled } from '../../hooks/use_filter_dropdown_enabled'
8
16
  import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
9
17
  import { useSearchEnabled } from '../../hooks/use_search_enabled'
@@ -23,6 +31,18 @@ export type ConversationsScreenProps = StaticScreenProps<{
23
31
  show_unread?: boolean
24
32
  }>
25
33
 
34
+ export const conversationsScreenOptions = ({
35
+ title,
36
+ onClose,
37
+ }: {
38
+ title?: string
39
+ onClose: () => void
40
+ }) =>
41
+ composeOptions(
42
+ { headerTitle: title ?? 'Chat', headerBackVisible: false },
43
+ withRightClose({ onPress: onClose })
44
+ )
45
+
26
46
  export function ConversationsScreen({ route }: ConversationsScreenProps) {
27
47
  const styles = useStyles()
28
48
  const Header = useListHeaderComponent()
@@ -32,6 +52,7 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
32
52
  return (
33
53
  <View style={styles.container}>
34
54
  <ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
55
+ <SelectModeHeader title={route.params?.title} />
35
56
  <Conversations ListHeaderComponent={Header} />
36
57
  </ConversationsContextProvider>
37
58
  <Toast />
@@ -39,6 +60,31 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
39
60
  )
40
61
  }
41
62
 
63
+ function SelectModeHeader({ title }: { title?: string }) {
64
+ const navigation = useNavigation()
65
+ const { selectMode, selectedIds, clearSelection } = useConversationsContext()
66
+ const hasEnteredSelectMode = useRef(false)
67
+ const selectedCount = selectedIds.length
68
+
69
+ useLayoutEffect(() => {
70
+ if (selectMode) hasEnteredSelectMode.current = true
71
+ if (!hasEnteredSelectMode.current) return
72
+
73
+ navigation.setOptions(
74
+ selectMode
75
+ ? composeOptions(
76
+ {
77
+ headerTitle: selectedCount > 0 ? `${selectedCount} selected` : 'Select conversations',
78
+ },
79
+ withRightText({ text: 'Cancel', onPress: clearSelection })
80
+ )
81
+ : conversationsScreenOptions({ title, onClose: navigation.goBack })
82
+ )
83
+ }, [navigation, selectMode, selectedCount, clearSelection, title])
84
+
85
+ return null
86
+ }
87
+
42
88
  const useListHeaderComponent = () => {
43
89
  const filterDropdownEnabled = useFilterDropdownEnabled()
44
90
  const searchEnabled = useSearchEnabled()