-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
66 lines (51 loc) · 1.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import {
NativeModules,
NativeEventEmitter,
requireNativeComponent
} from 'react-native';
import PropTypes from 'prop-types';
class Helpshift extends React.Component {
render() {
return <RNTHelpshift {...this.props} />;
}
}
Helpshift.propTypes = {
config: PropTypes.shape({
apiKey: PropTypes.string.isRequired,
domain: PropTypes.string.isRequired,
appId: PropTypes.string.isRequired,
height: PropTypes.number,
width: PropTypes.number,
user: PropTypes.shape({
identifier: PropTypes.string.isRequired,
email: PropTypes.string,
name: PropTypes.string,
authToken: PropTypes.string
}),
cifs: PropTypes.object
}).isRequired
};
const { RNHelpshift } = NativeModules;
const HelpshiftEventEmitter = Helpshift.eventEmitter = new NativeEventEmitter(RNHelpshift);
Helpshift.init = (apiKey, domain, appId) => RNHelpshift.init(apiKey, domain, appId);
// TODO: Rerender Helpshift view on iOS if using <Helpshift/>
Helpshift.login = user => RNHelpshift.login(user)
Helpshift.logout = user => RNHelpshift.logout();
Helpshift.showConversation = () => RNHelpshift.showConversation();
Helpshift.showFAQs = () => RNHelpshift.showFAQs();
Helpshift.showConversationWithCIFs = cifs => RNHelpshift.showConversationWithCIFs(cifs);
Helpshift.showFAQsWithCIFs = cifs => RNHelpshift.showFAQsWithCIFs(cifs);
Helpshift.requestUnreadMessagesCount = () => {
return new Promise((resolve, reject) => {
const subscription = HelpshiftEventEmitter.addListener('Helpshift/DidReceiveUnreadMessagesCount',
({ count }) => {
resolve(count);
subscription.remove();
}
);
RNHelpshift.requestUnreadMessagesCount();
});
}
var RNTHelpshift = requireNativeComponent('RNTHelpshift', Helpshift);
export default Helpshift;