Feature: Agent Profile Update with avatar (#449)

* Feature: Agent Profile Update with avatar
* Add Update Profile with name, avatar, email and password
This commit is contained in:
Pranav Raj S
2020-02-16 17:20:38 +05:30
committed by GitHub
parent e61ba95cf7
commit c4e2a84f65
25 changed files with 584 additions and 133 deletions

View File

@@ -1,5 +1,3 @@
/* eslint no-console: 0 */
/* eslint-env browser */
/* eslint no-param-reassign: 0 */
import axios from 'axios';
import moment from 'moment';
@@ -9,7 +7,8 @@ import router from '../../routes';
import authAPI from '../../api/auth';
import createAxios from '../../helper/APIHelper';
import actionCable from '../../helper/actionCable';
// initial state
import { setUser, getHeaderExpiry, clearCookiesOnLogout } from '../utils/api';
const state = {
currentUser: {
id: null,
@@ -27,15 +26,19 @@ const state = {
};
// getters
const getters = {
isLoggedIn(_state) {
return _state.currentUser.id !== null;
export const getters = {
isLoggedIn($state) {
return !!$state.currentUser.id;
},
getCurrentUserID(_state) {
return _state.currentUser.id;
},
getCurrentUser(_state) {
return _state.currentUser;
},
getSubscription(_state) {
return _state.currentUser.subscription === undefined
? null
@@ -53,7 +56,7 @@ const getters = {
};
// actions
const actions = {
export const actions = {
login({ commit }, credentials) {
return new Promise((resolve, reject) => {
authAPI
@@ -70,14 +73,21 @@ const actions = {
});
});
},
validityCheck(context) {
if (context.getters.isLoggedIn) {
authAPI.validityCheck();
async validityCheck(context) {
try {
const response = await authAPI.validityCheck();
setUser(response.data.payload.data, getHeaderExpiry(response));
context.commit(types.default.SET_CURRENT_USER);
} catch (error) {
if (error.response.status === 401) {
clearCookiesOnLogout();
}
}
},
set_user({ commit }) {
setUser({ commit, dispatch }) {
if (authAPI.isLoggedIn()) {
commit(types.default.SET_CURRENT_USER);
dispatch('validityCheck');
} else {
commit(types.default.CLEAR_USER);
}
@@ -85,6 +95,15 @@ const actions = {
logout({ commit }) {
commit(types.default.CLEAR_USER);
},
updateProfile: async ({ commit }, params) => {
try {
const response = await authAPI.profileUpdate(params);
setUser(response.data, getHeaderExpiry(response));
commit(types.default.SET_CURRENT_USER);
} catch (error) {
// Ignore error
}
},
};
// mutations
@@ -93,8 +112,12 @@ const mutations = {
_state.currentUser.id = null;
},
[types.default.SET_CURRENT_USER](_state) {
Object.assign(_state.currentUser, authAPI.getAuthData());
Object.assign(_state.currentUser, authAPI.getCurrentUser());
const currentUser = {
...authAPI.getAuthData(),
...authAPI.getCurrentUser(),
};
Vue.set(_state, 'currentUser', currentUser);
},
};