You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
5 years ago
|
import { Map as ImmutableMap } from 'immutable';
|
||
|
|
||
|
import {
|
||
|
ACCOUNT_NOTE_INIT_EDIT,
|
||
|
ACCOUNT_NOTE_CANCEL,
|
||
|
ACCOUNT_NOTE_CHANGE_COMMENT,
|
||
|
ACCOUNT_NOTE_SUBMIT_REQUEST,
|
||
|
ACCOUNT_NOTE_SUBMIT_FAIL,
|
||
|
ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
||
|
} from '../actions/account_notes';
|
||
|
|
||
|
const initialState = ImmutableMap({
|
||
|
edit: ImmutableMap({
|
||
|
isSubmitting: false,
|
||
|
account_id: null,
|
||
|
comment: null,
|
||
|
}),
|
||
|
});
|
||
|
|
||
|
export default function account_notes(state = initialState, action) {
|
||
|
switch (action.type) {
|
||
|
case ACCOUNT_NOTE_INIT_EDIT:
|
||
|
return state.withMutations((state) => {
|
||
|
state.setIn(['edit', 'isSubmitting'], false);
|
||
|
state.setIn(['edit', 'account_id'], action.account.get('id'));
|
||
|
state.setIn(['edit', 'comment'], action.comment);
|
||
|
});
|
||
|
case ACCOUNT_NOTE_CHANGE_COMMENT:
|
||
|
return state.setIn(['edit', 'comment'], action.comment);
|
||
|
case ACCOUNT_NOTE_SUBMIT_REQUEST:
|
||
|
return state.setIn(['edit', 'isSubmitting'], true);
|
||
|
case ACCOUNT_NOTE_SUBMIT_FAIL:
|
||
|
return state.setIn(['edit', 'isSubmitting'], false);
|
||
|
case ACCOUNT_NOTE_SUBMIT_SUCCESS:
|
||
|
case ACCOUNT_NOTE_CANCEL:
|
||
|
return state.withMutations((state) => {
|
||
|
state.setIn(['edit', 'isSubmitting'], false);
|
||
|
state.setIn(['edit', 'account_id'], null);
|
||
|
state.setIn(['edit', 'comment'], null);
|
||
|
});
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
}
|