@plusscommunities/pluss-core-web 1.7.3-beta.0 → 1.7.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/dist/components.js +390 -33094
- package/dist/components.js.map +1 -1
- package/dist/index.cjs.js +10388 -0
- package/dist/index.esm.js +10349 -0
- package/dist/index.js +394 -33098
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +10361 -0
- package/package.json +31 -22
- package/rollup.config.js +57 -0
- package/src/actions/AuthActions.js +83 -0
- package/src/actions/LocalActions.js +8 -0
- package/src/actions/NavActions.js +8 -0
- package/src/actions/ScheduledActionsActions.js +8 -0
- package/src/actions/TemplateActions.js +15 -0
- package/src/actions/UsersActions.js +95 -0
- package/src/actions/index.js +6 -0
- package/src/actions/types.js +23 -0
- package/src/analytics.js +183 -0
- package/src/apis/analyticsActions.js +53 -0
- package/src/apis/authActions.js +58 -0
- package/src/apis/fileActions.js +152 -0
- package/src/apis/index.js +10 -0
- package/src/apis/profileActions.js +133 -0
- package/src/apis/scheduledActionsActions.js +12 -0
- package/src/apis/stringActions.js +25 -0
- package/src/apis/templateActions.js +41 -0
- package/src/apis/typeActions.js +186 -0
- package/src/apis/userActions.js +169 -0
- package/src/apis/utilityActions.js +35 -0
- package/src/colours.js +134 -0
- package/src/components/AddButton.js +27 -0
- package/src/components/AnalyticsFilter.js +115 -0
- package/src/components/Attachment.js +27 -0
- package/src/components/AudienceIncluder.js +175 -0
- package/src/components/AudienceSelector.js +700 -0
- package/src/components/Button.js +66 -0
- package/src/components/CheckBox.js +77 -0
- package/src/components/ColourOptions.js +197 -0
- package/src/components/ColourPicker.js +267 -0
- package/src/components/Comment.js +46 -0
- package/src/components/CommentSection.js +116 -0
- package/src/components/DatePicker.js +290 -0
- package/src/components/DropdownInput.js +223 -0
- package/src/components/DurationInput.js +51 -0
- package/src/components/ExportCsvPopup.js +222 -0
- package/src/components/FileInput.js +389 -0
- package/src/components/GenericInput.js +169 -0
- package/src/components/Header.js +82 -0
- package/src/components/HubSidebar.js +134 -0
- package/src/components/ImageInput.js +987 -0
- package/src/components/InputGroup.js +18 -0
- package/src/components/MakerPopup.js +310 -0
- package/src/components/MoreMenu.js +22 -0
- package/src/components/OptionsSection.js +84 -0
- package/src/components/OverlayPage.js +74 -0
- package/src/components/OverlayPageBottomButtons.js +48 -0
- package/src/components/OverlayPageContents.js +48 -0
- package/src/components/OverlayPageSection.js +38 -0
- package/src/components/P60Icon.js +40 -0
- package/src/components/PageTitle.js +13 -0
- package/src/components/Popup.js +104 -0
- package/src/components/ProfilePic.js +50 -0
- package/src/components/RadioButton.js +144 -0
- package/src/components/Reactions.js +77 -0
- package/src/components/SVGIcon.js +33 -0
- package/src/components/SideNavItem.js +98 -0
- package/src/components/StatBox.js +49 -0
- package/src/components/StatusButton.js +22 -0
- package/src/components/SuccessPopup.js +57 -0
- package/src/components/Tabs.js +56 -0
- package/src/components/Tag.js +62 -0
- package/src/components/Text.js +20 -0
- package/src/components/TextFormatPopup.js +54 -0
- package/src/components/TimePicker.js +225 -0
- package/src/components/UserListing.js +111 -0
- package/src/components/index.js +46 -0
- package/src/components/svg-icons.json +821 -0
- package/src/config.js +25 -0
- package/src/helper/HelpDeskWidget.js +16 -0
- package/src/helper/api/getUrl.js +15 -0
- package/src/helper/api/getUrlParams.js +9 -0
- package/src/helper/api/safeReadParams.js +6 -0
- package/src/helper/auth/getUserFromState.js +8 -0
- package/src/helper/colours/getAppColourFromState.js +10 -0
- package/src/helper/files/canvasImageUploader.js +159 -0
- package/src/helper/files/generateImageName.js +10 -0
- package/src/helper/files/get1400.js +32 -0
- package/src/helper/files/getExtension.js +9 -0
- package/src/helper/files/getFileName.js +13 -0
- package/src/helper/files/getThumb300.js +36 -0
- package/src/helper/files/isVideo.js +8 -0
- package/src/helper/helper.js +97 -0
- package/src/helper/index.js +44 -0
- package/src/helper/site/getMerchantsFromState.js +9 -0
- package/src/helper/site/getSiteLevelFromState.js +34 -0
- package/src/helper/site/getSiteName.js +16 -0
- package/src/helper/site/getSiteNameFromRoles.js +12 -0
- package/src/helper/site/getSiteSettingFromState.js +10 -0
- package/src/helper/storage/readJSONFromStorage.js +9 -0
- package/src/helper/storage/readStorageWithCookie.js +22 -0
- package/src/helper/storage/setLocalStorage.js +5 -0
- package/src/helper/strings/getFirstName.js +10 -0
- package/src/helper/strings/htmlDecode.js +4 -0
- package/src/helper/strings/htmlEncode.js +4 -0
- package/src/helper/strings/isEmail.js +11 -0
- package/src/helper/strings/isUrl.js +13 -0
- package/src/helper/strings/onlyAlphanumeric.js +8 -0
- package/src/helper/strings/randomString.js +10 -0
- package/src/helper/strings/toParagraphed.js +17 -0
- package/src/index.js +12 -0
- package/src/reducers/ScheduledActionsReducer.js +14 -0
- package/src/reducers/TemplatesReducer.js +29 -0
- package/src/reducers/index.js +7 -0
- package/src/session.js +289 -0
- package/src/urls.js +21 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import FontAwesome from 'react-fontawesome';
|
|
5
|
+
import { CSVLink } from 'react-csv';
|
|
6
|
+
import { Popup } from './Popup';
|
|
7
|
+
import { CheckBox } from './CheckBox';
|
|
8
|
+
import { GenericInput } from './GenericInput';
|
|
9
|
+
import { DatePicker } from './DatePicker';
|
|
10
|
+
import { Text } from './Text';
|
|
11
|
+
|
|
12
|
+
class ExportCsvPopup extends Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
|
|
16
|
+
const state = {
|
|
17
|
+
columns: props.columns,
|
|
18
|
+
selectedHeaders: props.columns.filter((c) => c.key && c.selected),
|
|
19
|
+
selectedSource: [],
|
|
20
|
+
saving: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (props.timestampFilter) {
|
|
24
|
+
state.filterDateStart = props.timestampFilter.startDate;
|
|
25
|
+
state.filterDateEnd = props.timestampFilter.endDate;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.state = state;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canSave = () => {
|
|
32
|
+
return _.some(this.state.columns, (c) => c.selected);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
onConfirm = () => {
|
|
36
|
+
return this.canSave();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
onClose = () => {
|
|
40
|
+
if (this.props.onClose) this.props.onClose();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
onToggleColumn = (key) => {
|
|
44
|
+
const columns = _.cloneDeep(this.state.columns);
|
|
45
|
+
const column = columns.find((c) => c.key === key);
|
|
46
|
+
if (column) {
|
|
47
|
+
column.selected = !column.selected;
|
|
48
|
+
if (!column.key) columns.map((c) => (c.selected = column.selected)); // Toggle all
|
|
49
|
+
const selectedHeaders = columns.filter((c) => c.key && c.selected);
|
|
50
|
+
this.setState({ columns, selectedHeaders });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
onToggleStartDateFilter = () => {
|
|
55
|
+
const { filterDateStartVisible } = this.state;
|
|
56
|
+
if (filterDateStartVisible) {
|
|
57
|
+
setTimeout(() => this.setState({ filterDateStartVisible: false }), 200);
|
|
58
|
+
} else {
|
|
59
|
+
this.setState({ filterDateStartVisible: true });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
onToggleEndDateFilter = () => {
|
|
64
|
+
const { filterDateEndVisible } = this.state;
|
|
65
|
+
if (filterDateEndVisible) {
|
|
66
|
+
setTimeout(() => this.setState({ filterDateEndVisible: false }), 200);
|
|
67
|
+
} else {
|
|
68
|
+
this.setState({ filterDateEndVisible: true });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
onDateFilterStartChanged = (date) => {
|
|
73
|
+
const { filterDateEnd } = this.state;
|
|
74
|
+
const start = moment(date);
|
|
75
|
+
if (start.isSameOrBefore(filterDateEnd)) {
|
|
76
|
+
this.setState({ filterDateStart: start.startOf('day'), filterDateStartVisible: false });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
onDateFilterEndChanged = (date) => {
|
|
81
|
+
const { filterDateStart } = this.state;
|
|
82
|
+
const end = moment(date);
|
|
83
|
+
if (end.isSameOrAfter(filterDateStart)) {
|
|
84
|
+
this.setState({ filterDateEnd: end.endOf('day'), filterDateEndVisible: false });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
getSelectedSource = () => {
|
|
89
|
+
const { source } = this.props;
|
|
90
|
+
const { selectedHeaders } = this.state;
|
|
91
|
+
|
|
92
|
+
let result = source;
|
|
93
|
+
|
|
94
|
+
// apply timestamp filter
|
|
95
|
+
if (this.props.timestampFilter) {
|
|
96
|
+
const { filterDateStart, filterDateEnd } = this.state;
|
|
97
|
+
const { filterKey } = this.props.timestampFilter;
|
|
98
|
+
const minDate = filterDateStart.valueOf();
|
|
99
|
+
const maxDate = filterDateEnd.valueOf();
|
|
100
|
+
result = _.filter(source, (item) => {
|
|
101
|
+
return item[filterKey] >= minDate && item[filterKey] <= maxDate;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// map result to columns
|
|
106
|
+
const selectedheaderKeys = selectedHeaders.map((h) => h.key);
|
|
107
|
+
return result.map((i) => _.pick(i, selectedheaderKeys));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
renderTimestampFilter = () => {
|
|
111
|
+
if (!this.props.timestampFilter) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return (
|
|
115
|
+
<div>
|
|
116
|
+
<GenericInput
|
|
117
|
+
id="dateStart"
|
|
118
|
+
label="Start Date"
|
|
119
|
+
alwaysShowLabel
|
|
120
|
+
placeholder={'Select start date'}
|
|
121
|
+
value={this.state.filterDateStart.format('DD/MM/YYYY')}
|
|
122
|
+
onClick={this.onToggleStartDateFilter}
|
|
123
|
+
readOnly
|
|
124
|
+
/>
|
|
125
|
+
{this.state.filterDateStartVisible ? (
|
|
126
|
+
<DatePicker hideTop selectedDate={this.state.filterDateStart} selectDate={this.onDateFilterStartChanged} />
|
|
127
|
+
) : null}
|
|
128
|
+
<GenericInput
|
|
129
|
+
id="dateEnd"
|
|
130
|
+
label="End Date"
|
|
131
|
+
alwaysShowLabel
|
|
132
|
+
placeholder={'Select end date'}
|
|
133
|
+
value={this.state.filterDateEnd.format('DD/MM/YYYY')}
|
|
134
|
+
onClick={this.onToggleEndDateFilter}
|
|
135
|
+
readOnly
|
|
136
|
+
/>
|
|
137
|
+
{this.state.filterDateEndVisible ? (
|
|
138
|
+
<DatePicker hideTop selectedDate={this.state.filterDateEnd} selectDate={this.onDateFilterEndChanged} />
|
|
139
|
+
) : null}
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
renderContent = () => {
|
|
145
|
+
const { saving, columns } = this.state;
|
|
146
|
+
|
|
147
|
+
if (saving) {
|
|
148
|
+
return (
|
|
149
|
+
<div className="marginTop-32" style={{ maxWidth: 500, textAlign: 'center' }}>
|
|
150
|
+
<FontAwesome style={{ fontSize: 30 }} name="spinner fa-pulse fa-fw" />
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!columns) return null;
|
|
156
|
+
return (
|
|
157
|
+
<div className="marginTop-16">
|
|
158
|
+
{columns.map((c) => {
|
|
159
|
+
return (
|
|
160
|
+
<CheckBox
|
|
161
|
+
key={c.key}
|
|
162
|
+
label={c.label}
|
|
163
|
+
isActive={c.selected}
|
|
164
|
+
onChange={() => this.onToggleColumn(c.key)}
|
|
165
|
+
style={{ marginBottom: 8 }}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
})}
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
render() {
|
|
174
|
+
const { selectedHeaders } = this.state;
|
|
175
|
+
const { filename } = this.props;
|
|
176
|
+
|
|
177
|
+
const buttons = [
|
|
178
|
+
{
|
|
179
|
+
type: 'primary',
|
|
180
|
+
isActive: this.canSave(),
|
|
181
|
+
text: (
|
|
182
|
+
<CSVLink
|
|
183
|
+
headers={selectedHeaders}
|
|
184
|
+
data={this.getSelectedSource()}
|
|
185
|
+
style={{ textDecoration: 'none', color: '#fff' }}
|
|
186
|
+
filename={filename || 'export.csv'}
|
|
187
|
+
onClick={this.onConfirm}
|
|
188
|
+
>
|
|
189
|
+
Confirm
|
|
190
|
+
</CSVLink>
|
|
191
|
+
),
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
type: 'tertiary',
|
|
195
|
+
onClick: this.onClose,
|
|
196
|
+
isActive: true,
|
|
197
|
+
text: 'Close',
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<Popup
|
|
203
|
+
title="Confirm Export"
|
|
204
|
+
boxClasses="flex flex-column"
|
|
205
|
+
innerClasses="flex flex-column fillSpace flex-1"
|
|
206
|
+
minWidth={500}
|
|
207
|
+
maxWidth={500}
|
|
208
|
+
minHeight={'50vh'}
|
|
209
|
+
maxHeight={'100vh'}
|
|
210
|
+
hasPadding
|
|
211
|
+
onClose={this.onClose}
|
|
212
|
+
buttons={buttons}
|
|
213
|
+
>
|
|
214
|
+
{this.renderTimestampFilter()}
|
|
215
|
+
<Text type="bodyLarge">Select which columns to include in the export</Text>
|
|
216
|
+
{this.renderContent()}
|
|
217
|
+
</Popup>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { ExportCsvPopup };
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import { connect } from "react-redux";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
import Dropzone from "react-dropzone";
|
|
5
|
+
import FontAwesome from "react-fontawesome";
|
|
6
|
+
import { Button } from "./Button";
|
|
7
|
+
import { fileActions } from "../apis";
|
|
8
|
+
import { getFileName } from "../helper";
|
|
9
|
+
|
|
10
|
+
const DEFAULT_INPUT = {
|
|
11
|
+
uploadingFile: false,
|
|
12
|
+
value: "",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class FileInputComponent extends Component {
|
|
16
|
+
state = {
|
|
17
|
+
inputs: [
|
|
18
|
+
{
|
|
19
|
+
uploadingFile: false,
|
|
20
|
+
value: "",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
componentDidMount() {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
if (this.props.hasDefault) {
|
|
28
|
+
this.setState({
|
|
29
|
+
inputs: [
|
|
30
|
+
{
|
|
31
|
+
uploadingFile: false,
|
|
32
|
+
value: this.props.hasDefault,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
if (this.props.refreshCallback) {
|
|
37
|
+
this.props.refreshCallback(this.props.hasDefault);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, 100);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setValue(val) {
|
|
44
|
+
if (typeof val === "string") {
|
|
45
|
+
this.setState({
|
|
46
|
+
inputs: [
|
|
47
|
+
{
|
|
48
|
+
uploadingImage: false,
|
|
49
|
+
value: val,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
const inputs = [];
|
|
55
|
+
_.forEach(val, (str) => {
|
|
56
|
+
inputs.push({
|
|
57
|
+
uploadingImage: false,
|
|
58
|
+
value: str,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
if (!this.props.limit || this.props.limit > inputs.length)
|
|
62
|
+
inputs.push(DEFAULT_INPUT);
|
|
63
|
+
this.setState({ inputs });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getClassNames(input, inputsLength) {
|
|
68
|
+
let classes = "clearfix imageInput";
|
|
69
|
+
if (input.uploadingFile) {
|
|
70
|
+
classes += " imageInput-uploading";
|
|
71
|
+
} else if (!_.isEmpty(input.value) && !this.props.onlyAllowUpload) {
|
|
72
|
+
classes += " imageInput-hasImage";
|
|
73
|
+
}
|
|
74
|
+
if (inputsLength === 1) {
|
|
75
|
+
classes += " imageInput-only";
|
|
76
|
+
}
|
|
77
|
+
if (
|
|
78
|
+
this.props.style &&
|
|
79
|
+
this.props.style.height &&
|
|
80
|
+
this.props.style.height < 150
|
|
81
|
+
) {
|
|
82
|
+
classes += " imageInput-condensed";
|
|
83
|
+
}
|
|
84
|
+
return classes;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getErrorState() {
|
|
88
|
+
if (!_.isUndefined(this.props.showError) && this.props.showError()) {
|
|
89
|
+
return " imageInput_upload--error";
|
|
90
|
+
}
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getAccept = () => {
|
|
95
|
+
if (typeof this.props.accept === "object") {
|
|
96
|
+
return this.props.accept;
|
|
97
|
+
}
|
|
98
|
+
if (typeof this.props.accept === "string") {
|
|
99
|
+
const accept = {
|
|
100
|
+
[this.props.accept]: [`.${_.last(this.props.accept.split("/"))}`],
|
|
101
|
+
};
|
|
102
|
+
return accept;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
checkRefreshCallback = (inputs) => {
|
|
108
|
+
if (_.isUndefined(this.props.refreshCallback)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!this.props.multiple) {
|
|
112
|
+
const file = _.find(inputs, (i) => {
|
|
113
|
+
return !i.uploadingFile && !_.isEmpty(i.value);
|
|
114
|
+
});
|
|
115
|
+
this.props.refreshCallback(file ? file.value : undefined);
|
|
116
|
+
} else {
|
|
117
|
+
const files = _.filter(inputs, (i) => {
|
|
118
|
+
return !i.uploadingFile && !_.isEmpty(i.value);
|
|
119
|
+
}).map((i) => {
|
|
120
|
+
return i.value;
|
|
121
|
+
});
|
|
122
|
+
this.props.refreshCallback(files);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
checkSetDisplayValue(input, value) {
|
|
127
|
+
input.value = value;
|
|
128
|
+
input.uploadingFile = false;
|
|
129
|
+
const newInputs = _.clone(this.state.inputs);
|
|
130
|
+
this.setState({ inputs: newInputs });
|
|
131
|
+
this.checkRefreshCallback(newInputs);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
onDrop = (files) => {
|
|
135
|
+
if (this.props.multiple) {
|
|
136
|
+
const newInputs = _.clone(this.state.inputs);
|
|
137
|
+
files.forEach((file) => {
|
|
138
|
+
if (this.props.limit && newInputs.length === this.props.limit) {
|
|
139
|
+
// hit limit - replace last input if it's empty
|
|
140
|
+
if (_.isEmpty(newInputs[newInputs.length - 1].value)) {
|
|
141
|
+
const newInput = newInputs[newInputs.length - 1];
|
|
142
|
+
this.handleFile(newInput, file);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
const newInput = {
|
|
146
|
+
...DEFAULT_INPUT,
|
|
147
|
+
};
|
|
148
|
+
newInputs.splice(newInputs.length - 1, 0, newInput);
|
|
149
|
+
this.handleFile(newInput, file);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.setState({
|
|
153
|
+
inputs: newInputs,
|
|
154
|
+
});
|
|
155
|
+
this.checkRefreshCallback(newInputs);
|
|
156
|
+
} else {
|
|
157
|
+
this.handleFile(this.state.inputs[0], files[0]);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
handleFile = async (input, file) => {
|
|
162
|
+
if (!file || input.uploadingFile) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
input.uploadingFile = true;
|
|
166
|
+
const newInputs = _.clone(this.state.inputs);
|
|
167
|
+
this.setState({
|
|
168
|
+
inputs: newInputs,
|
|
169
|
+
});
|
|
170
|
+
this.checkRefreshCallback(newInputs);
|
|
171
|
+
if (this.props.handleFile) {
|
|
172
|
+
await this.props.handleFile(file, newInputs);
|
|
173
|
+
this.checkSetDisplayValue(input, "");
|
|
174
|
+
} else {
|
|
175
|
+
try {
|
|
176
|
+
let uploadFile = file;
|
|
177
|
+
const url = await fileActions.uploadMediaAsync(
|
|
178
|
+
uploadFile,
|
|
179
|
+
uploadFile.name,
|
|
180
|
+
);
|
|
181
|
+
this.checkSetDisplayValue(input, url);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.log("handleFile error", error);
|
|
184
|
+
this.setState({ uploadingFile: false });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
removeFile(input) {
|
|
190
|
+
const newState = {};
|
|
191
|
+
|
|
192
|
+
input.value = "";
|
|
193
|
+
|
|
194
|
+
const newInputs = _.clone(this.state.inputs);
|
|
195
|
+
|
|
196
|
+
if (newInputs.length > 1) {
|
|
197
|
+
newInputs.splice(newInputs.indexOf(input), 1);
|
|
198
|
+
if (
|
|
199
|
+
newInputs.length === this.props.limit - 1 &&
|
|
200
|
+
!_.isEmpty(newInputs[newInputs.length - 1].value)
|
|
201
|
+
) {
|
|
202
|
+
// was full
|
|
203
|
+
newInputs.push(DEFAULT_INPUT);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
newState.inputs = newInputs;
|
|
208
|
+
|
|
209
|
+
this.setState(newState);
|
|
210
|
+
// for single item
|
|
211
|
+
if (!_.isUndefined(this.props.refreshCallback)) {
|
|
212
|
+
this.props.refreshCallback();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
renderInput(input, index, inputsLength) {
|
|
217
|
+
const renderContent = () => {
|
|
218
|
+
if (this.props.onlyAllowUpload) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
if (!_.isEmpty(input.value) && !input.uploadingFile) {
|
|
222
|
+
return (
|
|
223
|
+
<div className="imageInput_simpleContainer">
|
|
224
|
+
<div
|
|
225
|
+
className="imageInput_image"
|
|
226
|
+
style={{
|
|
227
|
+
...this.props.style,
|
|
228
|
+
height:
|
|
229
|
+
this.props.style && this.props.style.height
|
|
230
|
+
? this.props.style.height - 62
|
|
231
|
+
: 80,
|
|
232
|
+
}}
|
|
233
|
+
>
|
|
234
|
+
<img
|
|
235
|
+
src="https://s3-ap-southeast-2.amazonaws.com/pluss60-dev-media/pluss/document.svg"
|
|
236
|
+
className="imageInput_icon"
|
|
237
|
+
alt="file"
|
|
238
|
+
/>
|
|
239
|
+
<p className="imageInput_text">{getFileName(input.value)}</p>
|
|
240
|
+
</div>
|
|
241
|
+
<Dropzone
|
|
242
|
+
accept={this.getAccept()}
|
|
243
|
+
onDrop={(files) => this.onDrop(files, true)}
|
|
244
|
+
>
|
|
245
|
+
{(state) => {
|
|
246
|
+
const { getRootProps, getInputProps } = state;
|
|
247
|
+
return (
|
|
248
|
+
<div style={{ padding: 10 }} {...getRootProps()}>
|
|
249
|
+
<input {...getInputProps()} />
|
|
250
|
+
<Button
|
|
251
|
+
buttonType="secondary"
|
|
252
|
+
className="imageInput_button"
|
|
253
|
+
disabled
|
|
254
|
+
>
|
|
255
|
+
Change file
|
|
256
|
+
</Button>
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}}
|
|
260
|
+
</Dropzone>
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return (
|
|
265
|
+
<div className="imageInput_image" style={{ ...this.props.style }}></div>
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const renderRemove = () => {
|
|
270
|
+
return (
|
|
271
|
+
!this.props.disableRemove &&
|
|
272
|
+
!this.props.disabled &&
|
|
273
|
+
(this.props.simpleStyle ? (
|
|
274
|
+
<FontAwesome
|
|
275
|
+
name="remove"
|
|
276
|
+
className="imageInput_removeIcon"
|
|
277
|
+
onClick={this.removeFile.bind(this, input)}
|
|
278
|
+
/>
|
|
279
|
+
) : (
|
|
280
|
+
<p
|
|
281
|
+
className="imageInput_remove"
|
|
282
|
+
onClick={this.removeFile.bind(this, input)}
|
|
283
|
+
>
|
|
284
|
+
remove
|
|
285
|
+
</p>
|
|
286
|
+
))
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const renderDownload = () => {
|
|
291
|
+
if (this.props.noDownload) return null;
|
|
292
|
+
return (
|
|
293
|
+
<a href={input.value} target="_blank" className="imageInput_download">
|
|
294
|
+
<img
|
|
295
|
+
alt=""
|
|
296
|
+
className="dlicon"
|
|
297
|
+
src="https://pluss60-dev-uploads.s3.ap-southeast-2.amazonaws.com/uploads/users/ap-southeast-2:efbab8db-136a-446e-b14a-d00af0067841/public/025971e94153af280049fdf3e3/downloadicon.png"
|
|
298
|
+
></img>
|
|
299
|
+
</a>
|
|
300
|
+
);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<div
|
|
305
|
+
key={index}
|
|
306
|
+
className={this.getClassNames(input, inputsLength)}
|
|
307
|
+
style={{ ...this.props.style }}
|
|
308
|
+
>
|
|
309
|
+
<Dropzone accept={this.getAccept()} onDrop={this.onDrop}>
|
|
310
|
+
{(state) => {
|
|
311
|
+
const { getRootProps, getInputProps, isDragActive } = state;
|
|
312
|
+
return (
|
|
313
|
+
<div
|
|
314
|
+
className={`imageInput_upload ${this.getErrorState()}`}
|
|
315
|
+
style={{ ...this.props.style }}
|
|
316
|
+
{...getRootProps()}
|
|
317
|
+
>
|
|
318
|
+
<input {...getInputProps()} />
|
|
319
|
+
<div
|
|
320
|
+
className={`${isDragActive ? "imageInput_dropZoneActive" : ""}`}
|
|
321
|
+
>
|
|
322
|
+
{!this.props.simpleStyle && (
|
|
323
|
+
<img
|
|
324
|
+
src="https://s3-ap-southeast-2.amazonaws.com/pluss60-dev-media/pluss/document.svg"
|
|
325
|
+
className="imageInput_icon"
|
|
326
|
+
alt="file"
|
|
327
|
+
/>
|
|
328
|
+
)}
|
|
329
|
+
<p className="imageInput_helpText">
|
|
330
|
+
{isDragActive ? `Drop file here` : `Drag and drop file or`}
|
|
331
|
+
</p>
|
|
332
|
+
{!isDragActive && (
|
|
333
|
+
<Button
|
|
334
|
+
buttonType="secondary"
|
|
335
|
+
className="imageInput_button"
|
|
336
|
+
disabled
|
|
337
|
+
>
|
|
338
|
+
{this.props.multiple ? `Upload files` : `Upload a file`}
|
|
339
|
+
</Button>
|
|
340
|
+
)}
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
);
|
|
344
|
+
}}
|
|
345
|
+
</Dropzone>
|
|
346
|
+
<div className="imageInput_uploading" style={{ ...this.props.style }}>
|
|
347
|
+
<FontAwesome
|
|
348
|
+
className="spinner imageInput_spinner"
|
|
349
|
+
name="spinner fa-pulse fa-fw"
|
|
350
|
+
/>
|
|
351
|
+
</div>
|
|
352
|
+
{renderContent()}
|
|
353
|
+
{renderRemove()}
|
|
354
|
+
{renderDownload()}
|
|
355
|
+
</div>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
renderUploadFiles(inputs) {
|
|
360
|
+
return (
|
|
361
|
+
<div
|
|
362
|
+
className={`imageInputContainer clearfix ${inputs.length === 1 ? "imageInputContainer-noPadding" : ""} ${this.props.simpleStyle ? "imageInputContainer-simple" : ""
|
|
363
|
+
}`}
|
|
364
|
+
style={{ ...this.props.style }}
|
|
365
|
+
>
|
|
366
|
+
{inputs.map((input, index) => {
|
|
367
|
+
return this.renderInput(input, index, inputs.length);
|
|
368
|
+
})}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
renderContent() {
|
|
374
|
+
return this.renderUploadFiles(this.state.inputs);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
render() {
|
|
378
|
+
return <div style={this.props.containerStyle}>{this.renderContent()}</div>;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const mapStateToProps = () => {
|
|
383
|
+
return {};
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const FileInput = connect(mapStateToProps, {}, null, { forwardRef: true })(
|
|
387
|
+
FileInputComponent,
|
|
388
|
+
);
|
|
389
|
+
export { FileInput };
|