mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-08 23:40:44 +08:00
adds apis for full_name and initials input fields
This commit is contained in:
parent
989be6563f
commit
ccd14f6b50
4 changed files with 75 additions and 6 deletions
|
|
@ -11,6 +11,34 @@ module ClientApi
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications";
|
||||||
|
|
||||||
// users
|
// users
|
||||||
export const CURRENT_USER_PATH = "/client_api/current_user_info";
|
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
|
// info dropdown_title
|
||||||
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";
|
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
import axios from "../../app/axios";
|
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 {
|
import {
|
||||||
SET_CURRENT_USER,
|
SET_CURRENT_USER,
|
||||||
CHANGE_CURRENT_USER_FULL_NAME,
|
CHANGE_CURRENT_USER_FULL_NAME,
|
||||||
|
|
@ -35,17 +41,45 @@ export function getCurrentUser() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeFullName(name) {
|
export function savedChangedFullName({ fullName }) {
|
||||||
return {
|
return {
|
||||||
type: CHANGE_CURRENT_USER_FULL_NAME,
|
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) {
|
export function changeInitials(initials) {
|
||||||
return {
|
return dispatch => {
|
||||||
type: CHANGE_CURRENT_USER_INITIALS,
|
axios
|
||||||
payload: initials
|
.post(CHANGE_USER_INITIALS_PATH, {
|
||||||
|
withCredentials: true,
|
||||||
|
initials
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
|
dispatch(savedChangeInitials(data));
|
||||||
|
})
|
||||||
|
.catch(err => console.log(err));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,18 @@ Rails.application.routes.draw do
|
||||||
namespace :client_api, defaults: { format: 'json' } do
|
namespace :client_api, defaults: { format: 'json' } do
|
||||||
# activities
|
# activities
|
||||||
get '/activities', to: 'activities#index'
|
get '/activities', to: 'activities#index'
|
||||||
|
|
||||||
# teams
|
# teams
|
||||||
get '/teams', to: 'teams#index'
|
get '/teams', to: 'teams#index'
|
||||||
post '/change_team', to: 'teams#change_team'
|
post '/change_team', to: 'teams#change_team'
|
||||||
|
|
||||||
# notifications
|
# notifications
|
||||||
get '/recent_notifications', to: 'notifications#recent_notifications'
|
get '/recent_notifications', to: 'notifications#recent_notifications'
|
||||||
|
|
||||||
# users
|
# users
|
||||||
get '/current_user_info', to: 'users/users#current_user_info'
|
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
|
end
|
||||||
|
|
||||||
# Save sample table state
|
# Save sample table state
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue