@plusscommunities/pluss-core-web 1.2.3 → 1.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-web",
3
- "version": "1.2.3",
3
+ "version": "1.2.7",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "main": "dist/index.cjs.js",
6
6
  "scripts": {
@@ -12,38 +12,41 @@ import { DropdownInput } from './DropdownInput';
12
12
  import { Tag } from './Tag';
13
13
 
14
14
  class AudienceSelector extends Component {
15
- state = {
16
- categories: [
17
- {
18
- Title: 'All Primary Users',
19
- Key: 'resident',
20
- ShortName: 'Primary',
21
- },
22
- {
23
- Title: 'All Staff Users',
24
- Key: 'staff',
25
- ShortName: 'Staff',
26
- },
27
- {
28
- Title: 'All Linked Users',
29
- Key: 'family',
30
- ShortName: 'Linked',
31
- },
32
- ],
33
- types: [],
34
- AudienceType: 'All',
35
-
36
- showInclude: false,
37
- includeList: [],
38
- showExclude: false,
39
- excludeList: [],
40
- Type: '',
41
- Category: '',
42
-
43
- userList: [],
44
- tagList: [],
45
- AudienceTagList: [],
46
- };
15
+ constructor(props) {
16
+ super(props);
17
+
18
+ this.state = {
19
+ categories: [
20
+ {
21
+ Title: 'All Primary Users',
22
+ Key: 'resident',
23
+ ShortName: 'Primary',
24
+ },
25
+ {
26
+ Title: 'All Staff Users',
27
+ Key: 'staff',
28
+ ShortName: 'Staff',
29
+ },
30
+ {
31
+ Title: 'All Linked Users',
32
+ Key: 'family',
33
+ ShortName: 'Linked',
34
+ },
35
+ ],
36
+ types: [],
37
+ AudienceType: props.audienceType || 'All',
38
+ showInclude: false,
39
+ includeList: [],
40
+ showExclude: false,
41
+ excludeList: [],
42
+ Type: '',
43
+ Category: '',
44
+
45
+ userList: [],
46
+ tagList: [],
47
+ AudienceTagList: props.audienceTypeSelection || [],
48
+ };
49
+ }
47
50
 
48
51
  componentDidMount() {
49
52
  const { disallowUserType, custom, disallowSingleUsers, allowTags } = this.props;
@@ -52,6 +55,14 @@ class AudienceSelector extends Component {
52
55
  if (allowTags || custom) this.getUserTags();
53
56
  }
54
57
 
58
+ componentDidUpdate(prevProps) {
59
+ const newState = {};
60
+ if (prevProps.audienceType !== this.props.audienceType) newState.AudienceType = this.props.audienceType;
61
+ if (!_.isEqual(prevProps.audienceTypeSelection, this.props.audienceTypeSelection))
62
+ newState.AudienceTagList = this.props.audienceTypeSelection;
63
+ if (!_.isEmpty(newState)) this.setState(newState);
64
+ }
65
+
55
66
  onSubmit() {
56
67
  if (this.state.AudienceType === 'User' && _.isEmpty(this.state.includeList)) {
57
68
  this.setState({ showInclude: true });
@@ -64,13 +75,7 @@ class AudienceSelector extends Component {
64
75
 
65
76
  getAudienceTypeSelection() {
66
77
  const { AudienceType, AudienceTagList, Category, Tag, Type } = this.state;
67
- if (AudienceType === 'Custom')
68
- return AudienceTagList.map((at) => {
69
- return {
70
- AudienceType: at.AudienceType,
71
- AudienceTypeSelection: at.AudienceTypeSelection,
72
- };
73
- });
78
+ if (AudienceType === 'Custom') return AudienceTagList;
74
79
  if (AudienceType === 'Category') return Category;
75
80
  if (AudienceType === 'UserTags') return Tag;
76
81
  return Type;
@@ -116,6 +121,13 @@ class AudienceSelector extends Component {
116
121
  this.setState(newState);
117
122
  }
118
123
 
124
+ onChangeSelection = () => {
125
+ const { updateValidation, onChange } = this.props;
126
+ const isValid = this.validateAudienceSelection();
127
+ if (updateValidation) updateValidation(isValid);
128
+ if (onChange) onChange(this.getAudienceType(), this.getAudienceTypeSelection(), isValid);
129
+ };
130
+
119
131
  onChangeOption(type) {
120
132
  this.setState({
121
133
  AudienceType: type,
@@ -124,9 +136,7 @@ class AudienceSelector extends Component {
124
136
  includeList: [],
125
137
  excludeList: [],
126
138
  });
127
- setTimeout(() => {
128
- this.props.updateValidation(this.validateAudienceSelection());
129
- }, 50);
139
+ setTimeout(this.onChangeSelection, 50);
130
140
  }
131
141
 
132
142
  getOptions() {
@@ -190,9 +200,7 @@ class AudienceSelector extends Component {
190
200
  includeList: [],
191
201
  excludeList: [],
192
202
  });
193
- setTimeout(() => {
194
- this.props.updateValidation(this.validateAudienceSelection());
195
- }, 50);
203
+ setTimeout(this.onChangeSelection, 50);
196
204
  }
197
205
 
198
206
  getTypeTitle() {
@@ -211,9 +219,7 @@ class AudienceSelector extends Component {
211
219
  includeList: [],
212
220
  excludeList: [],
213
221
  });
214
- setTimeout(() => {
215
- this.props.updateValidation(this.validateAudienceSelection());
216
- }, 50);
222
+ setTimeout(this.onChangeSelection, 50);
217
223
  };
218
224
 
219
225
  getTagTitle() {
@@ -281,9 +287,7 @@ class AudienceSelector extends Component {
281
287
  includeList: [],
282
288
  excludeList: [],
283
289
  });
284
- setTimeout(() => {
285
- this.props.updateValidation(this.validateAudienceSelection());
286
- }, 50);
290
+ setTimeout(this.onChangeSelection, 50);
287
291
  }
288
292
 
289
293
  getCatTitle() {
@@ -370,9 +374,7 @@ class AudienceSelector extends Component {
370
374
  profilePic: user.profilePic,
371
375
  });
372
376
  this.setState({ includeList: list });
373
- setTimeout(() => {
374
- this.props.updateValidation(this.validateAudienceSelection());
375
- }, 50);
377
+ setTimeout(this.onChangeSelection, 50);
376
378
  }
377
379
 
378
380
  removeUserInc(user) {
@@ -381,9 +383,7 @@ class AudienceSelector extends Component {
381
383
  return ev.Id !== user.Id;
382
384
  }),
383
385
  });
384
- setTimeout(() => {
385
- this.props.updateValidation(this.validateAudienceSelection());
386
- }, 50);
386
+ setTimeout(this.onChangeSelection, 50);
387
387
  }
388
388
 
389
389
  addToEx(user) {
@@ -404,7 +404,7 @@ class AudienceSelector extends Component {
404
404
  });
405
405
  }
406
406
 
407
- getAvailableAudienceTags = () => {
407
+ getAvailableAudienceTags = (includeSelected = false) => {
408
408
  const { categories, types, tagList, AudienceTagList } = this.state;
409
409
  const categoryTags = categories.map((c) => {
410
410
  return {
@@ -430,19 +430,18 @@ class AudienceSelector extends Component {
430
430
  Title: `User Tag: ${t.Title}`,
431
431
  };
432
432
  });
433
- return [...categoryTags, ...userTypeTags, ...userTagTags].filter((t) => {
434
- return !_.some(AudienceTagList, (at) => at.Id === t.Id);
435
- });
433
+ const result = [...categoryTags, ...userTypeTags, ...userTagTags];
434
+ return includeSelected ? result : result.filter((t) => !_.some(AudienceTagList, (at) => at.Id === t.Id));
436
435
  };
437
436
 
438
437
  onAttachAudienceTag = (tag) => {
439
438
  const AudienceTagList = [...this.state.AudienceTagList, tag];
440
- this.setState({ AudienceTagList }, () => this.props.updateValidation(this.validateAudienceSelection()));
439
+ this.setState({ AudienceTagList }, this.onChangeSelection);
441
440
  };
442
441
 
443
442
  onDetachAudienceTag = (tag) => {
444
443
  const AudienceTagList = _.filter(this.state.AudienceTagList, (at) => at.Id !== tag.Id);
445
- this.setState({ AudienceTagList }, () => this.props.updateValidation(this.validateAudienceSelection()));
444
+ this.setState({ AudienceTagList }, this.onChangeSelection);
446
445
  };
447
446
 
448
447
  renderExcludes() {
@@ -0,0 +1,22 @@
1
+ import React, { Component } from 'react';
2
+ import moment from 'moment';
3
+ import { toParagraphed } from '../helper';
4
+ import { ProfilePic } from './ProfilePic';
5
+
6
+ class Comment extends Component {
7
+ render() {
8
+ const { comment } = this.props;
9
+ return (
10
+ <div key={comment.Id} className="comment">
11
+ <p className="comment_text">{toParagraphed(comment.Comment)}</p>
12
+ <div className="comment_bottom">
13
+ <ProfilePic className="comment_profilePic" size={25} image={comment.User.profilePic} />
14
+ <p className="comment_name">{comment.User.displayName}</p>
15
+ <p className="comment_time">{moment.utc(comment.Timestamp).local().format('D MMM YYYY • h:mma')}</p>
16
+ </div>
17
+ </div>
18
+ );
19
+ }
20
+ }
21
+
22
+ export { Comment };
@@ -0,0 +1,63 @@
1
+ import React, { Component } from 'react';
2
+ import FontAwesome from 'react-fontawesome';
3
+ import _ from 'lodash';
4
+ import Textarea from 'react-textarea-autosize';
5
+ import { Text } from './Text';
6
+ import { Comment } from './Comment';
7
+
8
+ class CommentSection extends Component {
9
+ constructor(props) {
10
+ super(props);
11
+
12
+ this.state = {
13
+ commentInput: '',
14
+ };
15
+ }
16
+
17
+ onHandleChange = (event) => {
18
+ var stateChange = {};
19
+ stateChange[event.target.getAttribute('id')] = event.target.value;
20
+ this.setState(stateChange);
21
+ };
22
+
23
+ onAddComment = async () => {
24
+ const { commentInput } = this.state;
25
+ this.setState({ commentInput: '' });
26
+ this.props.onAddComment(commentInput);
27
+ };
28
+
29
+ render() {
30
+ return (
31
+ <div>
32
+ {this.props.includeTitle && (
33
+ <Text type="formTitleSmall" className="marginBottom-16">
34
+ Comments
35
+ </Text>
36
+ )}
37
+ <div className="commentSection">
38
+ {this.props.comments.map((c) => (
39
+ <Comment key={c.Id} comment={c} />
40
+ ))}
41
+ </div>
42
+ <div className="commentReply">
43
+ <div
44
+ className={`commentReply_button${!_.isEmpty(this.state.commentInput) ? ' commentReply_button-active' : ''}`}
45
+ onClick={this.onAddComment}
46
+ >
47
+ <FontAwesome className="commentReply_icon" name="paper-plane-o" />
48
+ </div>
49
+ <Textarea
50
+ id="commentInput"
51
+ placeholder="Reply here..."
52
+ type="text"
53
+ className="commentReply_input"
54
+ value={this.state.commentInput}
55
+ onChange={(e) => this.onHandleChange(e)}
56
+ />
57
+ </div>
58
+ </div>
59
+ );
60
+ }
61
+ }
62
+
63
+ export { CommentSection };
@@ -2,7 +2,8 @@ import React, { Component } from 'react';
2
2
  import _ from 'lodash';
3
3
  import FontAwesome from 'react-fontawesome';
4
4
  import { CSVLink } from 'react-csv';
5
- import { Popup, CheckBox } from '.';
5
+ import { Popup } from './Popup';
6
+ import { CheckBox } from './CheckBox';
6
7
 
7
8
  class ExportCsvPopup extends Component {
8
9
  constructor(props) {
@@ -2,6 +2,8 @@ export * from './AddButton';
2
2
  export * from './Attachment';
3
3
  export * from './Button';
4
4
  export * from './CheckBox';
5
+ export * from './Comment';
6
+ export * from './CommentSection';
5
7
  export * from './DatePicker';
6
8
  export * from './FileInput';
7
9
  export * from './GenericInput';