Add saving of profile photo (#19)

* Add saving of profile photo

* Add removal of profile photo

Needs work on knowing when a default photo has been supplied.

* Add action creator tests

* Fix some reference issues after merge

* Fix broken test
This commit is contained in:
Adam Butterworth
2019-02-20 11:44:47 -05:00
committed by GitHub
parent f1b6af4975
commit e7ffc6fe0c
9 changed files with 412 additions and 46 deletions

View File

@@ -1,11 +1,20 @@
import { SAVE_USER_PROFILE, EDITABLE_FIELD_CLOSE, EDITABLE_FIELD_OPEN } from '../../actions/profile';
import {
SAVE_USER_PROFILE,
SAVE_USER_PROFILE_PHOTO,
DELETE_USER_PROFILE_PHOTO,
EDITABLE_FIELD_CLOSE,
EDITABLE_FIELD_OPEN,
} from '../../actions/profile';
const initialState = {
error: null,
saveState: null,
savePhotoState: null,
currentlyEditingField: null,
};
const profile = (state = initialState, action) => {
switch (action.type) {
case EDITABLE_FIELD_OPEN:
@@ -22,6 +31,7 @@ const profile = (state = initialState, action) => {
};
}
return state;
case SAVE_USER_PROFILE.BEGIN:
return {
...state,
@@ -46,6 +56,57 @@ const profile = (state = initialState, action) => {
saveState: null,
error: null,
};
case SAVE_USER_PROFILE_PHOTO.BEGIN:
return {
...state,
savePhotoState: 'pending',
error: null,
};
case SAVE_USER_PROFILE_PHOTO.SUCCESS:
return {
...state,
savePhotoState: 'complete',
error: null,
};
case SAVE_USER_PROFILE_PHOTO.FAILURE:
return {
...state,
savePhotoState: 'error',
error: action.payload.error,
};
case SAVE_USER_PROFILE_PHOTO.RESET:
return {
...state,
savePhotoState: null,
error: null,
};
case DELETE_USER_PROFILE_PHOTO.BEGIN:
return {
...state,
savePhotoState: 'pending',
error: null,
};
case DELETE_USER_PROFILE_PHOTO.SUCCESS:
return {
...state,
savePhotoState: 'complete',
error: null,
};
case DELETE_USER_PROFILE_PHOTO.FAILURE:
return {
...state,
savePhotoState: 'error',
error: action.payload.error,
};
case DELETE_USER_PROFILE_PHOTO.RESET:
return {
...state,
savePhotoState: null,
error: null,
};
default:
return state;
}