/
Row.tsx
147 lines (120 loc) · 3.27 KB
/
Row.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 Pagination from 'modules/common/components/pagination/Pagination';
import { __ } from 'modules/common/utils';
import IntegrationList from 'modules/settings/integrations/containers/common/IntegrationList';
import MessengerAppList from 'modules/settings/integrations/containers/MessengerAppList';
import React from 'react';
import { Collapse } from 'react-bootstrap';
import StoreEntry from '../../containers/StoreEntry';
import Entry from './Entry';
import { CollapsibleContent, IntegrationRow } from './styles';
type Props = {
integrations: any[];
title?: string;
totalCount: {
messenger: number;
form: number;
facebook: number;
gmail: number;
};
queryParams: any;
};
type State = {
isContentVisible: boolean;
kind: string | null;
};
class Row extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
isContentVisible: false,
kind: null
};
}
getClassName = selectedKind => {
const { kind, isContentVisible } = this.state;
if (!isContentVisible) {
return '';
}
if (selectedKind === kind) {
return 'active';
}
return '';
};
toggleBox = selectedKind => {
if (!selectedKind || selectedKind === 'amazon-ses') {
return false;
}
const { isContentVisible, kind } = this.state;
this.setState(prevState => {
if (
prevState.kind === selectedKind ||
kind === null ||
!isContentVisible
) {
return { isContentVisible: !isContentVisible, kind: selectedKind };
}
return {
kind: selectedKind,
isContentVisible: prevState.isContentVisible
};
});
return null;
};
renderPagination(totalCount) {
if (!totalCount || totalCount <= 20) {
return null;
}
return <Pagination count={totalCount} />;
}
isMessengerApp(kind: string | null) {
if (kind === 'lead' || kind === 'knowledgebase') {
return true;
}
return false;
}
renderEntry(integration, totalCount, queryParams) {
const kind = integration.kind;
const commonProp = {
key: integration.name,
integration,
toggleBox: this.toggleBox,
getClassName: this.getClassName,
totalCount,
queryParams
};
if (this.isMessengerApp(kind)) {
return <StoreEntry {...commonProp} kind={kind} />;
}
return <Entry {...commonProp} />;
}
renderList() {
const { queryParams, totalCount } = this.props;
const { kind } = this.state;
if (this.isMessengerApp(kind)) {
return <MessengerAppList kind={kind} queryParams={queryParams} />;
}
return (
<>
<IntegrationList kind={kind} queryParams={queryParams} />
{this.renderPagination(totalCount[kind || ''])}
</>
);
}
render() {
const { integrations, title, totalCount, queryParams } = this.props;
return (
<>
{title && <h3>{__(title)}</h3>}
<IntegrationRow>
{integrations.map(integration =>
this.renderEntry(integration, totalCount, queryParams)
)}
</IntegrationRow>
<Collapse in={this.state.isContentVisible} unmountOnExit={true}>
<CollapsibleContent>{this.renderList()}</CollapsibleContent>
</Collapse>
</>
);
}
}
export default Row;