@plusscommunities/pluss-circles-web 1.5.4-auth.0 → 1.5.6

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.
@@ -1,487 +1,546 @@
1
- import React, { Component } from 'react';
2
- import { withRouter } from 'react-router';
3
- import _ from 'lodash';
4
- import { connect } from 'react-redux';
5
- import { PlussCore } from '../feature.config';
6
- import { circleActions } from '../apis';
7
- import { circlesLoaded, circleUpdated } from '../actions';
8
- import { values } from '../values.config';
1
+ import React, { Component } from "react";
2
+ import { withRouter } from "react-router";
3
+ import _ from "lodash";
4
+ import { connect } from "react-redux";
5
+ import { PlussCore } from "../feature.config";
6
+ import { circleActions } from "../apis";
7
+ import { circlesLoaded, circleUpdated } from "../actions";
8
+ import { values } from "../values.config";
9
9
 
10
10
  const { Actions, Components, Session, Apis, Colours, Helper } = PlussCore;
11
11
 
12
12
  class AddCircle extends Component {
13
- constructor(props) {
14
- super(props);
15
-
16
- const circleId = Helper.safeReadParams(props, 'circleId');
17
- this.state = {
18
- circleId,
19
- circle: _.find(props.circles, (c) => {
20
- return c.Id === circleId;
21
- }),
22
- title: '',
23
- showWarnings: false,
24
- success: false,
25
- users: [],
26
- selectedUsers: [],
27
- userSearch: '',
28
- isPublic: false,
29
- selectedOption: 'visibility',
30
- };
31
- }
32
-
33
- componentDidMount() {
34
- Session.checkLoggedIn(this, this.props.auth);
35
- this.props.addRecentlyCreated(values.entityKey);
36
- this.getUsers();
37
-
38
- this.checkGetCircle();
39
- }
40
-
41
- getUsers = () => {
42
- Apis.userActions
43
- .fetchUsers(this.props.auth.site)
44
- .then((res) => {
45
- this.setState({
46
- loadingAll: false,
47
- });
48
- if (res.userFetchFail) {
49
- return;
50
- }
51
- if (res.data != null && !_.isEmpty(res.data.results.Items)) {
52
- this.setState({
53
- users: _.sortBy(res.data.results.Items, (u) => {
54
- return (u.displayName || '').toLowerCase();
55
- }).map((u) => {
56
- return { ...u, userId: u.userId || u.Id };
57
- }),
58
- });
59
- }
60
- })
61
- .catch((error) => {
62
- this.setState({ loadingAll: false });
63
- });
64
- };
65
-
66
- getShownUsers = () => {
67
- return _.filter(this.state.users, (u) => {
68
- if (
69
- _.some(this.state.selectedUsers, (selectedUser) => {
70
- return u.userId === selectedUser.userId;
71
- })
72
- ) {
73
- return false;
74
- }
75
- if (!_.isEmpty(this.state.userSearch)) {
76
- return (u.displayName || '').toLowerCase().indexOf(this.state.userSearch.toLowerCase()) > -1;
77
- }
78
- return true;
79
- });
80
- };
81
-
82
- parseCircle = (circle) => {
83
- const selectedUsers = circle.Audience.map((user) => {
84
- return {
85
- userId: user.userId,
86
- profilePic: user.profilePic,
87
- displayName: user.displayName,
88
- isAdmin: user.isAdmin,
89
- };
90
- });
91
- const newState = {
92
- title: circle.Title,
93
- isPublic: !!circle.IsPublic,
94
- selectedUsers,
95
- };
96
- this.setState(newState);
97
-
98
- if (!_.isEmpty(circle.Image)) {
99
- this.checkSetImage(circle.Image);
100
- }
101
- };
102
-
103
- checkSetImage(url) {
104
- if (this.imageInput) {
105
- this.setState({
106
- image: url,
107
- });
108
- this.imageInput.setValue(url);
109
- } else {
110
- setTimeout(() => {
111
- this.checkSetImage(url);
112
- }, 100);
113
- }
114
- }
115
-
116
- checkGetCircle = () => {
117
- if (!this.state.circleId) {
118
- return;
119
- }
120
- if (this.state.circle) {
121
- return this.parseCircle(this.state.circle);
122
- }
123
- const { auth } = this.props;
124
- this.setState({ loadingAll: true }, async () => {
125
- try {
126
- const res = await circleActions.getAll(auth.site);
127
- console.log('getData', res.data);
128
- const circle = _.find(res.data, (c) => {
129
- return c.Id === this.state.circleId;
130
- });
131
-
132
- this.props.circlesLoaded(res.data);
133
- this.setState({ loadingAll: false, circle });
134
- this.parseCircle(circle);
135
- } catch (error) {
136
- console.error('getData', error);
137
- this.setState({ loadingAll: false });
138
- }
139
- });
140
- };
141
-
142
- onHandleChange = (event) => {
143
- var stateChange = {};
144
- stateChange[event.target.getAttribute('id')] = event.target.value;
145
- this.setState(stateChange);
146
- };
147
-
148
- onImageUpdated = (url) => {
149
- this.setState({
150
- image: url,
151
- });
152
- };
153
-
154
- toggleSelf = () => {
155
- this.setState({
156
- includeSelf: !this.state.includeSelf,
157
- });
158
- };
159
-
160
- onSelectUser = (user) => {
161
- const newState = {
162
- selectedUsers: _.xor(this.state.selectedUsers, [user]),
163
- };
164
- if (_.isEmpty(this.state.title) && _.includes(newState.selectedUsers, user)) {
165
- newState.title = `${user.displayName.split(' ')[0]}'s Circle`;
166
- }
167
- this.setState(newState);
168
- };
169
-
170
- onSave = () => {
171
- this.setState({ showWarnings: false });
172
- if (!this.validateForm()) {
173
- this.setState({ showWarnings: true });
174
- return;
175
- }
176
- if (this.state.updating) return;
177
- this.setState({ updating: true });
178
- const audience = this.state.selectedUsers.map((user) => {
179
- return {
180
- userId: user.userId,
181
- profilePic: user.profilePic,
182
- displayName: user.displayName,
183
- isAdmin: user.isAdmin,
184
- };
185
- });
186
-
187
- if (this.state.circleId) {
188
- circleActions
189
- .edit(this.state.circleId, this.state.title, this.state.image, audience, this.state.isPublic)
190
- .then((res) => {
191
- this.setState({
192
- success: true,
193
- updating: false,
194
- });
195
- console.log('success');
196
- this.props.circleUpdated(res.data);
197
- })
198
- .catch((err) => {
199
- console.log('error');
200
- this.setState({ updating: false });
201
- alert('Something went wrong with the request. Please try again.');
202
- });
203
- } else {
204
- circleActions
205
- .add(this.props.auth.site, this.state.title, this.state.image, audience, this.state.isPublic)
206
- .then((res) => {
207
- this.setState({
208
- success: true,
209
- updating: false,
210
- });
211
- console.log('success');
212
- this.props.circleUpdated(res.data);
213
- })
214
- .catch((err) => {
215
- console.log('error');
216
- this.setState({ updating: false });
217
- alert('Something went wrong with the request. Please try again.');
218
- });
219
- }
220
- };
221
-
222
- getSelectableUsers() {
223
- return _.filter(this.state.users, (user) => {
224
- if (
225
- _.some(this.state.selectedUsers, (selectedUser) => {
226
- return user.userId === selectedUser.userId;
227
- })
228
- ) {
229
- return false;
230
- }
231
- return true;
232
- });
233
- }
234
-
235
- validateForm() {
236
- if (_.isEmpty(this.state.title)) return false;
237
- return true;
238
- }
239
-
240
- addAdmin = (user) => {
241
- user.isAdmin = true;
242
- this.setState({
243
- selectedUsers: [...this.state.selectedUsers],
244
- });
245
- };
246
-
247
- removeAdmin = (user) => {
248
- user.isAdmin = false;
249
- this.setState({
250
- selectedUsers: [...this.state.selectedUsers],
251
- });
252
- };
253
-
254
- renderSuccess() {
255
- if (!this.state.success) return null;
256
- return (
257
- <Components.SuccessPopup
258
- text={`${_.capitalize(values.entityName)} has been ${this.state.circleId == null ? 'added' : 'edited'}`}
259
- buttons={[
260
- {
261
- type: 'outlined',
262
- onClick: () => {
263
- window.history.back();
264
- },
265
- text: `Back to ${values.textFeatureTitle}`,
266
- },
267
- ]}
268
- />
269
- );
270
- }
271
-
272
- renderSubmit() {
273
- if (this.state.updating) {
274
- return <Components.Button buttonType="secondary">Saving...</Components.Button>;
275
- }
276
-
277
- return (
278
- <div>
279
- <Components.Button
280
- inline
281
- buttonType="tertiary"
282
- onClick={() => this.props.history.push(`/${values.featureKey}`)}
283
- isActive
284
- style={{ marginRight: 16 }}
285
- >
286
- Cancel
287
- </Components.Button>
288
- <Components.Button inline buttonType="primary" onClick={this.onSave} isActive={this.validateForm()}>
289
- Save
290
- </Components.Button>
291
- </div>
292
- );
293
- }
294
-
295
- renderVisibility() {
296
- return (
297
- <div className="optionsContent_bottom">
298
- <Components.RadioButton
299
- label={`Do you want to make this ${values.entityName} a public ${values.entityName}?`}
300
- isActive={this.state.isPublic}
301
- options={[
302
- { Label: 'Yes', Value: true, onChange: () => this.setState({ isPublic: true }) },
303
- { Label: 'No', Value: false, onChange: () => this.setState({ isPublic: false }) },
304
- ]}
305
- />
306
- <div className="genericInput-help" style={{ marginTop: 4 }}>
307
- {`This will allow anyone in the community to view and join the ${values.entityName}.`}
308
- </div>
309
- </div>
310
- );
311
- }
312
-
313
- renderSelectedOption() {
314
- return (
315
- <div>
316
- <div style={{ display: this.state.selectedOption === 'visibility' ? 'block' : 'none' }}>{this.renderVisibility()}</div>
317
- </div>
318
- );
319
- }
320
-
321
- renderOptionsSection() {
322
- let options = [
323
- {
324
- key: 'visibility',
325
- icon: 'people3',
326
- text: 'Visibility',
327
- },
328
- ];
329
- if (!this.props.circleAllowPublicCircles) {
330
- options = _.filter(options, (o) => {
331
- return o.key !== 'visibility';
332
- });
333
- }
334
- if (_.isEmpty(options)) {
335
- return null;
336
- }
337
- return (
338
- <Components.OptionsSection options={options} selected={this.state.selectedOption} selectOption={this.selectOption}>
339
- {this.renderSelectedOption()}
340
- </Components.OptionsSection>
341
- );
342
- }
343
-
344
- renderMain() {
345
- return (
346
- <div>
347
- <div className="padding-60 paddingVertical-40 bottomDivideBorder">
348
- <Components.Text type="formTitleLarge" className="marginBottom-24">
349
- {this.state.circleId == null ? 'New' : 'Edit'} {_.capitalize(values.entityName)}
350
- </Components.Text>
351
- {/* Resident Information */}
352
- <div className="flex flex-reverse">
353
- <Components.ImageInput
354
- ref={(ref) => {
355
- this.imageInput = ref;
356
- }}
357
- label="IMAGE"
358
- limit={1}
359
- refreshCallback={this.onImageUpdated}
360
- containerStyle={{ marginLeft: 40 }}
361
- />
362
- <div className="flex-1">
363
- <Components.GenericInput
364
- id="title"
365
- type="text"
366
- label="Title"
367
- placeholder={`Name the ${_.capitalize(values.entityName)}`}
368
- value={this.state.title}
369
- onChange={(e) => this.onHandleChange(e)}
370
- isRequired
371
- alwaysShowLabel
372
- isValid={() => {
373
- return !_.isEmpty(this.state.title);
374
- }}
375
- showError={() => {
376
- return this.state.showWarnings && _.isEmpty(this.state.title);
377
- }}
378
- />
379
- </div>
380
- </div>
381
- </div>
382
- <div className="padding-60 paddingVertical-40 bottomDivideBorder">
383
- <Components.Text type="formTitleMedium">Members</Components.Text>
384
- <div className="flex marginTop-20">
385
- <div className="flex-1">
386
- <Components.Text type="formTitleSmall" className="marginBottom-10">
387
- Select Users
388
- </Components.Text>
389
- <Components.GenericInput
390
- id="userSearch"
391
- type="text"
392
- label="Search"
393
- placeholder="Enter name"
394
- value={this.state.userSearch}
395
- onChange={(e) => this.onHandleChange(e)}
396
- alwaysShowLabel
397
- />
398
- {this.getShownUsers().map((user) => {
399
- return (
400
- <Components.UserListing
401
- key={user.userId}
402
- user={user}
403
- onClick={() => {
404
- this.onSelectUser(user);
405
- }}
406
- />
407
- );
408
- })}
409
- </div>
410
- <div className="flex-1">
411
- <Components.Text type="formTitleSmall" className="marginBottom-10">
412
- Selected
413
- </Components.Text>
414
- {this.state.selectedUsers.map((user) => {
415
- return (
416
- <Components.UserListing
417
- key={user.userId}
418
- user={user}
419
- rightContent={
420
- <div className="flex flex-reverse flex-center">
421
- <Components.SVGIcon
422
- className="removeIcon marginLeft-8"
423
- icon="close"
424
- colour={Colours.COLOUR_DUSK}
425
- onClick={() => {
426
- this.onSelectUser(user);
427
- }}
428
- />
429
- <Components.StatusButton
430
- isActive={user.isAdmin}
431
- activate={() => {
432
- this.addAdmin(user);
433
- }}
434
- deactivate={() => {
435
- this.removeAdmin(user);
436
- }}
437
- activeText="Admin"
438
- activateText="Make Admin"
439
- deactivateText="Remove Admin"
440
- inactiveText="Not Admin"
441
- />
442
- </div>
443
- }
444
- />
445
- );
446
- })}
447
- </div>
448
- </div>
449
- </div>
450
-
451
- {this.renderOptionsSection()}
452
- </div>
453
- );
454
- }
455
-
456
- render() {
457
- const { success } = this.state;
458
-
459
- return (
460
- <Components.OverlayPage>
461
- <Components.OverlayPageContents noBottomButtons={success}>
462
- <Components.OverlayPageSection className="pageSectionWrapper--newPopup">
463
- <div>
464
- {this.renderSuccess()}
465
- {!success && this.renderMain()}
466
- </div>
467
- </Components.OverlayPageSection>
468
- </Components.OverlayPageContents>
469
- <Components.OverlayPageBottomButtons>{this.renderSubmit()}</Components.OverlayPageBottomButtons>
470
- </Components.OverlayPage>
471
- );
472
- }
13
+ constructor(props) {
14
+ super(props);
15
+
16
+ const circleId = Helper.safeReadParams(props, "circleId");
17
+ this.state = {
18
+ circleId,
19
+ circle: _.find(props.circles, (c) => {
20
+ return c.Id === circleId;
21
+ }),
22
+ title: "",
23
+ showWarnings: false,
24
+ success: false,
25
+ users: [],
26
+ selectedUsers: [],
27
+ userSearch: "",
28
+ isPublic: false,
29
+ selectedOption: "visibility",
30
+ };
31
+ }
32
+
33
+ componentDidMount() {
34
+ Session.checkLoggedIn(this, this.props.auth);
35
+ this.props.addRecentlyCreated(values.entityKey);
36
+ this.getUsers();
37
+
38
+ this.checkGetCircle();
39
+ }
40
+
41
+ getUsers = () => {
42
+ Apis.userActions
43
+ .fetchUsers(this.props.auth.site)
44
+ .then((res) => {
45
+ this.setState({
46
+ loadingAll: false,
47
+ });
48
+ if (res.userFetchFail) {
49
+ return;
50
+ }
51
+ if (res.data != null && !_.isEmpty(res.data.results.Items)) {
52
+ this.setState({
53
+ users: _.sortBy(res.data.results.Items, (u) => {
54
+ return (u.displayName || "").toLowerCase();
55
+ }).map((u) => {
56
+ return { ...u, userId: u.userId || u.Id };
57
+ }),
58
+ });
59
+ }
60
+ })
61
+ .catch((error) => {
62
+ this.setState({ loadingAll: false });
63
+ });
64
+ };
65
+
66
+ getShownUsers = () => {
67
+ return _.filter(this.state.users, (u) => {
68
+ if (
69
+ _.some(this.state.selectedUsers, (selectedUser) => {
70
+ return u.userId === selectedUser.userId;
71
+ })
72
+ ) {
73
+ return false;
74
+ }
75
+ if (!_.isEmpty(this.state.userSearch)) {
76
+ return (
77
+ (u.displayName || "")
78
+ .toLowerCase()
79
+ .indexOf(this.state.userSearch.toLowerCase()) > -1
80
+ );
81
+ }
82
+ return true;
83
+ });
84
+ };
85
+
86
+ parseCircle = (circle) => {
87
+ const selectedUsers = circle.Audience.map((user) => {
88
+ return {
89
+ userId: user.userId,
90
+ profilePic: user.profilePic,
91
+ displayName: user.displayName,
92
+ isAdmin: user.isAdmin,
93
+ };
94
+ });
95
+ const newState = {
96
+ title: circle.Title,
97
+ isPublic: !!circle.IsPublic,
98
+ selectedUsers,
99
+ };
100
+ this.setState(newState);
101
+
102
+ if (!_.isEmpty(circle.Image)) {
103
+ this.checkSetImage(circle.Image);
104
+ }
105
+ };
106
+
107
+ checkSetImage(url) {
108
+ if (this.imageInput) {
109
+ this.setState({
110
+ image: url,
111
+ });
112
+ this.imageInput.setValue(url);
113
+ } else {
114
+ setTimeout(() => {
115
+ this.checkSetImage(url);
116
+ }, 100);
117
+ }
118
+ }
119
+
120
+ checkGetCircle = () => {
121
+ if (!this.state.circleId) {
122
+ return;
123
+ }
124
+ if (this.state.circle) {
125
+ return this.parseCircle(this.state.circle);
126
+ }
127
+ const { auth } = this.props;
128
+ this.setState({ loadingAll: true }, async () => {
129
+ try {
130
+ const res = await circleActions.getAll(auth.site);
131
+ console.log("getData", res.data);
132
+ const circle = _.find(res.data, (c) => {
133
+ return c.Id === this.state.circleId;
134
+ });
135
+
136
+ this.props.circlesLoaded(res.data);
137
+ this.setState({ loadingAll: false, circle });
138
+ this.parseCircle(circle);
139
+ } catch (error) {
140
+ console.error("getData", error);
141
+ this.setState({ loadingAll: false });
142
+ }
143
+ });
144
+ };
145
+
146
+ onHandleChange = (event) => {
147
+ var stateChange = {};
148
+ stateChange[event.target.getAttribute("id")] = event.target.value;
149
+ this.setState(stateChange);
150
+ };
151
+
152
+ onImageUpdated = (url) => {
153
+ this.setState({
154
+ image: url,
155
+ });
156
+ };
157
+
158
+ toggleSelf = () => {
159
+ this.setState({
160
+ includeSelf: !this.state.includeSelf,
161
+ });
162
+ };
163
+
164
+ onSelectUser = (user) => {
165
+ const newState = {
166
+ selectedUsers: _.xor(this.state.selectedUsers, [user]),
167
+ };
168
+ if (
169
+ _.isEmpty(this.state.title) &&
170
+ _.includes(newState.selectedUsers, user)
171
+ ) {
172
+ newState.title = `${user.displayName.split(" ")[0]}'s Circle`;
173
+ }
174
+ this.setState(newState);
175
+ };
176
+
177
+ onSave = () => {
178
+ this.setState({ showWarnings: false });
179
+ if (!this.validateForm()) {
180
+ this.setState({ showWarnings: true });
181
+ return;
182
+ }
183
+ if (this.state.updating) return;
184
+ this.setState({ updating: true });
185
+ const audience = this.state.selectedUsers.map((user) => {
186
+ return {
187
+ userId: user.userId,
188
+ profilePic: user.profilePic,
189
+ displayName: user.displayName,
190
+ isAdmin: user.isAdmin,
191
+ };
192
+ });
193
+
194
+ if (this.state.circleId) {
195
+ circleActions
196
+ .edit(
197
+ this.state.circleId,
198
+ this.state.title,
199
+ this.state.image,
200
+ audience,
201
+ this.state.isPublic,
202
+ )
203
+ .then((res) => {
204
+ this.setState({
205
+ success: true,
206
+ updating: false,
207
+ });
208
+ console.log("success");
209
+ this.props.circleUpdated(res.data);
210
+ })
211
+ .catch((err) => {
212
+ console.log("error");
213
+ this.setState({ updating: false });
214
+ alert("Something went wrong with the request. Please try again.");
215
+ });
216
+ } else {
217
+ circleActions
218
+ .add(
219
+ this.props.auth.site,
220
+ this.state.title,
221
+ this.state.image,
222
+ audience,
223
+ this.state.isPublic,
224
+ )
225
+ .then((res) => {
226
+ this.setState({
227
+ success: true,
228
+ updating: false,
229
+ });
230
+ console.log("success");
231
+ this.props.circleUpdated(res.data);
232
+ })
233
+ .catch((err) => {
234
+ console.log("error");
235
+ this.setState({ updating: false });
236
+ alert("Something went wrong with the request. Please try again.");
237
+ });
238
+ }
239
+ };
240
+
241
+ getSelectableUsers() {
242
+ return _.filter(this.state.users, (user) => {
243
+ if (
244
+ _.some(this.state.selectedUsers, (selectedUser) => {
245
+ return user.userId === selectedUser.userId;
246
+ })
247
+ ) {
248
+ return false;
249
+ }
250
+ return true;
251
+ });
252
+ }
253
+
254
+ validateForm() {
255
+ if (_.isEmpty(this.state.title)) return false;
256
+ return true;
257
+ }
258
+
259
+ addAdmin = (user) => {
260
+ user.isAdmin = true;
261
+ this.setState({
262
+ selectedUsers: [...this.state.selectedUsers],
263
+ });
264
+ };
265
+
266
+ removeAdmin = (user) => {
267
+ user.isAdmin = false;
268
+ this.setState({
269
+ selectedUsers: [...this.state.selectedUsers],
270
+ });
271
+ };
272
+
273
+ renderSuccess() {
274
+ if (!this.state.success) return null;
275
+ return (
276
+ <Components.SuccessPopup
277
+ text={`${_.capitalize(values.entityName)} has been ${this.state.circleId == null ? "added" : "edited"}`}
278
+ buttons={[
279
+ {
280
+ type: "outlined",
281
+ onClick: () => {
282
+ window.history.back();
283
+ },
284
+ text: `Back to ${values.textFeatureTitle}`,
285
+ },
286
+ ]}
287
+ />
288
+ );
289
+ }
290
+
291
+ renderSubmit() {
292
+ if (this.state.updating) {
293
+ return (
294
+ <Components.Button buttonType="secondary">Saving...</Components.Button>
295
+ );
296
+ }
297
+
298
+ return (
299
+ <div>
300
+ <Components.Button
301
+ inline
302
+ buttonType="tertiary"
303
+ onClick={() => this.props.history.push(`/${values.featureKey}`)}
304
+ isActive
305
+ style={{ marginRight: 16 }}
306
+ >
307
+ Cancel
308
+ </Components.Button>
309
+ <Components.Button
310
+ inline
311
+ buttonType="primary"
312
+ onClick={this.onSave}
313
+ isActive={this.validateForm()}
314
+ >
315
+ Save
316
+ </Components.Button>
317
+ </div>
318
+ );
319
+ }
320
+
321
+ renderVisibility() {
322
+ return (
323
+ <div className="optionsContent_bottom">
324
+ <Components.RadioButton
325
+ label={`Do you want to make this ${values.entityName} a public ${values.entityName}?`}
326
+ isActive={this.state.isPublic}
327
+ options={[
328
+ {
329
+ Label: "Yes",
330
+ Value: true,
331
+ onChange: () => this.setState({ isPublic: true }),
332
+ },
333
+ {
334
+ Label: "No",
335
+ Value: false,
336
+ onChange: () => this.setState({ isPublic: false }),
337
+ },
338
+ ]}
339
+ />
340
+ <div className="genericInput-help" style={{ marginTop: 4 }}>
341
+ {`This will allow anyone in the community to view and join the ${values.entityName}.`}
342
+ </div>
343
+ </div>
344
+ );
345
+ }
346
+
347
+ renderSelectedOption() {
348
+ return (
349
+ <div>
350
+ <div
351
+ style={{
352
+ display:
353
+ this.state.selectedOption === "visibility" ? "block" : "none",
354
+ }}
355
+ >
356
+ {this.renderVisibility()}
357
+ </div>
358
+ </div>
359
+ );
360
+ }
361
+
362
+ renderOptionsSection() {
363
+ let options = [
364
+ {
365
+ key: "visibility",
366
+ icon: "people3",
367
+ text: "Visibility",
368
+ },
369
+ ];
370
+ if (!this.props.circleAllowPublicCircles) {
371
+ options = _.filter(options, (o) => {
372
+ return o.key !== "visibility";
373
+ });
374
+ }
375
+ if (_.isEmpty(options)) {
376
+ return null;
377
+ }
378
+ return (
379
+ <Components.OptionsSection
380
+ options={options}
381
+ selected={this.state.selectedOption}
382
+ selectOption={this.selectOption}
383
+ >
384
+ {this.renderSelectedOption()}
385
+ </Components.OptionsSection>
386
+ );
387
+ }
388
+
389
+ renderMain() {
390
+ return (
391
+ <div>
392
+ <div className="padding-60 paddingVertical-40 bottomDivideBorder">
393
+ <Components.Text type="formTitleLarge" className="marginBottom-24">
394
+ {this.state.circleId == null ? "New" : "Edit"}{" "}
395
+ {_.capitalize(values.entityName)}
396
+ </Components.Text>
397
+ {/* Resident Information */}
398
+ <div className="flex flex-reverse">
399
+ <Components.ImageInput
400
+ ref={(ref) => {
401
+ this.imageInput = ref;
402
+ }}
403
+ label="IMAGE"
404
+ limit={1}
405
+ refreshCallback={this.onImageUpdated}
406
+ containerStyle={{ marginLeft: 40 }}
407
+ />
408
+ <div className="flex-1">
409
+ <Components.GenericInput
410
+ id="title"
411
+ type="text"
412
+ label="Title"
413
+ placeholder={`Name the ${_.capitalize(values.entityName)}`}
414
+ value={this.state.title}
415
+ onChange={(e) => this.onHandleChange(e)}
416
+ isRequired
417
+ alwaysShowLabel
418
+ isValid={() => {
419
+ return !_.isEmpty(this.state.title);
420
+ }}
421
+ showError={() => {
422
+ return this.state.showWarnings && _.isEmpty(this.state.title);
423
+ }}
424
+ />
425
+ </div>
426
+ </div>
427
+ </div>
428
+ <div className="padding-60 paddingVertical-40 bottomDivideBorder">
429
+ <Components.Text type="formTitleMedium">Members</Components.Text>
430
+ <div className="flex marginTop-20">
431
+ <div className="flex-1">
432
+ <Components.Text
433
+ type="formTitleSmall"
434
+ className="marginBottom-10"
435
+ >
436
+ Select Users
437
+ </Components.Text>
438
+ <Components.GenericInput
439
+ id="userSearch"
440
+ type="text"
441
+ label="Search"
442
+ placeholder="Enter name"
443
+ value={this.state.userSearch}
444
+ onChange={(e) => this.onHandleChange(e)}
445
+ alwaysShowLabel
446
+ />
447
+ {this.getShownUsers().map((user) => {
448
+ return (
449
+ <Components.UserListing
450
+ key={user.userId}
451
+ user={user}
452
+ onClick={() => {
453
+ this.onSelectUser(user);
454
+ }}
455
+ />
456
+ );
457
+ })}
458
+ </div>
459
+ <div className="flex-1">
460
+ <Components.Text
461
+ type="formTitleSmall"
462
+ className="marginBottom-10"
463
+ >
464
+ Selected
465
+ </Components.Text>
466
+ {this.state.selectedUsers.map((user) => {
467
+ return (
468
+ <Components.UserListing
469
+ key={user.userId}
470
+ user={user}
471
+ rightContent={
472
+ <div className="flex flex-reverse flex-center">
473
+ <Components.SVGIcon
474
+ className="removeIcon marginLeft-8"
475
+ icon="close"
476
+ colour={Colours.COLOUR_DUSK}
477
+ onClick={() => {
478
+ this.onSelectUser(user);
479
+ }}
480
+ />
481
+ <Components.StatusButton
482
+ isActive={user.isAdmin}
483
+ activate={() => {
484
+ this.addAdmin(user);
485
+ }}
486
+ deactivate={() => {
487
+ this.removeAdmin(user);
488
+ }}
489
+ activeText="Admin"
490
+ activateText="Make Admin"
491
+ deactivateText="Remove Admin"
492
+ inactiveText="Not Admin"
493
+ />
494
+ </div>
495
+ }
496
+ />
497
+ );
498
+ })}
499
+ </div>
500
+ </div>
501
+ </div>
502
+
503
+ {this.renderOptionsSection()}
504
+ </div>
505
+ );
506
+ }
507
+
508
+ render() {
509
+ const { success } = this.state;
510
+
511
+ return (
512
+ <Components.OverlayPage>
513
+ <Components.OverlayPageContents noBottomButtons={success}>
514
+ <Components.OverlayPageSection className="pageSectionWrapper--newPopup">
515
+ <div>
516
+ {this.renderSuccess()}
517
+ {!success && this.renderMain()}
518
+ </div>
519
+ </Components.OverlayPageSection>
520
+ </Components.OverlayPageContents>
521
+ <Components.OverlayPageBottomButtons>
522
+ {this.renderSubmit()}
523
+ </Components.OverlayPageBottomButtons>
524
+ </Components.OverlayPage>
525
+ );
526
+ }
473
527
  }
474
528
 
475
529
  const mapStateToProps = (state) => {
476
- const { circles } = state[values.reducerKey];
477
- const { auth } = state;
478
- return {
479
- circles,
480
- auth,
481
- circleAllowPublicCircles: Helper.getSiteSettingFromState(state, values.allowPublicKey),
482
- };
530
+ const { circles } = state[values.reducerKey];
531
+ const { auth } = state;
532
+ return {
533
+ circles,
534
+ auth,
535
+ circleAllowPublicCircles: Helper.getSiteSettingFromState(
536
+ state,
537
+ values.allowPublicKey,
538
+ ),
539
+ };
483
540
  };
484
541
 
485
- export default connect(mapStateToProps, { circlesLoaded, circleUpdated, addRecentlyCreated: Actions.addRecentlyCreated })(
486
- withRouter(AddCircle),
487
- );
542
+ export default connect(mapStateToProps, {
543
+ circlesLoaded,
544
+ circleUpdated,
545
+ addRecentlyCreated: Actions.addRecentlyCreated,
546
+ })(withRouter(AddCircle));