|
1 | 1 | // @flow |
2 | 2 |
|
3 | 3 | import * as React from 'react' |
4 | | -import {Alert, StyleSheet, Clipboard} from 'react-native' |
| 4 | +import {StyleSheet} from 'react-native' |
5 | 5 | import {Card} from '../components/card' |
6 | 6 | import {Button} from '../components/button' |
7 | 7 | import {Markdown} from '../components/markdown' |
8 | | -import actualOpenUrl from '../components/open-url' |
9 | | -import {email, phonecall} from 'react-native-communications' |
| 8 | +import {openUrl} from '../components/open-url' |
| 9 | +import {sendEmail} from '../components/send-email' |
| 10 | +import {callPhone} from '../components/call-phone' |
10 | 11 | import type { |
11 | 12 | ToolOptions, |
12 | 13 | CallPhoneButtonParams, |
13 | 14 | SendEmailButtonParams, |
14 | 15 | OpenUrlButtonParams, |
15 | 16 | } from './types' |
16 | 17 |
|
17 | | -function callPhone(params: CallPhoneButtonParams) { |
18 | | - try { |
19 | | - phonecall(params.number, true) |
20 | | - } catch (err) { |
21 | | - Alert.alert( |
22 | | - "Apologies, we couldn't call that number", |
23 | | - `We were trying to call "${params.number}".`, |
24 | | - [ |
25 | | - { |
26 | | - text: 'Darn', |
27 | | - onPress: () => {}, |
28 | | - }, |
29 | | - { |
30 | | - text: 'Copy addresses', |
31 | | - onPress: () => Clipboard.setString(params.number), |
32 | | - }, |
33 | | - ], |
34 | | - ) |
35 | | - } |
| 18 | +function handleCallPhone(params: CallPhoneButtonParams) { |
| 19 | + callPhone(params.number) |
36 | 20 | } |
37 | 21 |
|
38 | | -function sendEmail(params: SendEmailButtonParams) { |
| 22 | +function handleSendEmail(params: SendEmailButtonParams) { |
39 | 23 | let {to, cc = [], bcc = [], subject, body} = params |
40 | 24 | to = Array.isArray(to) ? to : [to] |
41 | 25 | cc = Array.isArray(cc) ? cc : [cc] |
42 | 26 | bcc = Array.isArray(bcc) ? bcc : [bcc] |
43 | | - |
44 | | - try { |
45 | | - email(to, cc, bcc, subject, body) |
46 | | - } catch (err) { |
47 | | - const toString = to.join(', ') |
48 | | - |
49 | | - Alert.alert( |
50 | | - "Apologies, we couldn't open an email client", |
51 | | - `We were trying to email "${toString}".`, |
52 | | - [ |
53 | | - { |
54 | | - text: 'Darn', |
55 | | - onPress: () => {}, |
56 | | - }, |
57 | | - { |
58 | | - text: 'Copy addresses', |
59 | | - onPress: () => Clipboard.setString(toString), |
60 | | - }, |
61 | | - ], |
62 | | - ) |
63 | | - } |
| 27 | + sendEmail({to, cc, bcc, subject, body}) |
64 | 28 | } |
65 | 29 |
|
66 | | -function openUrl(params: OpenUrlButtonParams) { |
67 | | - return actualOpenUrl(params.url) |
| 30 | +function handleOpenUrl(params: OpenUrlButtonParams) { |
| 31 | + return openUrl(params.url) |
68 | 32 | } |
69 | 33 |
|
70 | 34 | function handleButtonPress(btn) { |
71 | 35 | switch (btn.action) { |
72 | 36 | case 'open-url': |
73 | | - return openUrl(btn.params) |
| 37 | + return handleOpenUrl(btn.params) |
74 | 38 | case 'send-email': |
75 | | - return sendEmail(btn.params) |
| 39 | + return handleSendEmail(btn.params) |
76 | 40 | case 'call-phone': |
77 | | - return callPhone(btn.params) |
| 41 | + return handleCallPhone(btn.params) |
78 | 42 | default: |
79 | 43 | ;(btn.action: empty) |
80 | 44 | } |
|
0 commit comments