/
IntegrationList.tsx
147 lines (125 loc) · 3.63 KB
/
IntegrationList.tsx
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import ActionButtons from 'modules/common/components/ActionButtons';
import Button from 'modules/common/components/Button';
import EmptyState from 'modules/common/components/EmptyState';
import Icon from 'modules/common/components/Icon';
import Label from 'modules/common/components/Label';
import ModalTrigger from 'modules/common/components/ModalTrigger';
import Table from 'modules/common/components/table';
import Tip from 'modules/common/components/Tip';
import { __ } from 'modules/common/utils';
import InstallCode from 'modules/settings/integrations/components/InstallCode';
import { KIND_CHOICES } from 'modules/settings/integrations/constants';
import React from 'react';
import { Link } from 'react-router-dom';
import { IIntegration } from '../../types';
type Props = {
integrations: IIntegration[];
removeIntegration: (integration: IIntegration, callback?: any) => void;
};
class IntegrationList extends React.Component<Props> {
getTypeName(integration) {
const kind = integration.kind;
if (kind === KIND_CHOICES.FACEBOOK) {
return 'facebook';
}
if (kind === KIND_CHOICES.GMAIL) {
return 'gmail';
}
if (kind === KIND_CHOICES.FORM) {
return 'form';
}
if (kind === KIND_CHOICES.CALLPRO) {
return 'callpro';
}
return 'default';
}
renderMessengerActions(integration) {
const kind = integration.kind;
if (kind === KIND_CHOICES.MESSENGER) {
const editTrigger = (
<Button btnStyle="link">
<Tip text="Install code">
<Icon icon="copy" />
</Tip>
</Button>
);
const content = props => (
<InstallCode {...props} integration={integration} />
);
return (
<ActionButtons>
<Tip text={__('Edit messenger integration')}>
<Link
to={`/settings/integrations/editMessenger/${integration._id}`}
>
<Button btnStyle="link" icon="edit" />
</Link>
</Tip>
<ModalTrigger
title="Install code"
size="lg"
trigger={editTrigger}
content={content}
/>
</ActionButtons>
);
}
return null;
}
renderRemoveAction(integration) {
const { removeIntegration } = this.props;
if (!removeIntegration) {
return null;
}
const onClick = () => removeIntegration(integration);
return (
<Tip text={__('Delete')}>
<Button btnStyle="link" onClick={onClick} icon="cancel-1" />
</Tip>
);
}
renderRow(integration) {
return (
<tr key={integration._id}>
<td>{integration.name}</td>
<td>
<Label className={`label-${this.getTypeName(integration)}`}>
{integration.kind}
</Label>
</td>
<td>{integration.brand ? integration.brand.name : ''}</td>
<td>
<ActionButtons>
{this.renderMessengerActions(integration)}
{this.renderRemoveAction(integration)}
</ActionButtons>
</td>
</tr>
);
}
render() {
const { integrations } = this.props;
if (!integrations || integrations.length < 1) {
return (
<EmptyState
text="Start adding integrations now!"
image="/images/actions/2.svg"
/>
);
}
return (
<Table>
<thead>
<tr>
<th>{__('Name')}</th>
<th>{__('Kind')}</th>
<th>{__('Brand')}</th>
<th>{__('Actions')}</th>
</tr>
</thead>
<tbody>{integrations.map(i => this.renderRow(i))}</tbody>
</Table>
);
}
}
export default IntegrationList;