- {timezoneField}
-
+
+
+
+
Notifications
state.current_user;
-
-export default connect(mapStateToProps)(SettingsPreferences);
+export default SettingsPreferences;
diff --git a/app/javascript/src/services/api/endpoints.js b/app/javascript/src/services/api/endpoints.js
index 1ef90b80c..35f04ed47 100644
--- a/app/javascript/src/services/api/endpoints.js
+++ b/app/javascript/src/services/api/endpoints.js
@@ -9,6 +9,7 @@ export const TEAMS_PATH = "/client_api/teams";
export const CHANGE_TEAM_PATH = "/client_api/teams/change_team";
export const TEAM_DETAILS_PATH = "/client_api/teams/:team_id/details";
export const TEAM_UPDATE_PATH = "/client_api/teams/update";
+export const CURRENT_USER_PATH = "/client_api/current_user_info"
// search
export const SEARCH_PATH = "/search";
@@ -19,6 +20,7 @@ export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications";
// users
export const USER_PROFILE_INFO = "/client_api/users/profile_info";
export const UPDATE_USER_PATH = "/client_api/users/update";
+export const PREFERENCES_INFO_PATH = "/client_api/users/preferences_info"
// info dropdown_title
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";
diff --git a/app/javascript/src/services/api/users_api.js b/app/javascript/src/services/api/users_api.js
index 7107abb94..952c21d64 100644
--- a/app/javascript/src/services/api/users_api.js
+++ b/app/javascript/src/services/api/users_api.js
@@ -2,12 +2,15 @@ import { axiosInstance } from "./config";
import {
USER_PROFILE_INFO,
UPDATE_USER_PATH,
- CURRENT_USER_PATH
+ CURRENT_USER_PATH,
+ PREFERENCES_INFO_PATH
} from "./endpoints";
-export const getUserProfileInfo = () => {
- return axiosInstance.get(USER_PROFILE_INFO).then(({ data }) => data.user);
-};
+export const getUserProfileInfo = () =>
+ axiosInstance.get(USER_PROFILE_INFO).then(({ data }) => data.user);
+
+export const getUserPreferencesInfo = () =>
+ axiosInstance.get(PREFERENCES_INFO_PATH).then(({ data }) => data);
export const updateUser = (params, formObj = false) => {
if (formObj) {
diff --git a/app/models/user.rb b/app/models/user.rb
index 14a18f417..6f4d2ae1c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -36,7 +36,7 @@ class User < ApplicationRecord
size: { less_than: Constants::AVATAR_MAX_SIZE_MB.megabytes }
validate :time_zone_check
- store_accessor :settings, :time_zone
+ store_accessor :settings, :time_zone, :notifications
default_settings(
time_zone: 'UTC',
@@ -48,7 +48,31 @@ 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
+ NOTIFICATIONS_TYPES = %w(assignmentsNotification assignmentsEmailNotification
+ recentNotification recentEmailNotification
+ systemMessageEmailNofification)
+ # declare notifications getters
+ NOTIFICATIONS_TYPES.each do |name|
+ define_method(name) do
+ attr_name = name.slice!('Notification').underscore
+ self.notifications.fetch(attr_name.to_sym)
+ end
+ end
+ # declare notifications setters
+ NOTIFICATIONS_TYPES.each do |name|
+ define_method("#{name}=") do |value|
+ attr_name = name.slice!('Notification').underscore
+ self.notifications[attr_name.to_sym] = value
+ save
+ end
+ end
# Relations
has_many :user_teams, inverse_of: :user
has_many :teams, through: :user_teams
diff --git a/app/views/client_api/users/preferences.json.jbuilder b/app/views/client_api/users/preferences.json.jbuilder
index 493b8874b..4eded607b 100644
--- a/app/views/client_api/users/preferences.json.jbuilder
+++ b/app/views/client_api/users/preferences.json.jbuilder
@@ -1,10 +1,6 @@
-json.user do
- json.timeZone user.time_zone
- json.notifications do
- json.assignmentsNotification user.assignments_notification
- json.assignmentsNotificationEmail user.assignments_notification_email
- json.recentNotification user.recent_notification
- json.recentNotificationEmail user.recent_notification_email
- json.systemMessageNofificationEmail user.system_message_notification_email
- end
-end
+json.timeZone timeZone
+json.assignmentsNotification notifications['assignments']
+json.assignmentsEmailNotification notifications['assignments_email']
+json.recentNotification notifications['recent']
+json.recentEmailNotification notifications['recent_email']
+json.systemMessageEmailNofification notifications['system_message_email']
diff --git a/app/views/client_api/users/show.json.jbuilder b/app/views/client_api/users/show.json.jbuilder
index 91a8f4081..12a84ab9e 100644
--- a/app/views/client_api/users/show.json.jbuilder
+++ b/app/views/client_api/users/show.json.jbuilder
@@ -1,5 +1,5 @@
json.user do
json.id user.id
json.fullName user.full_name
- json.avatarPath avatar_path(user, :icon_small)
+ json.avatarThumb avatar_path(user, :icon_small)
end