@planningcenter/chat-react-native 4.7.1-qa-staging.2 → 4.7.1-qa-staging.3
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/attachments/expanded_link.js +8 -8
- package/build/components/conversation/attachments/expanded_link.js.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.js +2 -2
- package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.js +2 -2
- package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +2 -2
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/message_form.js +2 -2
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_markdown.js +2 -2
- package/build/components/conversation/message_markdown.js.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +3 -3
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.js +2 -2
- package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -1
- package/build/screens/bug_report_screen.js +4 -4
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/get_help_screen.d.ts.map +1 -1
- package/build/screens/get_help_screen.js +5 -21
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/open_url.d.ts +11 -0
- package/build/utils/open_url.d.ts.map +1 -0
- package/build/utils/open_url.js +46 -0
- package/build/utils/open_url.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +1 -1
- package/src/__tests__/screens/get_help_screen.test.ts +1 -1
- package/src/components/conversation/attachments/expanded_link.tsx +4 -4
- package/src/components/conversation/attachments/generic_file_attachment.tsx +2 -5
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -4
- package/src/components/conversation/attachments/image_attachment.tsx +2 -2
- package/src/components/conversation/message_form.tsx +2 -2
- package/src/components/conversation/message_markdown.tsx +2 -2
- package/src/screens/age_check/age_check_underage_screen.tsx +3 -3
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +2 -2
- package/src/screens/bug_report_screen.tsx +4 -4
- package/src/screens/get_help_screen.tsx +5 -19
- package/src/utils/__tests__/open_url.test.ts +67 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/open_url.ts +47 -0
|
@@ -29,7 +29,7 @@ import Animated, {
|
|
|
29
29
|
import { useSafeAreaInsets, SafeAreaProvider } from 'react-native-safe-area-context'
|
|
30
30
|
import { useTheme } from '../../../hooks'
|
|
31
31
|
import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
32
|
-
import { Haptic,
|
|
32
|
+
import { Haptic, openUrl, platformFontWeightMedium } from '../../../utils'
|
|
33
33
|
import { formatDatePreview } from '../../../utils/date'
|
|
34
34
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
35
35
|
import { IconButton, Image, Heading, Text } from '../../display'
|
|
@@ -211,7 +211,7 @@ const LightboxGallery = ({
|
|
|
211
211
|
HANDLERS
|
|
212
212
|
============================ */
|
|
213
213
|
const handleOpenInBrowser = useCallback(() => {
|
|
214
|
-
|
|
214
|
+
openUrl(urlMedium || url, { forceOpenInBrowser: true })
|
|
215
215
|
}, [urlMedium, url])
|
|
216
216
|
|
|
217
217
|
// Helper to enable or disable FlatList scroll state after gestures have ended
|
|
@@ -33,9 +33,9 @@ import {
|
|
|
33
33
|
FileAttachment,
|
|
34
34
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
35
35
|
import {
|
|
36
|
-
Linking,
|
|
37
36
|
Log,
|
|
38
37
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
38
|
+
openUrl,
|
|
39
39
|
platformFontWeightMedium,
|
|
40
40
|
platformPressedOpacityStyle,
|
|
41
41
|
} from '../../utils'
|
|
@@ -430,7 +430,7 @@ function BannerMessage({ isSingular, fileType }: { isSingular: boolean; fileType
|
|
|
430
430
|
<Text
|
|
431
431
|
style={styles.flaggedBannerLink}
|
|
432
432
|
onPress={() =>
|
|
433
|
-
|
|
433
|
+
openUrl(
|
|
434
434
|
'https://www.planningcenter.com/terms#:~:text=4.%20Acceptable%20Use%20of%20Planning%20Center'
|
|
435
435
|
)
|
|
436
436
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { StyleSheet } from 'react-native'
|
|
3
|
-
import {
|
|
3
|
+
import { openUrl } from '../../utils/open_url'
|
|
4
4
|
import { parseSimpleMarkdown } from '../../utils/parse_simple_markdown'
|
|
5
5
|
import { Text, TextInlineButton } from '../display'
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@ export function MessageMarkdown({ text }: Props) {
|
|
|
36
36
|
return (
|
|
37
37
|
<TextInlineButton
|
|
38
38
|
key={i}
|
|
39
|
-
onPress={() =>
|
|
39
|
+
onPress={() => openUrl(part.content)}
|
|
40
40
|
accessibilityRole="link"
|
|
41
41
|
accessibilityHint="Opens browser"
|
|
42
42
|
>
|
|
@@ -4,7 +4,7 @@ import { StyleSheet, View, ScrollView } from 'react-native'
|
|
|
4
4
|
import { Heading } from '../../components'
|
|
5
5
|
import { Icon, Text, TextInlineButton } from '../../components/display'
|
|
6
6
|
import { useTheme } from '../../hooks'
|
|
7
|
-
import {
|
|
7
|
+
import { openUrl } from '../../utils'
|
|
8
8
|
import type { AgeCheckParams } from './screen_props'
|
|
9
9
|
|
|
10
10
|
export interface AgeCheckUnderageScreenProps {
|
|
@@ -19,11 +19,11 @@ export function AgeCheckUnderageScreen({ contactEmail }: AgeCheckUnderageScreenP
|
|
|
19
19
|
|
|
20
20
|
const openChurchAdminHelp = () => {
|
|
21
21
|
if (!email) return
|
|
22
|
-
|
|
22
|
+
openUrl(`mailto:${email}`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const openTerms = () => {
|
|
26
|
-
|
|
26
|
+
openUrl('https://www.planningcenter.com/terms')
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return (
|
|
@@ -3,7 +3,7 @@ import React, { useCallback } from 'react'
|
|
|
3
3
|
import { Alert, StyleSheet } from 'react-native'
|
|
4
4
|
import FormSheet, { getFormSheetScreenOptions } from '../../components/primitive/form_sheet'
|
|
5
5
|
import { useConversation } from '../../hooks/use_conversation'
|
|
6
|
-
import {
|
|
6
|
+
import { openUrl } from '../../utils'
|
|
7
7
|
import { useDeleteAttachment } from './hooks/useDeleteAttachment'
|
|
8
8
|
|
|
9
9
|
export const AttachmentActionsScreenOptions = getFormSheetScreenOptions({
|
|
@@ -60,7 +60,7 @@ export function AttachmentActionsScreen({ route }: AttachmentActionsScreenProps)
|
|
|
60
60
|
}, [attachmentName, handleDeleteAttachment, navigation])
|
|
61
61
|
|
|
62
62
|
const handleOpenInBrowser = () => {
|
|
63
|
-
|
|
63
|
+
openUrl(attachmentUrl, { forceOpenInBrowser: true })
|
|
64
64
|
navigation.goBack()
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -30,7 +30,7 @@ import { useTheme } from '../hooks'
|
|
|
30
30
|
import { useAppName } from '../hooks/use_app_name'
|
|
31
31
|
import { useReportBugAction } from '../hooks/use_report_bug_action'
|
|
32
32
|
import { useUploadClient } from '../hooks/use_upload_client'
|
|
33
|
-
import { ImagePicker, ImagePickerResult,
|
|
33
|
+
import { ImagePicker, ImagePickerResult, openUrl, platformFontWeightBold } from '../utils'
|
|
34
34
|
|
|
35
35
|
const MAX_DESCRIPTION_LENGTH = 2000
|
|
36
36
|
|
|
@@ -196,7 +196,7 @@ export function BugReportScreen() {
|
|
|
196
196
|
<TextInlineButton
|
|
197
197
|
accessibilityRole="link"
|
|
198
198
|
onPress={() =>
|
|
199
|
-
|
|
199
|
+
openUrl('https://support.planningcenteronline.com/hc/en-us/requests/new')
|
|
200
200
|
}
|
|
201
201
|
>
|
|
202
202
|
contact our help center
|
|
@@ -342,7 +342,7 @@ export function BugReportScreen() {
|
|
|
342
342
|
<TextInlineButton
|
|
343
343
|
accessibilityRole="link"
|
|
344
344
|
variant="footnote"
|
|
345
|
-
onPress={() =>
|
|
345
|
+
onPress={() => openUrl(VIDEO_RECORDING_HELP_URL)}
|
|
346
346
|
>
|
|
347
347
|
How to record your screen
|
|
348
348
|
</TextInlineButton>
|
|
@@ -355,7 +355,7 @@ export function BugReportScreen() {
|
|
|
355
355
|
<TextInlineButton
|
|
356
356
|
accessibilityRole="link"
|
|
357
357
|
variant="footnote"
|
|
358
|
-
onPress={() =>
|
|
358
|
+
onPress={() => openUrl('https://www.planningcenter.com/privacy')}
|
|
359
359
|
>
|
|
360
360
|
Privacy Policy
|
|
361
361
|
</TextInlineButton>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import { useCallback, useMemo } from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import { ScrollView, StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Heading, PressableRow, Text, TextInlineButton } from '../components'
|
|
5
5
|
import { useApiGet, useTheme } from '../hooks'
|
|
6
6
|
import { useAppName } from '../hooks/use_app_name'
|
|
7
7
|
import { useOrganization } from '../hooks/use_organization'
|
|
8
8
|
import { ResourceObject } from '../types'
|
|
9
|
-
import {
|
|
9
|
+
import { openUrl } from '../utils'
|
|
10
10
|
|
|
11
11
|
type GetHelpScreenRouteProps = {
|
|
12
12
|
type?: 'chat' | 'general'
|
|
@@ -65,7 +65,7 @@ export const GetHelpScreen = ({ route }: GetHelpScreenProps) => {
|
|
|
65
65
|
{appSpecificHelpUrls.map(helpUrl => (
|
|
66
66
|
<PressableRow
|
|
67
67
|
key={helpUrl.id}
|
|
68
|
-
onPress={() =>
|
|
68
|
+
onPress={() => openUrl(helpUrl.link)}
|
|
69
69
|
text={helpUrl.title}
|
|
70
70
|
isActive={true}
|
|
71
71
|
iconPath="general.newWindow"
|
|
@@ -117,27 +117,13 @@ const ContactRow = ({ email, phone }: { email?: string; phone?: string }) => {
|
|
|
117
117
|
export function sendEmail(email: string) {
|
|
118
118
|
if (!email) return
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Linking.openURL(url).catch(() => {
|
|
123
|
-
Alert.alert('Oops', `Unable to open: ${email}`, [
|
|
124
|
-
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(email) },
|
|
125
|
-
{ text: 'OK' },
|
|
126
|
-
])
|
|
127
|
-
})
|
|
120
|
+
openUrl(encodeURI(`mailto:${email}`))
|
|
128
121
|
}
|
|
129
122
|
|
|
130
123
|
export function placePhoneCall(phoneNumber: string) {
|
|
131
124
|
if (!phoneNumber) return
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
Linking.openURL(url).catch(() => {
|
|
136
|
-
Alert.alert('Oops', `Unable to open: ${phoneNumber}`, [
|
|
137
|
-
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(phoneNumber) },
|
|
138
|
-
{ text: 'OK' },
|
|
139
|
-
])
|
|
140
|
-
})
|
|
126
|
+
openUrl(encodeURI(`tel:${phoneNumber}`))
|
|
141
127
|
}
|
|
142
128
|
|
|
143
129
|
const useStyles = () => {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Alert } from 'react-native'
|
|
2
|
+
import { Clipboard, Linking, Log } from '../native_adapters'
|
|
3
|
+
import { openUrl } from '../open_url'
|
|
4
|
+
|
|
5
|
+
type AlertButton = { text?: string; onPress?: () => void }
|
|
6
|
+
|
|
7
|
+
const pressButton = (text: string) => {
|
|
8
|
+
const buttons = (Alert.alert as jest.Mock).mock.calls[0][2] as AlertButton[]
|
|
9
|
+
buttons.find(button => button.text === text)?.onPress?.()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('openUrl', () => {
|
|
13
|
+
let openURL: jest.SpyInstance
|
|
14
|
+
let setStringAsync: jest.SpyInstance
|
|
15
|
+
let reportError: jest.SpyInstance
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
19
|
+
openURL = jest.spyOn(Linking, 'openURL')
|
|
20
|
+
setStringAsync = jest.spyOn(Clipboard, 'setStringAsync').mockResolvedValue()
|
|
21
|
+
reportError = jest.spyOn(Log, 'reportError').mockImplementation(() => {})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
jest.restoreAllMocks()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('passes the url and options through to the Linking adapter', async () => {
|
|
29
|
+
openURL.mockResolvedValue(true)
|
|
30
|
+
|
|
31
|
+
await openUrl('https://youtu.be/abc', { forceOpenInBrowser: true })
|
|
32
|
+
|
|
33
|
+
expect(openURL).toHaveBeenCalledWith('https://youtu.be/abc', { forceOpenInBrowser: true })
|
|
34
|
+
expect(Alert.alert).not.toHaveBeenCalled()
|
|
35
|
+
expect(reportError).not.toHaveBeenCalled()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('reports a failed web link instead of alerting', async () => {
|
|
39
|
+
const error = new Error('Unable to open URL')
|
|
40
|
+
openURL.mockRejectedValue(error)
|
|
41
|
+
|
|
42
|
+
await openUrl('https://youtu.be/abc')
|
|
43
|
+
|
|
44
|
+
expect(reportError).toHaveBeenCalledWith(error, { extra: { url: 'https://youtu.be/abc' } })
|
|
45
|
+
expect(Alert.alert).not.toHaveBeenCalled()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
['mailto', 'mailto:admin@example.com', 'admin@example.com'],
|
|
50
|
+
['encoded mailto', encodeURI('mailto:first last@example.com'), 'first last@example.com'],
|
|
51
|
+
['tel', 'tel:+1 (555) 555-0100', '+1 (555) 555-0100'],
|
|
52
|
+
])('alerts and offers to copy the bare address for a %s link', async (_name, url, address) => {
|
|
53
|
+
openURL.mockRejectedValue(new Error('No Activity found'))
|
|
54
|
+
|
|
55
|
+
await openUrl(url)
|
|
56
|
+
|
|
57
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
58
|
+
'Oops',
|
|
59
|
+
`Unable to open: ${address}`,
|
|
60
|
+
expect.arrayContaining([expect.objectContaining({ text: 'Copy to clipboard' })])
|
|
61
|
+
)
|
|
62
|
+
expect(reportError).not.toHaveBeenCalled()
|
|
63
|
+
|
|
64
|
+
pressButton('Copy to clipboard')
|
|
65
|
+
expect(setStringAsync).toHaveBeenCalledWith(address)
|
|
66
|
+
})
|
|
67
|
+
})
|
package/src/utils/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './host_bridge'
|
|
|
10
10
|
export * from './liquid_glass'
|
|
11
11
|
export * from './membership_sync_info_text'
|
|
12
12
|
export * from './native_adapters'
|
|
13
|
+
export * from './open_url'
|
|
13
14
|
export * from './pluralize'
|
|
14
15
|
export * from './conversation_safety_constants'
|
|
15
16
|
export * from './reaction_constants'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Alert } from 'react-native'
|
|
2
|
+
import { Clipboard, Linking, Log } from './native_adapters'
|
|
3
|
+
import type { LinkingOpenURLOptions } from './native_adapters/linking'
|
|
4
|
+
|
|
5
|
+
const CONTACT_SCHEME = /^(mailto|tel):/i
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Opens a URL through the host's Linking adapter and never leaves the
|
|
9
|
+
* rejection unhandled.
|
|
10
|
+
*
|
|
11
|
+
* mailto: and tel: links fail for ordinary reasons (no mail app, no phone),
|
|
12
|
+
* so the user gets an alert offering to copy the address. Any other failure
|
|
13
|
+
* is reported through the Log adapter so it stays visible as a handled error.
|
|
14
|
+
*/
|
|
15
|
+
export function openUrl(url: string, options?: LinkingOpenURLOptions) {
|
|
16
|
+
return Linking.openURL(url, options).catch((error: unknown) => {
|
|
17
|
+
if (CONTACT_SCHEME.test(url)) {
|
|
18
|
+
alertUnableToOpen(url)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Log.reportError(toError(error, url), { extra: { url } })
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function alertUnableToOpen(url: string) {
|
|
27
|
+
const address = readableAddress(url)
|
|
28
|
+
|
|
29
|
+
Alert.alert('Oops', `Unable to open: ${address}`, [
|
|
30
|
+
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(address) },
|
|
31
|
+
{ text: 'OK' },
|
|
32
|
+
])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readableAddress(url: string) {
|
|
36
|
+
const address = url.replace(CONTACT_SCHEME, '')
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
return decodeURIComponent(address)
|
|
40
|
+
} catch {
|
|
41
|
+
return address
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function toError(error: unknown, url: string) {
|
|
46
|
+
return error instanceof Error ? error : new Error(`Unable to open URL: ${url}`)
|
|
47
|
+
}
|