@@ -8,60 +8,55 @@ import iconWeb from '../../../../../assets/images/icon-web.png'
88import './NotificationSettingsForm.scss'
99import _ from 'lodash'
1010
11- // TODO move this list to constants together with the same list in service/settings.js
11+ // list of the notification groups and related event types
12+ // TODO move it to constants and reuse the same list in services/settings.js
1213const topics = [
13- 'notifications.connect.project.created' ,
14- 'notifications.connect.project.updated' ,
15- 'notifications.connect.project.canceled' ,
16- 'notifications.connect.project.approved' ,
17- 'notifications.connect.project.paused' ,
18- 'notifications.connect.project.completed' ,
19- 'notifications.connect.project.submittedForReview' ,
20-
21- 'notifications.connect.project.fileUploaded' ,
22- 'notifications.connect.project.specificationModified' ,
23- 'notifications.connect.project.linkCreated' ,
24-
25- 'notifications.connect.project.member.joined' ,
26- 'notifications.connect.project.member.left' ,
27- 'notifications.connect.project.member.removed' ,
28- 'notifications.connect.project.member.managerJoined' ,
29- 'notifications.connect.project.member.copilotJoined' ,
30- 'notifications.connect.project.member.assignedAsOwner' ,
31-
32- 'notifications.connect.project.topic.created' ,
33- 'notifications.connect.project.topic.deleted' ,
34- 'notifications.connect.project.post.created' ,
35- 'notifications.connect.project.post.edited' ,
36- 'notifications.connect.project.post.deleted'
37- ]
38-
39- // TODO put these values to one list with `topics`
40- const titles = [
41- 'Project Created' ,
42- 'Project Updated' ,
43- 'Project Canceled' ,
44- 'Project Approved' ,
45- 'Project Paused' ,
46- 'Project Completed' ,
47- 'Project Submitted For Review' ,
48-
49- 'Project File uploaded' ,
50- 'Project Specification modified' ,
51- 'Project link added' ,
52-
53- 'Project member joined' ,
54- 'Project member left' ,
55- 'Project member removed' ,
56- 'Project manager joined' ,
57- 'Project copilot joined' ,
58- 'Project member assigned as owner' ,
59-
60- 'Project topic created' ,
61- 'Project topic deleted' ,
62- 'Project post created' ,
63- 'Project post edited' ,
64- 'Project post deleted'
14+ {
15+ title : 'New posts and replies' ,
16+ types : [
17+ 'notifications.connect.project.topic.created' ,
18+ 'notifications.connect.project.topic.deleted' ,
19+ 'notifications.connect.project.post.created' ,
20+ 'notifications.connect.project.post.edited' ,
21+ 'notifications.connect.project.post.deleted'
22+ ]
23+ } , {
24+ title : 'Project status changes' ,
25+ types : [
26+ 'notifications.connect.project.created' ,
27+ 'notifications.connect.project.updated' ,
28+ 'notifications.connect.project.canceled' ,
29+ 'notifications.connect.project.approved' ,
30+ 'notifications.connect.project.paused' ,
31+ 'notifications.connect.project.completed' ,
32+ 'notifications.connect.project.submittedForReview'
33+ ]
34+ } , {
35+ title : 'Project specification changes' ,
36+ types : [
37+ 'notifications.connect.project.specificationModified'
38+ ]
39+ } , {
40+ title : 'File uploads' ,
41+ types : [
42+ 'notifications.connect.project.fileUploaded'
43+ ]
44+ } , {
45+ title : 'New project links' ,
46+ types : [
47+ 'notifications.connect.project.linkCreated'
48+ ]
49+ } , {
50+ title : 'Team changes' ,
51+ types : [
52+ 'notifications.connect.project.member.joined' ,
53+ 'notifications.connect.project.member.left' ,
54+ 'notifications.connect.project.member.removed' ,
55+ 'notifications.connect.project.member.managerJoined' ,
56+ 'notifications.connect.project.member.copilotJoined' ,
57+ 'notifications.connect.project.member.assignedAsOwner'
58+ ]
59+ }
6560]
6661
6762/**
@@ -78,17 +73,18 @@ const titles = [
7873 */
7974const initSettings = ( notInitedSettings ) => {
8075 const settings = { ...notInitedSettings }
76+ const allTypes = _ . flatten ( _ . map ( topics , 'types' ) )
8177
82- topics . forEach ( ( topic ) => {
83- if ( ! settings [ topic ] ) {
84- settings [ topic ] = { }
78+ allTypes . forEach ( ( type ) => {
79+ if ( ! settings [ type ] ) {
80+ settings [ type ] = { }
8581 }
8682
8783 // check each of deliveryMethod method separately as some can have
8884 // values and some don't have
8985 [ 'web' , 'email' ] . forEach ( ( deliveryMethod ) => {
90- if ( _ . isUndefined ( settings [ topic ] [ deliveryMethod ] ) ) {
91- settings [ topic ] [ deliveryMethod ] = 'yes'
86+ if ( _ . isUndefined ( settings [ type ] [ deliveryMethod ] ) ) {
87+ settings [ type ] [ deliveryMethod ] = 'yes'
9288 }
9389 } )
9490 } )
@@ -108,13 +104,17 @@ class NotificationSettingsForm extends React.Component {
108104 this . handleChange = this . handleChange . bind ( this )
109105 }
110106
111- handleChange ( topic , deliveryMethod ) {
107+ handleChange ( topicIndex , deliveryMethod ) {
112108 const s = {
113109 settings : {
114110 ...this . state . settings
115111 }
116112 }
117- s . settings [ topic ] [ deliveryMethod ] = s . settings [ topic ] [ deliveryMethod ] === 'yes' ? 'no' : 'yes'
113+
114+ // update values for all types of the topic
115+ topics [ topicIndex ] . types . forEach ( ( type ) => {
116+ s . settings [ type ] [ deliveryMethod ] = s . settings [ type ] [ deliveryMethod ] === 'yes' ? 'no' : 'yes'
117+ } )
118118
119119 this . setState ( s )
120120 }
@@ -144,11 +144,13 @@ class NotificationSettingsForm extends React.Component {
144144 </ thead >
145145 < tbody >
146146 { _ . map ( topics , ( topic , index ) => {
147- const title = titles [ index ]
147+ // we toggle settings for all the types in one topic all together
148+ // so we can use values from the first type to get current value for the whole topic
149+ const topicFirstType = topic . types [ 0 ]
148150 return (
149- < tr key = { topic } >
150- < th > { title } </ th >
151- < td > < SwitchButton onChange = { ( ) => this . handleChange ( topic , 'web' ) } defaultChecked = { settings [ topic ] && settings [ topic ] . web === 'yes' } /> </ td >
151+ < tr key = { index } >
152+ < th > { topic . title } </ th >
153+ < td > < SwitchButton onChange = { ( ) => this . handleChange ( index , 'web' ) } defaultChecked = { settings [ topicFirstType ] && settings [ topicFirstType ] . web === 'yes' } /> </ td >
152154 { /* as email notification currently not supported, hide them for now */ }
153155 { /*<td><SwitchButton onChange={() => this.handleChange(topic, 'email')} defaultChecked={settings[topic] && settings[topic].email === 'yes'} /></td>*/ }
154156 </ tr >
0 commit comments