Added user redux for updating profile/credentials
• Added: - user redux for updating profile/credentials
This commit is contained in:
parent
3f434d6b7c
commit
f8d2b4845d
53
app/javascript/gabsocial/actions/user.js
Normal file
53
app/javascript/gabsocial/actions/user.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import isObject from 'lodash.isobject'
|
||||||
|
import api from '../api'
|
||||||
|
import { me } from '../initial_state'
|
||||||
|
import { importAccount } from './importer'
|
||||||
|
|
||||||
|
export const SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST = 'SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST'
|
||||||
|
export const SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS = 'SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS'
|
||||||
|
export const SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL = 'SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL'
|
||||||
|
|
||||||
|
export const saveUserProfileInformation = (data) => {
|
||||||
|
return function (dispatch, getState) {
|
||||||
|
if (!isObject(data) || !me) return
|
||||||
|
|
||||||
|
dispatch(saveUserProfileInformationRequest())
|
||||||
|
|
||||||
|
const formData = new FormData()
|
||||||
|
if (data.displayName) formData.append('display_name', data.displayName)
|
||||||
|
if (data.note) formData.append('note', data.note)
|
||||||
|
if (data.avatar) formData.append('avatar', data.avatar)
|
||||||
|
if (data.header) formData.append('header', data.header)
|
||||||
|
|
||||||
|
api(getState).patch('/api/v1/accounts/update_credentials', formData, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}).then((response) => {
|
||||||
|
dispatch(importAccount(response.data))
|
||||||
|
dispatch(saveUserProfileInformationSuccess(response.data))
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(saveUserProfileInformationFail(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveUserProfileInformationRequest() {
|
||||||
|
return {
|
||||||
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveUserProfileInformationSuccess(userProfileData) {
|
||||||
|
return {
|
||||||
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS,
|
||||||
|
userProfileData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveUserProfileInformationFail(error) {
|
||||||
|
return {
|
||||||
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,7 @@ import status_revisions from './status_revisions'
|
|||||||
import suggestions from './suggestions'
|
import suggestions from './suggestions'
|
||||||
import tenor from './tenor'
|
import tenor from './tenor'
|
||||||
import timelines from './timelines'
|
import timelines from './timelines'
|
||||||
|
import user from './user'
|
||||||
import user_lists from './user_lists'
|
import user_lists from './user_lists'
|
||||||
|
|
||||||
const reducers = {
|
const reducers = {
|
||||||
@ -78,6 +79,7 @@ const reducers = {
|
|||||||
suggestions,
|
suggestions,
|
||||||
tenor,
|
tenor,
|
||||||
timelines,
|
timelines,
|
||||||
|
user,
|
||||||
user_lists,
|
user_lists,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
app/javascript/gabsocial/reducers/user.js
Normal file
24
app/javascript/gabsocial/reducers/user.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {
|
||||||
|
SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST,
|
||||||
|
SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS,
|
||||||
|
SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL,
|
||||||
|
} from '../actions/user'
|
||||||
|
import { Map as ImmutableMap } from 'immutable'
|
||||||
|
|
||||||
|
const initialState = ImmutableMap({
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default function (state = initialState, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST:
|
||||||
|
return state.set('isLoading', true)
|
||||||
|
case SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS:
|
||||||
|
return state
|
||||||
|
case SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL:
|
||||||
|
return state.set('isError', true)
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user