2016-02-13 20:58:47 +05:30
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
|
2016-02-23 11:27:16 +05:30
|
|
|
import { ERROR, SET_CLIENT } from './actions';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
|
|
|
export default combineReducers({
|
2016-02-23 11:27:16 +05:30
|
|
|
error,
|
|
|
|
client
|
2016-02-13 20:58:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
function error(
|
|
|
|
state = null,
|
|
|
|
{type, payload = null, error = false}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case ERROR:
|
|
|
|
if (!error) {
|
|
|
|
throw new Error('Expected payload with error');
|
|
|
|
}
|
|
|
|
return payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 11:27:16 +05:30
|
|
|
|
|
|
|
function client(
|
|
|
|
state = null,
|
|
|
|
{type, payload = {}}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_CLIENT:
|
|
|
|
return {
|
|
|
|
id: payload.id,
|
|
|
|
name: payload.name,
|
|
|
|
description: payload.description
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|