adds apis for full_name and initials input fields

This commit is contained in:
Toni Dezman 2017-08-25 14:45:02 +02:00
parent 989be6563f
commit ccd14f6b50
4 changed files with 75 additions and 6 deletions

View file

@ -11,6 +11,34 @@ module ClientApi
end
end
end
def change_full_name
user = current_user
user.name = params['fullName']
saved_name = if user.save
user.name
else
user.reload.name
end
respond_to do |format|
format.json { render json: { fullName: saved_name } }
end
end
def change_initials
user = current_user
user.initials = params['initials']
saved_initials = if user.save
user.initials
else
user.reload.initials
end
respond_to do |format|
format.json { render json: { initials: saved_initials } }
end
end
end
end
end

View file

@ -23,6 +23,8 @@ export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications";
// users
export const CURRENT_USER_PATH = "/client_api/current_user_info";
export const CHANGE_USER_FULL_NAME_PATH = "/client_api/user/change_full_name";
export const CHANGE_USER_INITIALS_PATH = "/client_api/user/change_initials";
// info dropdown_title
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";

View file

@ -1,5 +1,11 @@
import axios from "../../app/axios";
import { CURRENT_USER_PATH } from "../../app/routes";
import {
CHANGE_USER_FULL_NAME_PATH,
CURRENT_USER_PATH,
CHANGE_USER_INITIALS_PATH
} from "../../app/routes";
import {
SET_CURRENT_USER,
CHANGE_CURRENT_USER_FULL_NAME,
@ -35,17 +41,45 @@ export function getCurrentUser() {
};
}
export function changeFullName(name) {
export function savedChangedFullName({ fullName }) {
return {
type: CHANGE_CURRENT_USER_FULL_NAME,
payload: name
payload: fullName
};
}
export function changeFullName(name) {
return dispatch => {
axios
.post(CHANGE_USER_FULL_NAME_PATH, {
withCredentials: true,
fullName: name
})
.then(({ data }) => {
dispatch(savedChangedFullName(data));
})
.catch(err => console.log(err));
};
}
export function savedChangeInitials({ initials }) {
return {
type: CHANGE_CURRENT_USER_INITIALS,
payload: initials
};
}
export function changeInitials(initials) {
return {
type: CHANGE_CURRENT_USER_INITIALS,
payload: initials
return dispatch => {
axios
.post(CHANGE_USER_INITIALS_PATH, {
withCredentials: true,
initials
})
.then(({ data }) => {
dispatch(savedChangeInitials(data));
})
.catch(err => console.log(err));
};
}

View file

@ -15,13 +15,18 @@ Rails.application.routes.draw do
namespace :client_api, defaults: { format: 'json' } do
# activities
get '/activities', to: 'activities#index'
# teams
get '/teams', to: 'teams#index'
post '/change_team', to: 'teams#change_team'
# notifications
get '/recent_notifications', to: 'notifications#recent_notifications'
# users
get '/current_user_info', to: 'users/users#current_user_info'
post '/user/change_full_name', to: 'users/users#change_full_name'
post '/user/change_initials', to: 'users/users#change_initials'
end
# Save sample table state