@@ -5,11 +5,9 @@ import React from 'react'
55import PropTypes from 'prop-types'
66import FormsyForm from 'appirio-tech-react-components/components/Formsy'
77const Formsy = FormsyForm . Formsy
8- import { NOTIFICATION_SETTINGS_PERIODS } from '../../../../../config/constants'
98import SwitchButton from 'appirio-tech-react-components/components/SwitchButton/SwitchButton'
109import BtnGroup from '../../../../../components/BtnGroup/BtnGroup'
1110import IconSettingsWeb from '../../../../../assets/icons/settings-icon-web.svg'
12- import IconSettingsEmail from '../../../../../assets/icons/settings-icon-mail.svg'
1311import './NotificationSettingsForm.scss'
1412import _ from 'lodash'
1513
@@ -80,28 +78,22 @@ const topics = [
8078 */
8179const initSettings = ( notInitedSettings ) => {
8280 const settings = { ...notInitedSettings }
83- const notifications = { ...settings . notifications }
8481 const allTypes = _ . flatten ( _ . map ( topics , 'types' ) )
8582
8683 allTypes . forEach ( ( type ) => {
87- if ( ! notifications [ type ] ) {
88- notifications [ type ] = { }
84+ if ( ! settings [ type ] ) {
85+ settings [ type ] = { }
8986 }
9087
91- // check each of serviceId method separately as some can have
88+ // check each of deliveryMethod method separately as some can have
9289 // values and some don't have
93- [ 'web' , 'email' ] . forEach ( ( serviceId ) => {
94- if ( ! notifications [ type ] [ serviceId ] ) {
95- notifications [ type ] [ serviceId ] = { }
96- }
97- if ( _ . isUndefined ( notifications [ type ] [ serviceId ] . enabled ) ) {
98- notifications [ type ] [ serviceId ] . enabled = 'yes'
90+ [ 'web' , 'email' ] . forEach ( ( deliveryMethod ) => {
91+ if ( _ . isUndefined ( settings [ type ] [ deliveryMethod ] ) ) {
92+ settings [ type ] [ deliveryMethod ] = 'yes'
9993 }
10094 } )
10195 } )
10296
103- settings . notifications = notifications
104-
10597 return settings
10698}
10799
@@ -115,45 +107,26 @@ class NotificationSettingsForm extends React.Component {
115107 }
116108
117109 this . handleChange = this . handleChange . bind ( this )
118- this . handleBundleEmailChange = this . handleBundleEmailChange . bind ( this )
119110 }
120111
121- handleChange ( topicIndex , serviceId ) {
122- const notifications = { ...this . state . settings . notifications }
112+ handleChange ( topicIndex , deliveryMethod ) {
113+ const s = {
114+ settings : {
115+ ...this . state . settings
116+ }
117+ }
123118
124119 // update values for all types of the topic
125120 topics [ topicIndex ] . types . forEach ( ( type ) => {
126- notifications [ type ] [ serviceId ] . enabled = notifications [ type ] [ serviceId ] . enabled === 'yes' ? 'no' : 'yes'
127- } )
128-
129- this . setState ( {
130- settings : {
131- ...this . state . settings ,
132- notifications,
133- }
121+ s . settings [ type ] [ deliveryMethod ] = s . settings [ type ] [ deliveryMethod ] === 'yes' ? 'no' : 'yes'
134122 } )
135- }
136123
137- handleBundleEmailChange ( bundlePeriod ) {
138- this . setState ( {
139- settings : {
140- ...this . state . settings ,
141- services : {
142- ...this . state . settings . services ,
143- email : {
144- ...this . state . settings . services . email ,
145- // this will be send to backend which uses null instead of 'immediately'
146- bundlePeriod : bundlePeriod === 'immediately' ? null : bundlePeriod ,
147- }
148- }
149- }
150- } )
124+ this . setState ( s )
151125 }
152126
153127 render ( ) {
154128 const areSettingsProvided = ! ! this . props . values . settings
155129 const settings = this . state . settings
156- const notifications = settings . notifications
157130
158131 // if settings weren't provided (not loaded) don't render anything
159132 if ( ! areSettingsProvided ) {
@@ -172,9 +145,8 @@ class NotificationSettingsForm extends React.Component {
172145 < th > < span className = "th-with-icon" >
173146 < IconSettingsWeb className = "icon-settings-web" />
174147 < span > Web</ span > </ span > </ th >
175- < th > < span className = "th-with-icon" >
176- < IconSettingsEmail />
177- < span > Email</ span > </ span > </ th >
148+ { /* as email notification currently not supported, hide them for now */ }
149+ { /*<th><span className="th-with-icon"><img src={iconMail} /><span>Email</span></span></th>*/ }
178150 </ tr >
179151 </ thead >
180152 < tbody >
@@ -185,26 +157,37 @@ class NotificationSettingsForm extends React.Component {
185157 return (
186158 < tr key = { index } >
187159 < th > { topic . title } </ th >
188- < td > < SwitchButton onChange = { ( ) => this . handleChange ( index , 'web' ) } defaultChecked = { notifications [ topicFirstType ] . web . enabled === 'yes' } /> </ td >
189- < td > < SwitchButton onChange = { ( ) => this . handleChange ( index , 'email' ) } defaultChecked = { notifications [ topicFirstType ] . email . enabled === 'yes' } /> </ td >
160+ < td > < SwitchButton onChange = { ( ) => this . handleChange ( index , 'web' ) } defaultChecked = { settings [ topicFirstType ] && settings [ topicFirstType ] . web === 'yes' } /> </ td >
161+ { /* as email notification currently not supported, hide them for now */ }
162+ { /*<td><SwitchButton onChange={() => this.handleChange(topic, 'email')} defaultChecked={settings[topic] && settings[topic].email === 'yes'} /></td>*/ }
190163 </ tr >
191164 )
192165 } ) }
193- < tr >
166+
167+ { false && < tr >
194168 < td colSpan = "3" >
195169 < div className = "bundle-emails" >
196170 < div className = "th" > Bundle emails:</ div >
197171 < BtnGroup
198- items = { NOTIFICATION_SETTINGS_PERIODS }
199- onChange = { this . handleBundleEmailChange }
200- defaultValue = { _ . get ( this . props . values , 'settings.services.email.bundlePeriod' ) || 'immediately' }
172+ items = { [
173+ { text : 'Send as they happen' , value : 'immediately' } ,
174+ { text : 'Every hour' , value : 'hourly' } ,
175+ { text : 'Every 12h.' , value : '12h' } ,
176+ { text : 'Every 24h.' , value : '24h' }
177+ ] }
178+ defaultValue = { this . props . values . bundleEmail }
201179 />
202180 </ div >
203181 </ td >
204182 </ tr >
183+ }
205184 </ tbody >
206185 </ table >
207186
187+ < div className = "email-settings" >
188+ < a href = "https://www.topcoder.com/settings/email/" > Manage email settings</ a >
189+ </ div >
190+
208191 < div className = "controls" >
209192 < button type = "submit" className = "tc-btn tc-btn-primary" disabled = { this . props . values . pending } > Save settings</ button >
210193 </ div >
0 commit comments