1 | import qs from 'query-string';
|
2 | import { MailComposerStatus } from './MailComposer.types';
|
3 | function removeNullishValues(obj) {
|
4 | for (const propName in obj) {
|
5 | if (obj[propName] == null) {
|
6 | delete obj[propName];
|
7 | }
|
8 | }
|
9 | return obj;
|
10 | }
|
11 | function checkValue(value) {
|
12 | if (!value) {
|
13 | return null;
|
14 | }
|
15 | const arr = Array.isArray(value) ? value : [value];
|
16 | return arr.join(',');
|
17 | }
|
18 | export default {
|
19 | get name() {
|
20 | return 'ExpoMailComposer';
|
21 | },
|
22 | async composeAsync(options) {
|
23 | const email = removeNullishValues({
|
24 | cc: checkValue(options.ccRecipients),
|
25 | bcc: checkValue(options.bccRecipients),
|
26 | subject: options.subject,
|
27 | body: options.body,
|
28 | });
|
29 | const query = qs.stringify(email);
|
30 | const queryComponent = query ? '?' + query : '';
|
31 | const to = checkValue(options.recipients) || '';
|
32 | const mailto = `mailto:${to}${queryComponent}`;
|
33 | window.open(mailto);
|
34 | return { status: MailComposerStatus.UNDETERMINED };
|
35 | },
|
36 | async isAvailableAsync() {
|
37 | return true;
|
38 | },
|
39 | };
|
40 |
|
\ | No newline at end of file |