API & Client: Profile picture

This commit is contained in:
SamR1
2018-01-01 21:54:03 +01:00
parent 8e21fc4112
commit ddb765e02d
14 changed files with 293 additions and 8 deletions

View File

@ -11,6 +11,10 @@ function AuthErrors(messages) {
return { type: 'AUTH_ERRORS', messages }
}
function PictureError(message) {
return { type: 'PICTURE_ERROR', message }
}
function ProfileSuccess(message) {
return { type: 'PROFILE_SUCCESS', message }
}
@ -151,7 +155,7 @@ export function handleProfileFormSubmit(event) {
event.preventDefault()
return (dispatch, getState) => {
const state = getState()
if (state.formProfile.formProfile.password !==
if (!state.formProfile.formProfile.password ===
state.formProfile.formProfile.passwordConf) {
dispatch(PwdError('Password and password confirmation don\'t match.'))
} else {
@ -172,3 +176,41 @@ export function handleProfileFormSubmit(event) {
}
}
export function uploadPicture (event) {
event.preventDefault()
const form = new FormData()
form.append('file', event.target.picture.files[0])
event.target.reset()
return function(dispatch) {
return mpwoApi
.updatePicture(form)
.then(ret => {
if (ret.status === 'success') {
getProfile(dispatch)
} else {
dispatch(PictureError(ret.message))
}
})
.catch(error => {
throw error
})
}
}
export function deletePicture() {
return function(dispatch) {
return mpwoApi
.deletePicture()
.then(ret => {
if (ret.status === 'success') {
getProfile(dispatch)
} else {
dispatch(PictureError(ret.message))
}
})
.catch(error => {
throw error
})
}
}