-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (53 loc) · 1.22 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
import React, { Component } from 'react';
import PropTypes from 'prop-types'
export default class CustomerChat extends Component {
constructor() {
super();
this.state = {
};
}
componentDidMount() {
this.getInit()
this.setupSdk()
}
getInit() {
const { xfbml, version } = this.props
window.fbAsyncInit = function () {
FB.init({
xfbml,
version
});
};
}
setupSdk() {
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
render() {
const { pageId, attribute } = this.props;
return (
<div>
<div className="fb-customerchat"
{...attribute}
page_id={pageId}>
</div>
</div>
);
}
}
const propTypes = {
pageId: PropTypes.string.isRequired,
xfbml: PropTypes.bool,
version: PropTypes.string,
}
const defaultProps = {
xfbml: true,
version: 'v3.2'
}
CustomerChat.propTypes = propTypes
CustomerChat.defaultProps = defaultProps