diff --git a/app/controllers/client_api/users/users_controller.rb b/app/controllers/client_api/users/users_controller.rb index 9f2ca152c..25ac46519 100644 --- a/app/controllers/client_api/users/users_controller.rb +++ b/app/controllers/client_api/users/users_controller.rb @@ -58,11 +58,12 @@ module ClientApi user.time_zone = params['timezone'] timezone = if user.save - user.time_zone - else - user.reload.time_zone - errors[:timezone_errors] << 'You need to select valid TimeZone.' - end + user.time_zone + else + msg = 'You need to select valid TimeZone.' + user.reload.time_zone + errors[:timezone_errors] << msg + end respond_to do |format| format.json { render json: { timezone: timezone, errors: errors}} @@ -77,16 +78,17 @@ module ClientApi if user.valid_password? params['passwrd'] user.email = params['email'] saved_email = if user.save - user.email - else - user.reload.email - end + user.email + else + user.reload.email + end else errors[:current_password_email_field] << 'Wrong password.' end respond_to do |format| - format.json { render json: { email: saved_email || current_email, errors: errors } } + resp = { email: saved_email || current_email, errors: errors } + format.json { render json: resp } end end @@ -94,24 +96,25 @@ module ClientApi user = current_user user.name = params['fullName'] saved_name = if user.save - user.name - else - user.reload.name - end + user.name + else + user.reload.name + end respond_to do |format| - format.json { render json: { fullName: saved_name, errors: user.errors.messages } } + resp = { fullName: saved_name, errors: user.errors.messages } + format.json { render json: resp } end end def change_initials user = current_user user.initials = params['initials'] - saved_initials = if user.save - user.initials - else - user.reload.initials - end + saved_initials = if user.save + user.initials + else + user.reload.initials + end respond_to do |format| format.json { render json: { initials: saved_initials } } diff --git a/app/javascript/packs/src/settings/components/account/preferences/NotificationsSwitchGroup.jsx b/app/javascript/packs/src/settings/components/account/preferences/NotificationsSwitchGroup.jsx index 71a20da5e..26b3dee71 100644 --- a/app/javascript/packs/src/settings/components/account/preferences/NotificationsSwitchGroup.jsx +++ b/app/javascript/packs/src/settings/components/account/preferences/NotificationsSwitchGroup.jsx @@ -23,7 +23,7 @@ class NotificationsSwitchGroup extends Component { super(props); this.state = { - isSciNoteSwitchOn: false, + isSwitchOn: false, isEmailSwitchOn: false }; @@ -36,7 +36,7 @@ class NotificationsSwitchGroup extends Component { switch (this.props.type) { case ASSIGNMENT_NOTIFICATION: this.setState({ - isSciNoteSwitchOn: this.props.assignmentsNotification, + isSwitchOn: this.props.assignmentsNotification, isEmailSwitchOn: this.props.assignmentsNotificationEmail, sciNoteDispatch: state => this.props.changeAssignmentsNotification(state), @@ -46,7 +46,7 @@ class NotificationsSwitchGroup extends Component { break; case RECENT_NOTIFICATION: this.setState({ - isSciNoteSwitchOn: this.props.recentNotification, + isSwitchOn: this.props.recentNotification, isEmailSwitchOn: this.props.recentNotificationEmail, sciNoteDispatch: state => this.props.changeRecentNotification(state), emailDispatch: state => @@ -55,7 +55,7 @@ class NotificationsSwitchGroup extends Component { break; case SYSTEM_NOTIFICATION: this.setState({ - isSciNoteSwitchOn: true, + isSwitchOn: true, isEmailSwitchOn: this.props.systemMessageNotificationEmail, sciNoteDispatch: state => `${state}: Do Nothing`, emailDispatch: state => @@ -64,19 +64,19 @@ class NotificationsSwitchGroup extends Component { break; default: this.setState({ - isSciNoteSwitchOn: false, + isSwitchOn: false, isEmailSwitchOn: false }); } } toggleFirstSwitch() { - if (this.state.isSciNoteSwitchOn) { - this.setState({ isSciNoteSwitchOn: false, isEmailSwitchOn: false }); + if (this.state.isSwitchOn) { + this.setState({ isSwitchOn: false, isEmailSwitchOn: false }); this.state.sciNoteDispatch(false); this.state.emailDispatch(false); } else { - this.setState({ isSciNoteSwitchOn: true }); + this.setState({ isSwitchOn: true }); this.state.sciNoteDispatch(true); } } @@ -104,7 +104,7 @@ class NotificationsSwitchGroup extends Component {
@@ -112,7 +112,7 @@ class NotificationsSwitchGroup extends Component { title="settings_page.notify_me_via_email" isSwitchOn={this.state.isEmailSwitchOn} toggleSwitch={this.toggleSecondSwitch} - isDisabled={!this.state.isSciNoteSwitchOn} + isDisabled={!this.state.isSwitchOn} />
); diff --git a/spec/controllers/client_api/users/users_controller_spec.rb b/spec/controllers/client_api/users/users_controller_spec.rb index ed7a077fc..c23d17658 100644 --- a/spec/controllers/client_api/users/users_controller_spec.rb +++ b/spec/controllers/client_api/users/users_controller_spec.rb @@ -46,28 +46,28 @@ describe ClientApi::Users::UsersController, type: :controller do it 'responds successfully' do user = User.first expect(user.time_zone).to eq('UTC') - post :change_timezone, params: { timezone: 'Pacific/Fiji'}, format: :json + post :change_timezone, params: { timezone: 'Pacific/Fiji' }, format: :json expect(response).to have_http_status(:ok) end it 'changes timezone' do user = User.first expect(user.time_zone).to eq('UTC') - post :change_timezone, params: { timezone: 'Pacific/Fiji'}, format: :json + post :change_timezone, params: { timezone: 'Pacific/Fiji' }, format: :json expect(user.reload.time_zone).to eq('Pacific/Fiji') end end describe 'POST change_initials' do it 'responds successfully' do - post :change_initials, params: { initials: 'TD'}, format: :json + post :change_initials, params: { initials: 'TD' }, format: :json expect(response).to have_http_status(:ok) end it 'responds successfully' do user = User.first expect(user.initials).not_to eq('TD') - post :change_initials, params: { initials: 'TD'}, format: :json + post :change_initials, params: { initials: 'TD' }, format: :json expect(user.reload.initials).to eq('TD') end end