-
Notifications
You must be signed in to change notification settings - Fork 23
/
updateProfile.js
31 lines (28 loc) · 882 Bytes
/
updateProfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import axios from 'axios';
import API from './api';
import setAuthorizationToken from '../utils/setAuthorizationToken';
import { loginUser } from './authActions/login';
import Notify from './Notify';
import reportNetworkError from './reportNetworkError';
/**
* action creator for updating user information
*
* @param {Object} profile profile data
*
* @return {Promise} resolves with updated user data
*/
const updateProfile = profile => dispatch => (
axios.put(`${API}/users`, profile)
.then((response) => {
const token = response.data.token;
localStorage.setItem('token', token);
setAuthorizationToken(token);
Notify.success(response.data.message);
return dispatch(loginUser(response.data));
})
.catch((error) => {
reportNetworkError(error);
return Promise.reject(error);
})
);
export default updateProfile;