From c8c8afdd1db779378e2dce22481bc6165e3b83d0 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 28 Sep 2017 15:00:54 +0200 Subject: [PATCH] update react-bootstrap --- .../client_api/users/users_controller.rb | 15 -- app/javascript/src/assets/missing.png | Bin 0 -> 1859 bytes .../src/components/actions/UsersActions.js | 138 --------------- .../src/components/reducers/UsersReducer.js | 65 ++----- app/javascript/src/config/action_types.js | 10 -- app/javascript/src/config/api_endpoints.js | 2 - app/javascript/src/config/locales/messages.js | 1 + .../components/NotificationsGroup.jsx | 112 ++++++++++--- .../components/NotificationsSwitch.jsx | 98 ++++++----- .../components/NotificationsSwitchGroup.jsx | 158 ------------------ .../SettingsPage/scenes/preferences/index.jsx | 38 ++--- app/models/user.rb | 9 +- yarn.lock | 4 +- 13 files changed, 175 insertions(+), 475 deletions(-) create mode 100644 app/javascript/src/assets/missing.png delete mode 100644 app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitchGroup.jsx diff --git a/app/controllers/client_api/users/users_controller.rb b/app/controllers/client_api/users/users_controller.rb index 0f37d089b..37bc5913c 100644 --- a/app/controllers/client_api/users/users_controller.rb +++ b/app/controllers/client_api/users/users_controller.rb @@ -76,21 +76,6 @@ module ClientApi :time_zone) end - def change_notification(dinamic_param, params) - user = current_user - user[dinamic_param] = params['status'] - status = - if user.save - user[dinamic_param] - else - user.reload[dinamic_param] - end - - respond_to do |format| - format.json { render json: { status: status } } - end - end - def success_response(template = nil, locals = nil) respond_to do |format| format.json do diff --git a/app/javascript/src/assets/missing.png b/app/javascript/src/assets/missing.png new file mode 100644 index 0000000000000000000000000000000000000000..b13b08127eeba4ca630ebfa06ea6d235358a5fc1 GIT binary patch literal 1859 zcmV-J2fX-+P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qRNAp5A000KENklJ63*7t1Fuho$!Qja}Pb@dbvaH)wdoeKpA33#JH9~1tD z@DQ)q2pFE_Pp$KvGu4Zl#)~iUJwu{X1`|X6SU4nwLw?WZ;{5#5!keIXO9}^Lp#U2M z8v%2#Sf^|rQR|qa!UXz4r?GHA5<>AvSQ3O;`)q4l$4?CgsH3xcd0`JTNfCQB}=YZK=4JiisE^1`0Oko6G#hF+xTS zqmh=13}G~rh^6DP!5Xhx!T0>DS6Nv~NunH$Ft+NO)S5nU1q{1*;azv45t`xyF%&>< zjG9X(Y*rgbs#UY0E#UR$l5vF{4zl@%6Q62Y1ry_|E7)#e*SA4JMpFzHLq@`&=2P

_{9a~SnQ1j@C1<*XkW4HTG*4T&zW%eUW(!Q~z%*^@n66zl zXY5UhXk>C?s;Q}!>*a^k*wi{cI*x5l4EkBx)iq7dk4I!}(RvQJ$tuF=$igMX9QV0B zQoH_#Y1aZ&;W?Uhc6RslJQ*9C*l@X$QdBK5#EEG}v?`cX zmT%n^ppF?B`v8{Eb~dxOy?waN%eE@#rIz0%J4`_t3Pp$f)+q6MRj z>Nv(6SHWR`nPU~4&t~9BE3E9Rt1sWaefx5C_3@A2lX5bX&YYc|+zn=POp2=t#vE6{ zx~Pi)zdx?TB}q$V`t#x^;U;dTP7wD7bqw;|obs?ojU7cf{V_Ma0vt)BD(NiHO z$BUWtZn03_+dZk2w+neKlF8%oUYwtwpPgB)Gx*uu+QP9SQ&1KKd{am#OZhx{IW8ZZRw_7pwNwaccXXiOALE3;&(V>wlgi=Y zyFCmSY0*tPiu|HMKfuazqU)GAW?)3mz(^YhFs2!sElV4{pf3cNPA2>M2DM?TQBi8z&!vwBD%XQi@~sEKJ@waBq}a|?iJe2MS#sl;}bEk&a^bU7sS?CA*VpLoq> zi|Hi04&V~O?B3+epU2cR#zJaaJJU39+&#d?oFQ`|7%&=pI4T6NC`5|c47?I*3_GQO zRiw@?EUER(q<}F5W*UXZ))fsL7cPOZakgh=*);r&L#i4Z9nU5cs#ivZ0oWkRm)WIP z9|g>eli$QN`L6@oY1qVfT!@6cKD*6+$2|m>g}E2MguIv|Tr_W}{!LvmtExuLM0YW^ zrrBhNe4eE@Zw3d34TkzB5~r4yj^QEG%EAJ^B~*mGUgwGl>A=*ta3>hD4rl&7o%+^r!j#rl!dVBl0j~_&X z{e!OMMetOX4m@Liu&WlQh6cl&eOAlTMQxdy=012p*{wG4RF)1r{qrQ(`T;d#vFO06 xcW82Af@}SNvYE|Vmd^3y`2PyF+^`%g{{X!@mDwIAlDGf>002ovPDHLkV1mb%b6x-d literal 0 HcmV?d00001 diff --git a/app/javascript/src/components/actions/UsersActions.js b/app/javascript/src/components/actions/UsersActions.js index 215710318..c1556280c 100644 --- a/app/javascript/src/components/actions/UsersActions.js +++ b/app/javascript/src/components/actions/UsersActions.js @@ -1,22 +1,7 @@ import axios from "../../config/axios"; -import { - CHANGE_USER_TIMEZONE_PATH, - CHANGE_USER_ASSIGNEMENTS_NOTIFICATION_PATH, - CHANGE_USER_ASSIGNMENTS_NOTIFICATION_EMAIL_PATH, - CHANGE_USER_RECENT_NOTIFICATION_PATH, - CHANGE_USER_RECENT_NOTIFICATION_EMAIL_PATH, - CHANGE_USER_SYSTEM_MESSAGE_NOTIFICATION_EMAIL_PATH -} from "../../config/api_endpoints"; - import { SET_CURRENT_USER, - CHANGE_CURRENT_USER_TIMEZONE, - CHANGE_ASSIGNMENTS_NOTIFICATION, - CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL, - CHANGE_RECENT_NOTIFICATION, - CHANGE_RECENT_NOTIFICATION_EMAIL, - CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL } from "../../config/action_types"; export function addCurrentUser(data) { @@ -25,126 +10,3 @@ export function addCurrentUser(data) { payload: data }; } - -export function saveTimezone({ timezone }) { - return { - type: CHANGE_CURRENT_USER_TIMEZONE, - payload: timezone - }; -} - -export function changeTimezone(timezone) { - return dispatch => { - axios - .post(CHANGE_USER_TIMEZONE_PATH, { withCredentials: true, timezone }) - .then(({ data }) => { - dispatch(saveTimezone(data)); - }) - .catch(err => console.log(err)); - }; -} - -export function saveAssignmentsNotification({ status }) { - return { - type: CHANGE_ASSIGNMENTS_NOTIFICATION, - payload: status - }; -} - -export function changeAssignmentsNotification(status) { - return dispatch => { - axios - .post(CHANGE_USER_ASSIGNEMENTS_NOTIFICATION_PATH, { - withCredentials: true, - status - }) - .then(({ data }) => { - dispatch(saveAssignmentsNotification(data)); - }) - .catch(err => console.log(err)); - }; -} - -export function saveAssignmentsNotificationEmail({ status }) { - return { - type: CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL, - payload: status - }; -} - -export function changeAssignmentsNotificationEmail(status) { - return dispatch => { - axios - .post(CHANGE_USER_ASSIGNMENTS_NOTIFICATION_EMAIL_PATH, { - withCredentials: true, - status - }) - .then(({ data }) => { - dispatch(saveAssignmentsNotificationEmail(data)); - }) - .catch(err => console.log(err)); - }; -} - -export function saveRecentNotification({ status }) { - return { - type: CHANGE_RECENT_NOTIFICATION, - payload: status - }; -} - -export function changeRecentNotification(status) { - return dispatch => { - axios - .post(CHANGE_USER_RECENT_NOTIFICATION_PATH, { - withCredentials: true, - status - }) - .then(({ data }) => { - dispatch(saveRecentNotification(data)); - }) - .catch(err => console.log(err)); - }; -} - -export function saveRecentNotificationEmail({ status }) { - return { - type: CHANGE_RECENT_NOTIFICATION_EMAIL, - payload: status - }; -} - -export function changeRecentNotificationEmail(status) { - return dispatch => { - axios - .post(CHANGE_USER_RECENT_NOTIFICATION_EMAIL_PATH, { - withCredentials: true, - status - }) - .then(({ data }) => { - dispatch(saveRecentNotificationEmail(data)); - }) - .catch(err => console.log(err)); - }; -} - -export function saveSystemMessageNotificationEmail({ status }) { - return { - type: CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL, - payload: status - }; -} - -export function changeSystemMessageNotificationEmail(status) { - return dispatch => { - axios - .post(CHANGE_USER_SYSTEM_MESSAGE_NOTIFICATION_EMAIL_PATH, { - withCredentials: true, - status - }) - .then(({ data }) => { - dispatch(saveSystemMessageNotificationEmail(data)); - }) - .catch(err => console.log(err)); - }; -} diff --git a/app/javascript/src/components/reducers/UsersReducer.js b/app/javascript/src/components/reducers/UsersReducer.js index bccfeaede..0de21684f 100644 --- a/app/javascript/src/components/reducers/UsersReducer.js +++ b/app/javascript/src/components/reducers/UsersReducer.js @@ -1,54 +1,17 @@ -import { - SET_CURRENT_USER, - CHANGE_CURRENT_USER_TIMEZONE, - CHANGE_ASSIGNMENTS_NOTIFICATION, - CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL, - CHANGE_RECENT_NOTIFICATION, - CHANGE_RECENT_NOTIFICATION_EMAIL, - CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL -} from "../../config/action_types"; +import { SET_CURRENT_USER } from "../../config/action_types"; -export function currentUser( - state = { - id: 0, - fullName: "", - initials: "", - email: "", - avatarPath: "", - avatarThumbPath: "", - timezone: "", - assignmentsNotification: false, - assignmentsNotificationEmail: false, - recentNotification: false, - recentNotificationEmail: false, - systemMessageNotificationEmail: false - }, - action -) { - switch (action.type) { - case SET_CURRENT_USER: - return Object.assign({}, state, action.payload); - case CHANGE_CURRENT_USER_TIMEZONE: - return Object.assign({}, state, { timezone: action.payload }); - case CHANGE_ASSIGNMENTS_NOTIFICATION: - return Object.assign({}, state, { - assignmentsNotification: action.payload - }); - case CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL: - return Object.assign({}, state, { - assignmentsNotificationEmail: action.payload - }); - case CHANGE_RECENT_NOTIFICATION: - return Object.assign({}, state, { recentNotification: action.payload }); - case CHANGE_RECENT_NOTIFICATION_EMAIL: - return Object.assign({}, state, { - recentNotificationEmail: action.payload - }); - case CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL: - return Object.assign({}, state, { - systemMessageNotificationEmail: action.payload - }); - default: - return state; +const initialState = { + id: 0, + fullName: "", + initials: "", + email: "", + avatarPath: "", + avatarThumbPath: "" +}; + +export function currentUser(state = initialState, action) { + if (action.type === SET_CURRENT_USER) { + return Object.assign({}, state, action.payload); } + return state; } diff --git a/app/javascript/src/config/action_types.js b/app/javascript/src/config/action_types.js index 62e2b9e3b..aa640fdaa 100644 --- a/app/javascript/src/config/action_types.js +++ b/app/javascript/src/config/action_types.js @@ -9,16 +9,6 @@ export const DESTROY_GLOBAL_ACTIVITIES_DATA = "DESTROY_GLOBAL_ACTIVITIES_DATA"; // users export const SET_CURRENT_USER = "SET_CURRENT_USER"; -export const CHANGE_CURRENT_USER_TIMEZONE = "CHANGE_CURRENT_USER_TIMEZONE"; -export const CHANGE_ASSIGNMENTS_NOTIFICATION = - "CHANGE_ASSIGNMENTS_NOTIFICATION"; -export const CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL = - "CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL"; -export const CHANGE_RECENT_NOTIFICATION = "CHANGE_RECENT_NOTIFICATION"; -export const CHANGE_RECENT_NOTIFICATION_EMAIL = - "CHANGE_RECENT_NOTIFICATION_EMAIL"; -export const CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL = - "CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL"; // user teams export const LEAVE_TEAM = "LEAVE_TEAM"; diff --git a/app/javascript/src/config/api_endpoints.js b/app/javascript/src/config/api_endpoints.js index 3265dbf76..8c644a23b 100644 --- a/app/javascript/src/config/api_endpoints.js +++ b/app/javascript/src/config/api_endpoints.js @@ -17,8 +17,6 @@ export const SEARCH_PATH = "/search"; // notifications export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications"; -// users - // info dropdown_title export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support"; export const TUTORIALS_LINK = "http://scinote.net/product/tutorials/"; diff --git a/app/javascript/src/config/locales/messages.js b/app/javascript/src/config/locales/messages.js index 185054f76..6c15e2b5a 100644 --- a/app/javascript/src/config/locales/messages.js +++ b/app/javascript/src/config/locales/messages.js @@ -55,6 +55,7 @@ export default { time_zone_warning: "Time zone setting affects all time & date fields throughout application.", repeat_tutorial: "Repeat tutorial", + notifications: "Notifications", profile: "Profile", preferences: "Preferences", assignement: "Assignement", diff --git a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsGroup.jsx b/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsGroup.jsx index d75e895a4..585fc7148 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsGroup.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsGroup.jsx @@ -1,10 +1,17 @@ import React, { Component } from "react"; -import PropTypes from "prop-types"; +import { string, bool, func } from "prop-types"; import styled from "styled-components"; import { FormattedMessage } from "react-intl"; -import NotificationsSwitchGroup from "./NotificationsSwitchGroup"; +import { updateUser } from "../../../../../services/api/users_api"; +import NotificationsSwitch from "./NotificationsSwitch"; +import { + RECENT_NOTIFICATION, + SYSTEM_NOTIFICATION, + ASSIGNMENT_NOTIFICATION +} from "../../../../../config/constants/strings"; import { WHITE_COLOR } from "../../../../../config/constants/colors"; +import avatarImg from "../../../../../assets/missing.png"; const Wrapper = styled.div`margin-bottom: 6px;`; @@ -40,29 +47,66 @@ const Image = styled.span` class NotificationsGroup extends Component { constructor(props) { super(props); + this.notificationImage = this.notificationImage.bind(this); + this.inAppNotificationField = this.inAppNotificationField.bind(this); + this.emailNotificationField = this.emailNotificationField.bind(this); + this.updateStatus = this.updateStatus.bind(this); } - render() { - let imgOrIcon; - - if (this.props.imgUrl === "") { - imgOrIcon = ( - - - - ); - } else { - imgOrIcon = ( + notificationImage() { + if (this.props.type === RECENT_NOTIFICATION) { + return ( - default avatar + default avatar ); } + return ( + + + + ); + } + inAppNotificationField() { + switch (this.props.type) { + case ASSIGNMENT_NOTIFICATION: + return "assignmentsNotification"; + case RECENT_NOTIFICATION: + return "recentNotification"; + case SYSTEM_NOTIFICATION: + return "systemMessageEmailNofification"; + default: + return ""; + } + } + + emailNotificationField() { + switch (this.props.type) { + case ASSIGNMENT_NOTIFICATION: + return "assignmentsEmailNotification"; + case RECENT_NOTIFICATION: + return "recentEmailNotification"; + default: + return ""; + } + } + + updateStatus(actionType, value) { + if (actionType === "inAppNotification") { + const inAppField = this.inAppNotificationField(); + updateUser({ [inAppField]: value }).then(() => this.props.reloadInfo()); + } else if (actionType === "emailNotification") { + const emailField = this.emailNotificationField(); + updateUser({ [emailField]: value }).then(() => this.props.reloadInfo()); + } + } + + render() { return ( - {imgOrIcon} + {this.notificationImage()}

@@ -73,7 +117,22 @@ class NotificationsGroup extends Component {

- +
+ + this.updateStatus("inAppNotification", value)} + isDisabled={false} + /> + + this.updateStatus("emailNotification", value)} + isDisabled={this.props.type === SYSTEM_NOTIFICATION} + /> +
); @@ -81,12 +140,21 @@ class NotificationsGroup extends Component { } NotificationsGroup.propTypes = { - title: PropTypes.string.isRequired, - subtitle: PropTypes.string.isRequired, - type: PropTypes.string.isRequired, - imgUrl: PropTypes.string.isRequired, - iconClasses: PropTypes.string.isRequired, - iconBackground: PropTypes.string.isRequired + title: string.isRequired, + subtitle: string.isRequired, + type: string.isRequired, + iconClasses: string, + iconBackground: string, + inAppNotification: bool, + emailNotification: bool, + reloadInfo: func.isRequired +}; + +NotificationsGroup.defaultProps = { + iconClasses: "", + iconBackground: "", + emailNotification: false, + inAppNotification: false }; export default NotificationsGroup; diff --git a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitch.jsx b/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitch.jsx index b3ac1853f..0ba82c467 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitch.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitch.jsx @@ -1,5 +1,10 @@ import React, { Component } from "react"; -import PropTypes from "prop-types"; +import { string, bool, func } from "prop-types"; +import { + ButtonToolbar, + ToggleButtonGroup, + ToggleButton +} from "react-bootstrap"; import styled from "styled-components"; import { FormattedMessage } from "react-intl"; @@ -27,66 +32,59 @@ const RightButton = styled.button` class NotificationsSwitch extends Component { constructor(props) { super(props); - + this.state = { status: this.props.status }; this.handleClick = this.handleClick.bind(this); + this.disabledButton = this.disabledButton.bind(this); } - handleClick() { + handleClick(value) { if (!this.props.isDisabled) { - this.props.toggleSwitch(); + this.props.updateStatus(value); } } - render() { - let switchBtn; - - if (this.props.isSwitchOn) { - switchBtn = ( -
- - - - - - -
- ); - } else { - switchBtn = ( -
- - - - - - -
+ disabledButton() { + if (this.props.isDisabled) { + return ( + + + No + + + Yes + + ); } - + return ( + + + No + + + Yes + + + ); + } + render() { return (
- {switchBtn} + {this.disabledButton()}
); @@ -94,10 +92,10 @@ class NotificationsSwitch extends Component { } NotificationsSwitch.propTypes = { - title: PropTypes.string.isRequired, - isSwitchOn: PropTypes.bool.isRequired, - isDisabled: PropTypes.bool.isRequired, - toggleSwitch: PropTypes.func.isRequired + title: string.isRequired, + status: bool.isRequired, + isDisabled: bool.isRequired, + updateStatus: func.isRequired }; export default NotificationsSwitch; diff --git a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitchGroup.jsx b/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitchGroup.jsx deleted file mode 100644 index 00242357a..000000000 --- a/app/javascript/src/scenes/SettingsPage/scenes/preferences/components/NotificationsSwitchGroup.jsx +++ /dev/null @@ -1,158 +0,0 @@ -import React, { Component } from "react"; -import { connect } from "react-redux"; -import { string, bool, func } from "prop-types"; - -import NotificationsSwitch from "./NotificationsSwitch"; - -import { - ASSIGNMENT_NOTIFICATION, - RECENT_NOTIFICATION, - SYSTEM_NOTIFICATION -} from "../../../../../config/constants/strings"; - -import { - changeAssignmentsNotification, - changeAssignmentsNotificationEmail, - changeRecentNotification, - changeRecentNotificationEmail, - changeSystemMessageNotificationEmail -} from "../../../../../components/actions/UsersActions"; - -class NotificationsSwitchGroup extends Component { - constructor(props) { - super(props); - - this.state = { - isSwitchOn: false, - isEmailSwitchOn: false - }; - - this.toggleFirstSwitch = this.toggleFirstSwitch.bind(this); - this.toggleSecondSwitch = this.toggleSecondSwitch.bind(this); - this.isSwitchDisabled = this.isSwitchDisabled.bind(this); - } - - componentWillMount() { - switch (this.props.type) { - case ASSIGNMENT_NOTIFICATION: - this.setState({ - isSwitchOn: this.props.assignmentsNotification, - isEmailSwitchOn: this.props.assignmentsNotificationEmail, - sciNoteDispatch: state => - this.props.changeAssignmentsNotification(state), - emailDispatch: state => - this.props.changeAssignmentsNotificationEmail(state) - }); - break; - case RECENT_NOTIFICATION: - this.setState({ - isSwitchOn: this.props.recentNotification, - isEmailSwitchOn: this.props.recentNotificationEmail, - sciNoteDispatch: state => this.props.changeRecentNotification(state), - emailDispatch: state => - this.props.changeRecentNotificationEmail(state) - }); - break; - case SYSTEM_NOTIFICATION: - this.setState({ - isSwitchOn: true, - isEmailSwitchOn: this.props.systemMessageNotificationEmail, - sciNoteDispatch: state => `${state}: Do Nothing`, - emailDispatch: state => - this.props.changeSystemMessageNotificationEmail(state) - }); - break; - default: - this.setState({ - isSwitchOn: false, - isEmailSwitchOn: false - }); - } - } - - toggleFirstSwitch() { - if (this.state.isSwitchOn) { - this.setState({ isSwitchOn: false, isEmailSwitchOn: false }); - this.state.sciNoteDispatch(false); - this.state.emailDispatch(false); - } else { - this.setState({ isSwitchOn: true }); - this.state.sciNoteDispatch(true); - } - } - - toggleSecondSwitch() { - if (this.state.isEmailSwitchOn) { - this.setState({ isEmailSwitchOn: false }); - this.state.emailDispatch(false); - } else { - this.setState({ isEmailSwitchOn: true }); - this.state.emailDispatch(true); - } - } - - isSwitchDisabled() { - if (this.props.type === SYSTEM_NOTIFICATION) { - return true; - } - - return false; - } - - render() { - return ( -
- - -
- ); - } -} - -// TODO get rid of unnecesary proptypes -NotificationsSwitchGroup.propTypes = { - type: string.isRequired, - assignmentsNotification: bool.isRequired, - assignmentsNotificationEmail: bool.isRequired, - recentNotification: bool.isRequired, - recentNotificationEmail: bool.isRequired, - systemMessageNotificationEmail: bool.isRequired, - changeAssignmentsNotification: func.isRequired, - changeAssignmentsNotificationEmail: func.isRequired, - changeRecentNotification: func.isRequired, - changeRecentNotificationEmail: func.isRequired, - changeSystemMessageNotificationEmail: func.isRequired -}; - -const mapStateToProps = state => state.current_user; -const mapDispatchToProps = dispatch => ({ - changeAssignmentsNotification(status) { - dispatch(changeAssignmentsNotification(status)); - }, - changeAssignmentsNotificationEmail(status) { - dispatch(changeAssignmentsNotificationEmail(status)); - }, - changeRecentNotification(status) { - dispatch(changeRecentNotification(status)); - }, - changeRecentNotificationEmail(status) { - dispatch(changeRecentNotificationEmail(status)); - }, - changeSystemMessageNotificationEmail(status) { - dispatch(changeSystemMessageNotificationEmail(status)); - } -}); - -export default connect(mapStateToProps, mapDispatchToProps)( - NotificationsSwitchGroup -); diff --git a/app/javascript/src/scenes/SettingsPage/scenes/preferences/index.jsx b/app/javascript/src/scenes/SettingsPage/scenes/preferences/index.jsx index 3529564ab..5f249157c 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/preferences/index.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/preferences/index.jsx @@ -1,7 +1,5 @@ import React, { Component } from "react"; import { FormattedMessage } from "react-intl"; -import { Button } from "react-bootstrap"; -import styled from "styled-components"; import { getUserPreferencesInfo } from "../../../../services/api/users_api"; import SettingsAccountWrapper from "../../components/SettingsAccountWrapper"; @@ -16,15 +14,9 @@ import { import { MAIN_COLOR_BLUE, - ICON_GREEN_COLOR, - BORDER_LIGHT_COLOR + ICON_GREEN_COLOR } from "../../../../config/constants/colors"; -const TutorialWrapper = styled.div` - margin: 20px 0; - padding-bottom: 15px; - border-bottom: 1px solid ${BORDER_LIGHT_COLOR}; -` class SettingsPreferences extends Component { constructor(props) { super(props); @@ -38,7 +30,7 @@ class SettingsPreferences extends Component { systemMessageEmailNofification: false }; - this.getPreferencesInfo = this.getPreferencesInfo.bind(this) + this.getPreferencesInfo = this.getPreferencesInfo.bind(this); } componentDidMount() { @@ -59,35 +51,39 @@ class SettingsPreferences extends Component { value={this.state.timeZone} loadPreferences={this.getPreferencesInfo} /> - - - -

Notifications

+

+ +

diff --git a/app/models/user.rb b/app/models/user.rb index 6f4d2ae1c..e5ae9fb63 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,12 +48,8 @@ class User < ApplicationRecord system_message_email: false } ) - # json.assignmentsNotification notifications['assignments'] - # json.assignmentsEmailNotification notifications['assignments_email'] - # json.recentNotification notifications['recent'] - # json.recentEmailNotification notifications['recent_email'] - # json.systemMessageEmailNofification notifications['system_message_email'] - # joson friendly attributes + + # json friendly attributes NOTIFICATIONS_TYPES = %w(assignmentsNotification assignmentsEmailNotification recentNotification recentEmailNotification systemMessageEmailNofification) @@ -67,6 +63,7 @@ class User < ApplicationRecord # declare notifications setters NOTIFICATIONS_TYPES.each do |name| + next if name == 'systemMessageEmailNofification' define_method("#{name}=") do |value| attr_name = name.slice!('Notification').underscore self.notifications[attr_name.to_sym] = value diff --git a/yarn.lock b/yarn.lock index 325f88e95..db3189d70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4685,8 +4685,8 @@ react-bootstrap-timezone-picker@^1.0.11: prop-types "^15.5.10" react-bootstrap@^0.31.1: - version "0.31.2" - resolved "https://registry.yarnpkg.com/react-bootstrap/-/react-bootstrap-0.31.2.tgz#f59184676ecedfc4c572d29ffdd6f9126ea8fe6a" + version "0.31.3" + resolved "https://registry.yarnpkg.com/react-bootstrap/-/react-bootstrap-0.31.3.tgz#db2b7d45b00b5dac1ab8b6de3dd97feb3091b849" dependencies: babel-runtime "^6.11.6" classnames "^2.2.5"