@plusscommunities/pluss-newsletter-web-sharing 1.2.8

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.
Files changed (52) hide show
  1. package/.babelrc +3 -0
  2. package/dist/index.cjs.js +7451 -0
  3. package/dist/index.esm.js +7399 -0
  4. package/dist/index.umd.js +7434 -0
  5. package/package.default.json +43 -0
  6. package/package.json +45 -0
  7. package/package.test.json +43 -0
  8. package/rollup.config.js +59 -0
  9. package/src/actions/NewsActions.js +102 -0
  10. package/src/actions/index.js +9 -0
  11. package/src/actions/types.js +10 -0
  12. package/src/components/ActivityText.js +73 -0
  13. package/src/components/MakerPopup/index.js +3 -0
  14. package/src/components/PreviewFull.js +32 -0
  15. package/src/components/PreviewGrid.js +19 -0
  16. package/src/components/PreviewWidget.js +28 -0
  17. package/src/components/Reactions/index.js +3 -0
  18. package/src/components/ViewFull.js +19 -0
  19. package/src/components/ViewWidget.js +17 -0
  20. package/src/components/index.js +25 -0
  21. package/src/components/text/index.js +4 -0
  22. package/src/config/index.js +9 -0
  23. package/src/feature.config.default.js +235 -0
  24. package/src/feature.config.js +235 -0
  25. package/src/feature.config.sharing.js +235 -0
  26. package/src/feature.config.test.js +235 -0
  27. package/src/helper/index.js +17 -0
  28. package/src/images/full.png +0 -0
  29. package/src/images/fullNoTitle.png +0 -0
  30. package/src/images/fullNoTitleCondensed.png +0 -0
  31. package/src/images/previewWidget.png +0 -0
  32. package/src/images/widget.png +0 -0
  33. package/src/index.js +33 -0
  34. package/src/js/Events.js +26 -0
  35. package/src/js/index.js +20 -0
  36. package/src/reducers/NewsReducer.js +82 -0
  37. package/src/screens/Newsletter/AddNewsletterEntry.js +1186 -0
  38. package/src/screens/Newsletter/AvailableNews.js +124 -0
  39. package/src/screens/Newsletter/GenerateNewsletter.js +891 -0
  40. package/src/screens/Newsletter/ListNewsletterEntries.js +234 -0
  41. package/src/screens/Newsletter/NewsHub.js +328 -0
  42. package/src/screens/Newsletter/NewsHubAnalytics.js +320 -0
  43. package/src/screens/Newsletter/NewsletterAnalytics.js +140 -0
  44. package/src/screens/Newsletter/NewsletterSubmission.js +476 -0
  45. package/src/screens/Newsletter/NewsletterSubmissions.js +278 -0
  46. package/src/screens/Newsletter/NewsletterTemplate.js +1051 -0
  47. package/src/screens/Newsletter/PublishAvailableNews.js +450 -0
  48. package/src/session/index.js +7 -0
  49. package/src/webapi/eventActions.js +18 -0
  50. package/src/webapi/helper.js +4 -0
  51. package/src/webapi/index.js +11 -0
  52. package/src/webapi/newsletterActions.js +153 -0
@@ -0,0 +1,476 @@
1
+ import React, { Component } from 'react';
2
+ import _ from 'lodash';
3
+ import moment from 'moment';
4
+ import FontAwesome from 'react-fontawesome';
5
+ import { connect } from 'react-redux';
6
+ import { removeNewsSubmission, newsSubmissionsLoaded } from '../../actions';
7
+ import {
8
+ GenericInput,
9
+ ImageInput,
10
+ Button,
11
+ OverlayPage,
12
+ OverlayPageContents,
13
+ OverlayPageSection,
14
+ OverlayPageBottomButtons,
15
+ SuccessPopup,
16
+ } from '../../components';
17
+ import { newsletterActions } from '../../webapi';
18
+ import { safeReadParams, getThumb300, get1400 } from '../../helper';
19
+ import { checkLoggedIn } from '../../session';
20
+ import { COLOUR_BRANDING_MAIN, COLOUR_BRANDING_OFF } from '../../js';
21
+ import { values } from '../../feature.config';
22
+
23
+ class NewsletterSubmission extends Component {
24
+ initialState = {
25
+ updateId: safeReadParams(this.props, 'updateId'),
26
+ success: false,
27
+ submitting: false,
28
+ editSubmitting: false,
29
+ showEditWarnings: false,
30
+ updating: false,
31
+ update: {},
32
+ newUpdate: {},
33
+ action: '',
34
+ };
35
+
36
+ state = { ...this.initialState };
37
+
38
+ UNSAFE_componentWillMount() {
39
+ checkLoggedIn(this, this.props.auth);
40
+
41
+ if (this.state.updateId) {
42
+ this.getData();
43
+ }
44
+ }
45
+
46
+ handleChange(event) {
47
+ var stateChange = { newUpdate: { ...this.state.newUpdate } };
48
+ stateChange.newUpdate[event.target.getAttribute('id')] = event.target.value;
49
+ this.setState(stateChange);
50
+ }
51
+
52
+ getData() {
53
+ newsletterActions.getNewsletterSubmission(this.state.updateId).then((res) => {
54
+ this.setState({
55
+ update: res.data,
56
+ newUpdate: res.data,
57
+ });
58
+ });
59
+ }
60
+
61
+ getDate() {
62
+ if (!this.state.update.Timestamp) {
63
+ return '';
64
+ }
65
+ return moment.utc(this.state.update.Timestamp).local().format('D MMM');
66
+ }
67
+
68
+ validateForm() {
69
+ if (this.state.submitting) {
70
+ return false;
71
+ }
72
+ return true;
73
+ }
74
+
75
+ handleSubmit(action) {
76
+ if (!this.validateForm()) {
77
+ this.setState({ showWarnings: true });
78
+ return;
79
+ }
80
+ if (
81
+ window.confirm(
82
+ action === 'accept'
83
+ ? 'Approving this post will make it visible to everyone in the app. Are you sure you want to continue?'
84
+ : 'Rejecting this post will remove it from the system. Are you sure you want to continue?',
85
+ )
86
+ ) {
87
+ this.setState({ submitting: true, action });
88
+
89
+ newsletterActions
90
+ .handleNewsletterSubmission(this.props.auth.site, this.state.updateId, action)
91
+ .then((res) => {
92
+ this.setState({
93
+ success: true,
94
+ submitting: false,
95
+ });
96
+ this.props.removeNewsSubmission(this.state.updateId);
97
+ })
98
+ .catch((res) => {
99
+ this.setState({ submitting: false });
100
+ alert('Something went wrong with the request. Please try again.');
101
+ });
102
+ }
103
+ }
104
+
105
+ renderSuccess() {
106
+ if (!this.state.success) {
107
+ return null;
108
+ }
109
+ return (
110
+ <SuccessPopup
111
+ text={`Update has been ${this.state.action === 'accept' ? 'approved' : 'rejected'}`}
112
+ buttons={[
113
+ {
114
+ type: 'outlined',
115
+ onClick: () => {
116
+ window.history.back();
117
+ },
118
+ text: 'Go to home',
119
+ },
120
+ ]}
121
+ />
122
+ );
123
+ }
124
+
125
+ checkSetImage() {
126
+ if (this.refs.imageInput) {
127
+ if (this.state.newUpdate.Images) {
128
+ this.refs.imageInput.getWrappedInstance().setValue(this.state.newUpdate.Images);
129
+ } else {
130
+ this.refs.imageInput.getWrappedInstance().setValue(this.state.newUpdate.Image);
131
+ }
132
+ } else {
133
+ setTimeout(() => {
134
+ this.checkSetImage();
135
+ }, 100);
136
+ }
137
+ }
138
+
139
+ validateLoading() {
140
+ if (this.state.submitting) {
141
+ return false;
142
+ }
143
+ return true;
144
+ }
145
+
146
+ validateImage() {
147
+ if (_.isEmpty(this.state.newUpdate.Image)) {
148
+ return true;
149
+ }
150
+ return this.state.newUpdate.Image.match(/\.(jpeg|jpg|gif|png|ashx)/) != null;
151
+ }
152
+
153
+ validateCompulsoryText() {
154
+ if (_.isEmpty(this.state.newUpdate.Title)) {
155
+ return false;
156
+ }
157
+ if (_.isEmpty(this.state.newUpdate.Text)) {
158
+ return false;
159
+ }
160
+ return true;
161
+ }
162
+
163
+ validateEditForm() {
164
+ if (!this.validateCompulsoryText()) {
165
+ return false;
166
+ }
167
+ if (!this.validateImage()) {
168
+ return false;
169
+ }
170
+ if (this.state.editSubmitting) {
171
+ return false;
172
+ }
173
+ return true;
174
+ }
175
+
176
+ setTags(input) {
177
+ const tags = [];
178
+
179
+ if (!_.isEmpty(this.state.newUpdate.Tags)) {
180
+ this.state.newUpdate.Tags.split(',').forEach((tag) => {
181
+ if (!_.isEmpty(tag)) {
182
+ tags.push(tag.trim());
183
+ }
184
+ });
185
+ }
186
+
187
+ input.Tags = tags;
188
+ }
189
+
190
+ compileJson() {
191
+ const result = {
192
+ ...this.state.newUpdate,
193
+ Image: '',
194
+ Images: this.refs.imageInput
195
+ .getWrappedInstance()
196
+ .getValue()
197
+ .map((url) => {
198
+ return get1400(url);
199
+ }),
200
+ Thumbnail: '',
201
+ };
202
+ if (!_.isEmpty(result.Images)) {
203
+ result.Thumbnail = getThumb300(result.Images[0]);
204
+ result.Image = get1400(result.Images[0]);
205
+ }
206
+
207
+ result.EditedBy = {
208
+ displayName: this.props.auth.user.displayName,
209
+ id: this.props.auth.user.uid,
210
+ };
211
+
212
+ this.setTags(result);
213
+
214
+ return result;
215
+ }
216
+
217
+ handleEditSubmit() {
218
+ if (!this.validateEditForm()) {
219
+ this.setState({ showEditWarnings: true });
220
+ return;
221
+ }
222
+ this.setState({ showEditWarnings: false, editSubmitting: true });
223
+ const data = this.compileJson();
224
+
225
+ newsletterActions
226
+ .editNewsletterSubmission(this.props.auth.site, this.state.updateId, data)
227
+ .then((res) => {
228
+ this.setState({
229
+ update: { ...data },
230
+ edit: false,
231
+ editSubmitting: false,
232
+ });
233
+ this.getData();
234
+ this.props.newsSubmissionsLoaded([data]);
235
+ })
236
+ .catch((res) => {
237
+ this.setState({ editSubmitting: false });
238
+ alert('Something went wrong with the submission. Please try again.');
239
+ });
240
+ }
241
+
242
+ setEditForm() {
243
+ const newUpdate = {
244
+ ...this.state.update,
245
+ };
246
+ if (newUpdate.Tags != null) {
247
+ newUpdate.Tags = this.state.update.Tags.join(',');
248
+ } else {
249
+ newUpdate.Tags = '';
250
+ }
251
+ this.setState({ edit: true, newUpdate });
252
+ this.checkSetImage();
253
+ }
254
+
255
+ renderEditSubmit() {
256
+ if (this.state.editSubmitting) {
257
+ return <Button buttonType="secondary">Saving changes...</Button>;
258
+ }
259
+ return (
260
+ <div>
261
+ <Button
262
+ inline
263
+ buttonType="tertiary"
264
+ onClick={() => {
265
+ this.setState({ edit: false });
266
+ }}
267
+ isActive
268
+ style={{ marginRight: 16 }}
269
+ >
270
+ Cancel
271
+ </Button>
272
+ <Button inline buttonType="primary" onClick={this.handleEditSubmit.bind(this)} isActive={this.validateEditForm()}>
273
+ Save changes
274
+ </Button>
275
+ </div>
276
+ );
277
+ }
278
+
279
+ renderSubmit() {
280
+ if (this.state.edit) {
281
+ return this.renderEditSubmit();
282
+ }
283
+ if (this.state.submitting) {
284
+ return <Button buttonType="secondary">Saving...</Button>;
285
+ }
286
+ return (
287
+ <div style={{ width: '100%' }} className="flex flex-between">
288
+ <div>
289
+ <Button inline buttonType="primary" onClick={this.handleSubmit.bind(this, 'accept')} isActive={true}>
290
+ Approve
291
+ </Button>
292
+ <Button inline buttonType="secondary" onClick={this.handleSubmit.bind(this, 'reject')} isActive={true} style={{ marginLeft: 16 }}>
293
+ Reject
294
+ </Button>
295
+ </div>
296
+ <Button inline buttonType="outlined" onClick={() => this.setEditForm()} isActive={true} style={{ marginLeft: 16 }}>
297
+ Edit submission
298
+ </Button>
299
+ </div>
300
+ );
301
+ }
302
+
303
+ renderEditForm() {
304
+ return (
305
+ <div>
306
+ <div className="padding-60 paddingBottom-20 bottomDivideBorder">
307
+ <div className="newTopBar clearfix">
308
+ <p className="newTopBarTitle text-sectionTitle">{values.textNewsSubmission}</p>
309
+ </div>
310
+ <div className="newTopBar clearfix">
311
+ <span className="newTopBarTitle text-sectionTitle">
312
+ Submitted by <span className="text-brandingColour">{this.state.update.SubmittedBy.displayName}</span>
313
+ </span>
314
+ </div>
315
+ {!_.isUndefined(this.state.update.EditedBy) && (
316
+ <div className="newTopBar clearfix">
317
+ <span className="newTopBarTitle text-sectionTitle">
318
+ Last edited by <span className="text-brandingColour">{this.state.update.EditedBy.displayName}</span>
319
+ </span>
320
+ </div>
321
+ )}
322
+ </div>
323
+ <div className="padding-60 paddingVertical-40 bottomDivideBorder">
324
+ {/* title */}
325
+ <GenericInput
326
+ id="Title"
327
+ type="text"
328
+ label={values.textNewsPostTitle}
329
+ placeholder={values.textNewsPostTitle}
330
+ showError={() => {
331
+ return this.state.showWarnings && _.isEmpty(this.state.newUpdate.Title);
332
+ }}
333
+ isValid={() => {
334
+ return !_.isEmpty(this.state.newUpdate.Title);
335
+ }}
336
+ value={this.state.newUpdate.Title}
337
+ onChange={(e) => this.handleChange(e)}
338
+ large
339
+ isRequired
340
+ disabled={this.state.editSubmitting}
341
+ />
342
+ {/* tags */}
343
+ <GenericInput
344
+ id="Tags"
345
+ type="text"
346
+ label="Tags"
347
+ help="Separate tags by commas"
348
+ placeholder="Humour, Social, etc."
349
+ value={this.state.newUpdate.Tags}
350
+ onChange={(e) => this.handleChange(e)}
351
+ alwaysShowLabel
352
+ disabled={this.state.editSubmitting}
353
+ />
354
+ {/* description */}
355
+ <GenericInput
356
+ id="Text"
357
+ type="textarea"
358
+ label="Description"
359
+ placeholder="Enter story here"
360
+ value={this.state.newUpdate.Text}
361
+ onChange={(e) => this.handleChange(e)}
362
+ isRequired
363
+ showError={() => {
364
+ return this.state.showWarnings && _.isEmpty(this.state.newUpdate.Text);
365
+ }}
366
+ isValid={() => {
367
+ return !_.isEmpty(this.state.newUpdate.Text);
368
+ }}
369
+ disabled={this.state.editSubmitting}
370
+ />
371
+ </div>
372
+ <div className="padding-60 paddingVertical-40">
373
+ <p className="text-sectionTitle">IMAGES</p>
374
+ <ImageInput ref="imageInput" multiple limit={10} />
375
+ </div>
376
+ </div>
377
+ );
378
+ }
379
+
380
+ renderForm() {
381
+ if (this.state.success) {
382
+ return null;
383
+ }
384
+ if (_.isEmpty(this.state.update)) {
385
+ return (
386
+ <div className="padding-60 bottomPadding-40" style={{ textAlign: 'center' }}>
387
+ <FontAwesome style={{ fontSize: 32, color: COLOUR_BRANDING_OFF }} name="spinner fa-pulse fa-fw" />
388
+ </div>
389
+ );
390
+ }
391
+ if (this.state.edit) {
392
+ return this.renderEditForm();
393
+ }
394
+ return (
395
+ <div>
396
+ <div className="padding-60 bottomPadding-40">
397
+ <div className="newTopBar clearfix">
398
+ <p className="newTopBarTitle text-sectionTitle">{values.textNewsSubmission}</p>
399
+ </div>
400
+ <div className="newTopBar clearfix">
401
+ <span className="newTopBarTitle text-sectionTitle">
402
+ Submitted by <span className="text-brandingColour">{this.state.update.SubmittedBy.displayName}</span>
403
+ </span>
404
+ </div>
405
+ {!_.isUndefined(this.state.update.EditedBy) && (
406
+ <div className="newTopBar clearfix">
407
+ <span className="newTopBarTitle text-sectionTitle">
408
+ Last edited by <span className="text-brandingColour">{this.state.update.EditedBy.displayName}</span>
409
+ </span>
410
+ </div>
411
+ )}
412
+ <div className="marginTop-16 fontMedium text-dark" style={{ fontSize: 26 }}>
413
+ {this.state.update.Title}
414
+ </div>
415
+ <div className="fontMedium marginBottom-8 text-light">
416
+ <span>{this.getDate()}</span>
417
+ <span> · </span>
418
+ {_.map(this.state.update.Tags, (tag, index) => {
419
+ return (
420
+ <span key={index} style={{ color: COLOUR_BRANDING_MAIN }}>
421
+ {tag}
422
+ {index !== this.state.update.Tags.length - 1 ? ', ' : ''}
423
+ </span>
424
+ );
425
+ })}
426
+ </div>
427
+ {!_.isEmpty(this.state.update.Images) &&
428
+ _.map(this.state.update.Images, (im, index) => {
429
+ return (
430
+ <div
431
+ key={index}
432
+ style={{
433
+ height: 250,
434
+ backgroundImage: `url(${im})`,
435
+ backgroundSize: 'cover',
436
+ backgroundPosition: 'center',
437
+ marginBottom: 10,
438
+ }}
439
+ />
440
+ );
441
+ })}
442
+ {_.isEmpty(this.state.update.Images) && <div className="fontRegular text-light">No image</div>}
443
+ <div className="marginTop-16 fontRegular text-dark fontSize-16" style={{ whiteSpace: 'pre-line' }}>
444
+ {this.state.update.Text}
445
+ </div>
446
+ </div>
447
+ </div>
448
+ );
449
+ }
450
+
451
+ render() {
452
+ return (
453
+ <OverlayPage>
454
+ <OverlayPageContents noBottomButtons={this.state.success}>
455
+ <OverlayPageSection className="pageSectionWrapper--newPopup">
456
+ {this.renderForm()}
457
+ {this.renderSuccess()}
458
+ </OverlayPageSection>
459
+ </OverlayPageContents>
460
+ {!this.state.success && (
461
+ <OverlayPageBottomButtons>
462
+ {this.renderSubmit()}
463
+ {/* {this.renderEditSubmit()} */}
464
+ </OverlayPageBottomButtons>
465
+ )}
466
+ </OverlayPage>
467
+ );
468
+ }
469
+ }
470
+
471
+ const mapStateToProps = (state) => {
472
+ const { auth } = state;
473
+ return { auth };
474
+ };
475
+
476
+ export default connect(mapStateToProps, { removeNewsSubmission, newsSubmissionsLoaded })(NewsletterSubmission);