2022-04-14 08:50:47 -07:00
|
|
|
import { Record as ImmutableRecord } from 'immutable';
|
|
|
|
import { AnyAction } from 'redux';
|
2022-02-26 06:57:09 -08:00
|
|
|
|
|
|
|
import {
|
|
|
|
ACCOUNT_NOTE_INIT_MODAL,
|
|
|
|
ACCOUNT_NOTE_CHANGE_COMMENT,
|
|
|
|
ACCOUNT_NOTE_SUBMIT_REQUEST,
|
|
|
|
ACCOUNT_NOTE_SUBMIT_FAIL,
|
|
|
|
ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
|
|
|
} from '../actions/account_notes';
|
|
|
|
|
2022-04-14 08:50:47 -07:00
|
|
|
const EditRecord = ImmutableRecord({
|
|
|
|
isSubmitting: false,
|
|
|
|
account: null,
|
|
|
|
comment: null,
|
2022-02-26 06:57:09 -08:00
|
|
|
});
|
|
|
|
|
2022-04-14 08:50:47 -07:00
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
edit: EditRecord(),
|
|
|
|
});
|
|
|
|
|
|
|
|
type State = ReturnType<typeof ReducerRecord>;
|
|
|
|
|
|
|
|
export default function account_notes(state: State = ReducerRecord(), action: AnyAction) {
|
2022-02-26 06:57:09 -08:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case ACCOUNT_NOTE_INIT_MODAL:
|
|
|
|
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:
|
|
|
|
case ACCOUNT_NOTE_SUBMIT_SUCCESS:
|
|
|
|
return state.setIn(['edit', 'isSubmitting'], false);
|
|
|
|
default:
|
|
|
|
return state;
|
2022-02-26 06:57:09 -08:00
|
|
|
}
|
|
|
|
}
|