2020-07-15 00:44:42 +01:00
|
|
|
import isObject from 'lodash.isobject'
|
|
|
|
import api from '../api'
|
2020-10-16 22:25:37 +01:00
|
|
|
import {
|
|
|
|
me,
|
|
|
|
emailConfirmed,
|
|
|
|
} from '../initial_state'
|
2020-07-17 21:19:40 +01:00
|
|
|
import { importFetchedAccount } from './importer'
|
2020-07-15 00:44:42 +01:00
|
|
|
|
|
|
|
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'
|
2020-10-16 22:25:37 +01:00
|
|
|
export const RESEND_USER_CONFIRMATION_EMAIL_SUCCESS = 'RESEND_USER_CONFIRMATION_EMAIL_SUCCESS'
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const saveUserProfileInformation = (data) => (dispatch, getState) => {
|
|
|
|
if (!isObject(data) || !me) return
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
dispatch(saveUserProfileInformationRequest())
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
const formData = new FormData()
|
|
|
|
if (!!data.displayName) formData.append('display_name', data.displayName)
|
|
|
|
if (data.note !== undefined) formData.append('note', data.note)
|
|
|
|
if (data.avatar !== undefined) formData.append('avatar', data.avatar)
|
|
|
|
if (data.header !== undefined) formData.append('header', data.header)
|
|
|
|
if (data.locked !== undefined) formData.append('locked', data.locked)
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
api(getState).patch('/api/v1/accounts/update_credentials', formData, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'multipart/form-data'
|
|
|
|
}
|
|
|
|
}).then((response) => {
|
|
|
|
dispatch(importFetchedAccount(response.data))
|
|
|
|
dispatch(saveUserProfileInformationSuccess(response.data))
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(saveUserProfileInformationFail(error))
|
|
|
|
})
|
2020-07-15 00:44:42 +01:00
|
|
|
}
|
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
const saveUserProfileInformationRequest = () => ({
|
|
|
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_REQUEST,
|
|
|
|
})
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
const saveUserProfileInformationSuccess = (userProfileData) => ({
|
|
|
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS,
|
|
|
|
userProfileData,
|
|
|
|
})
|
2020-07-15 00:44:42 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
const saveUserProfileInformationFail = (error) => ({
|
|
|
|
type: SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
})
|
2020-10-16 22:25:37 +01:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2020-10-16 22:25:37 +01:00
|
|
|
export const resendUserConfirmationEmail = () => (dispatch, getState) => {
|
|
|
|
if (!me || emailConfirmed) return
|
|
|
|
|
|
|
|
api(getState).post('/api/v1/accounts/resend_email_confirmation').then((response) => {
|
|
|
|
dispatch({ type: RESEND_USER_CONFIRMATION_EMAIL_SUCCESS })
|
|
|
|
})
|
|
|
|
|
2020-07-15 00:44:42 +01:00
|
|
|
}
|