@planningcenter/chat-react-native 3.42.3-qa-staging.6 → 3.43.0-rc.0
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.
- package/build/components/conversation/messages_disabled_banners.d.ts +3 -2
- package/build/components/conversation/messages_disabled_banners.d.ts.map +1 -1
- package/build/components/conversation/messages_disabled_banners.js +7 -2
- package/build/components/conversation/messages_disabled_banners.js.map +1 -1
- package/build/components/display/adult_requirement_notice.js +1 -1
- package/build/components/display/adult_requirement_notice.js.map +1 -1
- package/build/components/display/platform_modal_header_buttons.d.ts +7 -47
- package/build/components/display/platform_modal_header_buttons.d.ts.map +1 -1
- package/build/components/display/platform_modal_header_buttons.js +9 -119
- package/build/components/display/platform_modal_header_buttons.js.map +1 -1
- package/build/hooks/index.d.ts +1 -1
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +1 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +0 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_conversation_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_jolt_events.js +2 -10
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_current_person.d.ts.map +1 -1
- package/build/hooks/use_current_person.js +0 -1
- package/build/hooks/use_current_person.js.map +1 -1
- package/build/hooks/use_direct_messages_enabled.d.ts +2 -0
- package/build/hooks/use_direct_messages_enabled.d.ts.map +1 -0
- package/build/hooks/use_direct_messages_enabled.js +16 -0
- package/build/hooks/use_direct_messages_enabled.js.map +1 -0
- package/build/hooks/use_features.d.ts +1 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -0
- package/build/hooks/use_features.js.map +1 -1
- package/build/navigation/index.d.ts +173 -69
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +72 -61
- package/build/navigation/index.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +13 -10
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +12 -11
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_filters/components/conversation_filters.js +3 -3
- package/build/screens/conversation_filters/components/conversation_filters.js.map +1 -1
- package/build/screens/conversation_filters/components/rows.js +1 -1
- package/build/screens/conversation_filters/components/rows.js.map +1 -1
- package/build/screens/conversation_filters_screen.js +2 -2
- package/build/screens/conversation_filters_screen.js.map +1 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +3 -10
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/components/groups_recipient_row.js +1 -1
- package/build/screens/conversation_select_recipients/components/groups_recipient_row.js.map +1 -1
- package/build/screens/conversation_select_recipients/components/restricted_group_row.js +1 -1
- package/build/screens/conversation_select_recipients/components/restricted_group_row.js.map +1 -1
- package/build/screens/conversation_select_type_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_type_screen.js +7 -4
- package/build/screens/conversation_select_type_screen.js.map +1 -1
- package/build/screens/conversations/components/list_header_component.js +3 -3
- package/build/screens/conversations/components/list_header_component.js.map +1 -1
- package/build/screens/message_report_screen.d.ts.map +1 -1
- package/build/screens/message_report_screen.js +18 -14
- package/build/screens/message_report_screen.js.map +1 -1
- package/build/screens/notification_settings_screen.d.ts.map +1 -1
- package/build/screens/notification_settings_screen.js +14 -0
- package/build/screens/notification_settings_screen.js.map +1 -1
- package/build/screens/settings_screen.js +3 -3
- package/build/screens/settings_screen.js.map +1 -1
- package/build/types/jolt_events/conversation_events.d.ts +2 -2
- package/build/types/jolt_events/conversation_events.d.ts.map +1 -1
- package/build/types/jolt_events/conversation_events.js.map +1 -1
- package/build/types/resources/conversation.d.ts +2 -2
- package/build/types/resources/conversation.d.ts.map +1 -1
- package/build/types/resources/conversation.js.map +1 -1
- package/build/types/resources/person.d.ts +0 -1
- package/build/types/resources/person.d.ts.map +1 -1
- package/build/types/resources/person.js.map +1 -1
- package/build/utils/conversation_safety_constants.d.ts +1 -1
- package/build/utils/conversation_safety_constants.d.ts.map +1 -1
- package/build/utils/conversation_safety_constants.js +1 -1
- package/build/utils/conversation_safety_constants.js.map +1 -1
- package/build/utils/request/conversation.d.ts.map +1 -1
- package/build/utils/request/conversation.js +0 -1
- package/build/utils/request/conversation.js.map +1 -1
- package/package.json +4 -4
- package/src/components/conversation/messages_disabled_banners.tsx +11 -3
- package/src/components/display/adult_requirement_notice.tsx +1 -1
- package/src/components/display/platform_modal_header_buttons.tsx +13 -254
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use_conversation.ts +0 -1
- package/src/hooks/use_conversation_jolt_events.ts +3 -16
- package/src/hooks/use_current_person.ts +0 -1
- package/src/hooks/use_direct_messages_enabled.ts +23 -0
- package/src/hooks/use_features.ts +1 -0
- package/src/navigation/index.tsx +166 -149
- package/src/screens/bug_report_screen.tsx +15 -16
- package/src/screens/conversation_details_screen.tsx +17 -11
- package/src/screens/conversation_filters/components/conversation_filters.tsx +3 -3
- package/src/screens/conversation_filters/components/rows.tsx +2 -2
- package/src/screens/conversation_filters_screen.tsx +2 -2
- package/src/screens/conversation_screen.tsx +3 -11
- package/src/screens/conversation_select_recipients/components/groups_recipient_row.tsx +1 -1
- package/src/screens/conversation_select_recipients/components/restricted_group_row.tsx +2 -2
- package/src/screens/conversation_select_type_screen.tsx +7 -4
- package/src/screens/conversations/components/list_header_component.tsx +3 -3
- package/src/screens/message_report_screen.tsx +21 -20
- package/src/screens/notification_settings_screen.tsx +21 -1
- package/src/screens/settings_screen.tsx +3 -3
- package/src/types/jolt_events/conversation_events.ts +2 -2
- package/src/types/resources/conversation.ts +3 -2
- package/src/types/resources/person.ts +0 -1
- package/src/utils/conversation_safety_constants.ts +1 -1
- package/src/utils/request/conversation.ts +0 -1
- package/build/hooks/use_direct_messages_eligible.d.ts +0 -2
- package/build/hooks/use_direct_messages_eligible.d.ts.map +0 -1
- package/build/hooks/use_direct_messages_eligible.js +0 -9
- package/build/hooks/use_direct_messages_eligible.js.map +0 -1
- package/src/__tests__/hooks/use_direct_messages_eligible.test.tsx +0 -77
- package/src/hooks/use_direct_messages_eligible.ts +0 -11
|
@@ -2,6 +2,7 @@ import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
|
2
2
|
import React, { useLayoutEffect } from 'react'
|
|
3
3
|
import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
|
|
4
4
|
import { useCurrentPerson } from '../hooks/use_current_person'
|
|
5
|
+
import { availableFeatures, useFeatures } from '../hooks/use_features'
|
|
5
6
|
import { useConversationTypeAccess } from '../hooks/use_new_conversation_entry'
|
|
6
7
|
import type { NewConversationFromFilter } from '../hooks/use_new_conversation_from_filter'
|
|
7
8
|
import { AppName } from '../types/resources/app_name'
|
|
@@ -27,15 +28,17 @@ export function ConversationSelectTypeScreen({ route }: ConversationSelectTypeSc
|
|
|
27
28
|
const navigation = useNavigation()
|
|
28
29
|
const { canCreateGroupsConversations, canCreateServicesConversations } =
|
|
29
30
|
useConversationTypeAccess()
|
|
30
|
-
const {
|
|
31
|
+
const { featureEnabled } = useFeatures()
|
|
32
|
+
const { directMessagesDisabled, under_18 } = useCurrentPerson()
|
|
31
33
|
const { newConversationFromFilter, chat_group_graph_id, group_source_app_name } =
|
|
32
34
|
route.params || {}
|
|
33
35
|
|
|
34
36
|
const filterParams = { chat_group_graph_id, group_source_app_name }
|
|
35
|
-
const
|
|
37
|
+
const dmFeatureEnabled = featureEnabled(availableFeatures.direct_messages_eap)
|
|
38
|
+
const showDirectMessageOption = dmFeatureEnabled && !under_18
|
|
36
39
|
|
|
37
|
-
// sheetAllowedDetents depends on DM
|
|
38
|
-
// here instead of in the static ConversationSelectTypeScreenOptions. useLayoutEffect applies
|
|
40
|
+
// sheetAllowedDetents depends on the DM feature flag, which isn't known until render, so it's
|
|
41
|
+
// set here instead of in the static ConversationSelectTypeScreenOptions. useLayoutEffect applies
|
|
39
42
|
// it before paint so the sheet never visibly resizes after opening.
|
|
40
43
|
useLayoutEffect(() => {
|
|
41
44
|
navigation.setOptions({ sheetAllowedDetents: showDirectMessageOption ? [0.3] : [0.25] })
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useAtFontScaleBreakpoint,
|
|
7
7
|
useCanCreateConversations,
|
|
8
8
|
useCurrentPersonCache,
|
|
9
|
-
|
|
9
|
+
useDirectMessagesEnabled,
|
|
10
10
|
useHasDirectMessages,
|
|
11
11
|
useNewConversationEntry,
|
|
12
12
|
useTheme,
|
|
@@ -35,9 +35,9 @@ export const ListHeaderComponent = () => {
|
|
|
35
35
|
const navigation = useNavigation()
|
|
36
36
|
const canFilterByTeams = useCanDisplayGroups({ source_app_name: 'Services', source_type: 'Team' })
|
|
37
37
|
const canFilterByGroups = useCanDisplayGroups({ source_app_name: 'Groups', source_type: 'Group' })
|
|
38
|
-
const
|
|
38
|
+
const directMessagesEnabled = useDirectMessagesEnabled()
|
|
39
39
|
const hasDirectMessages = useHasDirectMessages()
|
|
40
|
-
const canFilterByDMs =
|
|
40
|
+
const canFilterByDMs = directMessagesEnabled && hasDirectMessages
|
|
41
41
|
const route = useRoute<RouteProp<ConversationsScreenProps['route']>>()
|
|
42
42
|
const {
|
|
43
43
|
chat_group_graph_id,
|
|
@@ -8,9 +8,8 @@ import { View, StyleSheet, TextInput, ScrollView } from 'react-native'
|
|
|
8
8
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
9
9
|
import { Spinner, Text, KeyboardView } from '../components'
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
withLeftClose,
|
|
11
|
+
HeaderDismissButton,
|
|
12
|
+
HeaderTextButton,
|
|
14
13
|
} from '../components/display/platform_modal_header_buttons'
|
|
15
14
|
import BlankState from '../components/primitive/blank_state_primitive'
|
|
16
15
|
import { useTheme } from '../hooks'
|
|
@@ -35,10 +34,11 @@ export const MessageReportScreenOptions = ({
|
|
|
35
34
|
})
|
|
36
35
|
)
|
|
37
36
|
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
return {
|
|
38
|
+
presentation: 'modal',
|
|
39
|
+
title: 'Report message',
|
|
40
|
+
headerLeft: () => <HeaderDismissButton title="Cancel" onPress={handleClose} />,
|
|
41
|
+
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export type MessageReportScreenProps = StaticScreenProps<{
|
|
@@ -103,22 +103,23 @@ function MessageReportScreenContent({
|
|
|
103
103
|
navigation.dispatch(StackActions.popTo('Conversation', { conversation_id }))
|
|
104
104
|
}, [navigation, conversation_id])
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
accessibilityLabel: 'Submit',
|
|
111
|
-
variant: 'fill',
|
|
112
|
-
onPress: handleSubmit,
|
|
113
|
-
disabled: !isFormValid,
|
|
114
|
-
enabled: formVisible,
|
|
115
|
-
})
|
|
106
|
+
const HeaderRight = useCallback(
|
|
107
|
+
() => <HeaderTextButton title="Submit" onPress={handleSubmit} disabled={!isFormValid} />,
|
|
108
|
+
[handleSubmit, isFormValid]
|
|
109
|
+
)
|
|
116
110
|
|
|
117
111
|
useLayoutEffect(() => {
|
|
118
|
-
if (
|
|
119
|
-
navigation.setOptions({
|
|
112
|
+
if (status === 'pending' || status === 'success') {
|
|
113
|
+
navigation.setOptions({
|
|
114
|
+
headerRight: () => null,
|
|
115
|
+
})
|
|
116
|
+
} else {
|
|
117
|
+
navigation.setOptions({
|
|
118
|
+
headerTitle: 'Report message',
|
|
119
|
+
headerRight: HeaderRight,
|
|
120
|
+
})
|
|
120
121
|
}
|
|
121
|
-
}, [
|
|
122
|
+
}, [HeaderRight, navigation, status])
|
|
122
123
|
|
|
123
124
|
if (status === 'pending') {
|
|
124
125
|
return (
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { type ReactNode } from 'react'
|
|
3
|
+
import React, { useCallback, useEffect, type ReactNode } from 'react'
|
|
4
4
|
import { FlatList, Platform, StyleSheet, View, type ViewProps, type ViewStyle } from 'react-native'
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
6
6
|
import { Badge, Heading, Icon, Text } from '../components'
|
|
7
|
+
import { HeaderTextButton } from '../components/display/platform_modal_header_buttons'
|
|
7
8
|
import { useTheme } from '../hooks'
|
|
8
9
|
import { isDefined } from '../types'
|
|
9
10
|
import { chatTypeLabel } from '../utils'
|
|
@@ -50,6 +51,25 @@ export function NotificationSettingsScreen({}: NotificationSettingsScreenProps)
|
|
|
50
51
|
const { data: chatTypes } = useChatTypes()
|
|
51
52
|
const { data: groups } = useGroups()
|
|
52
53
|
|
|
54
|
+
// Header configuration
|
|
55
|
+
const HeaderRight = useCallback(() => {
|
|
56
|
+
return (
|
|
57
|
+
<HeaderTextButton
|
|
58
|
+
onPress={() => {
|
|
59
|
+
// Save settings logic would go here
|
|
60
|
+
navigation.goBack()
|
|
61
|
+
}}
|
|
62
|
+
title="Done"
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
}, [navigation])
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
navigation.setOptions({
|
|
69
|
+
headerRight: HeaderRight,
|
|
70
|
+
})
|
|
71
|
+
}, [HeaderRight, navigation])
|
|
72
|
+
|
|
53
73
|
// Build section data
|
|
54
74
|
const listData = [
|
|
55
75
|
{
|
|
@@ -4,7 +4,7 @@ import React, { useCallback } from 'react'
|
|
|
4
4
|
import { Platform, StyleSheet, View } from 'react-native'
|
|
5
5
|
import { Heading, Icon, Text } from '../components'
|
|
6
6
|
import { Switch } from '../components/display/switch'
|
|
7
|
-
import {
|
|
7
|
+
import { useDirectMessagesEnabled, useTheme } from '../hooks'
|
|
8
8
|
import { useAppName } from '../hooks/use_app_name'
|
|
9
9
|
import { usePersonSettings } from '../hooks/use_person_settings'
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ export type SettingsScreenProps = StaticScreenProps<{}>
|
|
|
13
13
|
export function SettingsScreen({}: SettingsScreenProps) {
|
|
14
14
|
const styles = useStyles()
|
|
15
15
|
const { directMessagesDisabled, setDirectMessagesDisabled, isMutating } = usePersonSettings()
|
|
16
|
-
const
|
|
16
|
+
const directMessagesEnabled = useDirectMessagesEnabled()
|
|
17
17
|
const appName = useAppName()
|
|
18
18
|
const navigation = useNavigation()
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ export function SettingsScreen({}: SettingsScreenProps) {
|
|
|
31
31
|
<View style={styles.sectionHeader}>
|
|
32
32
|
<Heading variant="h2">Messages</Heading>
|
|
33
33
|
</View>
|
|
34
|
-
{
|
|
34
|
+
{directMessagesEnabled && (
|
|
35
35
|
<View style={styles.settingRow}>
|
|
36
36
|
<View style={styles.settingRowText}>
|
|
37
37
|
<Text>Allow direct messages</Text>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'
|
|
2
|
+
import type { ConversationDisabledReason } from '../resources/conversation'
|
|
2
3
|
|
|
3
4
|
type DateString = string
|
|
4
5
|
interface BaseConversationEventData extends Record<string, unknown> {
|
|
@@ -15,8 +16,7 @@ interface BaseConversationEventData extends Record<string, unknown> {
|
|
|
15
16
|
latest_read_message_sort_key?: string
|
|
16
17
|
organization_id: number
|
|
17
18
|
disabled: boolean
|
|
18
|
-
disabled_reason
|
|
19
|
-
disabled_message: string | null
|
|
19
|
+
disabled_reason?: ConversationDisabledReason
|
|
20
20
|
replies_disabled: boolean
|
|
21
21
|
subtitle?: string
|
|
22
22
|
title: string
|
|
@@ -5,6 +5,8 @@ import { GroupResource } from './group_resource'
|
|
|
5
5
|
import { MemberAbilityResource } from './member_ability'
|
|
6
6
|
import { ReactionCountResource } from './reaction'
|
|
7
7
|
|
|
8
|
+
export type ConversationDisabledReason = 'safety_check' | 'direct_messages_disabled'
|
|
9
|
+
|
|
8
10
|
export interface ConversationPreviewData {
|
|
9
11
|
kind: 'reaction' | 'message'
|
|
10
12
|
authorName: string
|
|
@@ -24,8 +26,7 @@ export interface ConversationResource {
|
|
|
24
26
|
deleted?: boolean
|
|
25
27
|
directMessage?: boolean
|
|
26
28
|
disabled?: boolean
|
|
27
|
-
disabledReason?:
|
|
28
|
-
disabledMessage?: string | null
|
|
29
|
+
disabledReason?: ConversationDisabledReason
|
|
29
30
|
genderOption?: string | null
|
|
30
31
|
groups?: GroupResource[]
|
|
31
32
|
previewAvatarUrls?: string[]
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const ADULT_REQUIREMENT_BODY =
|
|
2
|
-
'Conversations with
|
|
2
|
+
'Conversations with teens require at least 2 adults. This chat is paused until another adult is added.'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_direct_messages_eligible.d.ts","sourceRoot":"","sources":["../../src/hooks/use_direct_messages_eligible.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,QAAO,OAM5C,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useApiGet } from './use_api';
|
|
2
|
-
import { currentPersonRequestArgs } from './use_current_person';
|
|
3
|
-
export const useDirectMessagesEligible = () => {
|
|
4
|
-
const { data: person, isFetched } = useApiGet(currentPersonRequestArgs);
|
|
5
|
-
if (!isFetched)
|
|
6
|
-
return false;
|
|
7
|
-
return person?.directMessagesEligible ?? false;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=use_direct_messages_eligible.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_direct_messages_eligible.js","sourceRoot":"","sources":["../../src/hooks/use_direct_messages_eligible.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAE/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAY,EAAE;IACrD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAwB,wBAAwB,CAAC,CAAA;IAE9F,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAA;IAE5B,OAAO,MAAM,EAAE,sBAAsB,IAAI,KAAK,CAAA;AAChD,CAAC,CAAA","sourcesContent":["import { CurrentPersonResource } from '../types'\nimport { useApiGet } from './use_api'\nimport { currentPersonRequestArgs } from './use_current_person'\n\nexport const useDirectMessagesEligible = (): boolean => {\n const { data: person, isFetched } = useApiGet<CurrentPersonResource>(currentPersonRequestArgs)\n\n if (!isFetched) return false\n\n return person?.directMessagesEligible ?? false\n}\n"]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
-
import { act, renderHook, waitFor } from '@testing-library/react-native'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
-
import { ChatContext, ChatContextValue } from '../../contexts/chat_context'
|
|
6
|
-
import { ApiClient, useApiClient } from '../../hooks/use_api_client'
|
|
7
|
-
import { currentPersonQueryKey } from '../../hooks/use_current_person'
|
|
8
|
-
import { useDirectMessagesEligible } from '../../hooks/use_direct_messages_eligible'
|
|
9
|
-
import { Session } from '../../utils'
|
|
10
|
-
|
|
11
|
-
jest.mock('../../hooks/use_api_client')
|
|
12
|
-
|
|
13
|
-
const mockedUseApiClient = useApiClient as jest.MockedFunction<typeof useApiClient>
|
|
14
|
-
|
|
15
|
-
let get: jest.Mock
|
|
16
|
-
|
|
17
|
-
const session = new Session({ token: { access_token: 'a-real-token' } })
|
|
18
|
-
|
|
19
|
-
const renderUseDirectMessagesEligible = (queryClient = buildTestQueryClient()) => {
|
|
20
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
21
|
-
<QueryClientProvider client={queryClient}>
|
|
22
|
-
<ChatContext.Provider value={{ session } as unknown as ChatContextValue}>
|
|
23
|
-
{children}
|
|
24
|
-
</ChatContext.Provider>
|
|
25
|
-
</QueryClientProvider>
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
return { ...renderHook(() => useDirectMessagesEligible(), { wrapper }), queryClient }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const flushMicrotasks = () =>
|
|
32
|
-
act(async () => {
|
|
33
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
get = jest.fn().mockResolvedValue({ data: { id: 1, directMessagesEligible: true } })
|
|
38
|
-
mockedUseApiClient.mockReturnValue({ chat: { get } } as unknown as ApiClient)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
afterEach(() => {
|
|
42
|
-
jest.clearAllMocks()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('useDirectMessagesEligible', () => {
|
|
46
|
-
it('returns true once the person is fetched as eligible', async () => {
|
|
47
|
-
get.mockResolvedValue({
|
|
48
|
-
data: { id: 1, directMessagesEligible: true, directMessagesDisabled: true },
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
const { result } = renderUseDirectMessagesEligible()
|
|
52
|
-
|
|
53
|
-
await waitFor(() => expect(result.current).toBe(true))
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('returns false when the attribute is absent from the response', async () => {
|
|
57
|
-
get.mockResolvedValue({ data: { id: 1 } })
|
|
58
|
-
|
|
59
|
-
const { result } = renderUseDirectMessagesEligible()
|
|
60
|
-
|
|
61
|
-
await waitFor(() => expect(get).toHaveBeenCalled())
|
|
62
|
-
await flushMicrotasks()
|
|
63
|
-
|
|
64
|
-
expect(result.current).toBe(false)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('reads the same /me cache entry as useCurrentPerson', () => {
|
|
68
|
-
const queryClient = buildTestQueryClient()
|
|
69
|
-
queryClient.setQueryData(currentPersonQueryKey, {
|
|
70
|
-
data: { id: 1, directMessagesEligible: true },
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const { result } = renderUseDirectMessagesEligible(queryClient)
|
|
74
|
-
|
|
75
|
-
expect(result.current).toBe(true)
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CurrentPersonResource } from '../types'
|
|
2
|
-
import { useApiGet } from './use_api'
|
|
3
|
-
import { currentPersonRequestArgs } from './use_current_person'
|
|
4
|
-
|
|
5
|
-
export const useDirectMessagesEligible = (): boolean => {
|
|
6
|
-
const { data: person, isFetched } = useApiGet<CurrentPersonResource>(currentPersonRequestArgs)
|
|
7
|
-
|
|
8
|
-
if (!isFetched) return false
|
|
9
|
-
|
|
10
|
-
return person?.directMessagesEligible ?? false
|
|
11
|
-
}
|