stitch-ui
Version:
119 lines (113 loc) • 3.17 kB
JavaScript
import { createReducer } from "redux-act";
import { OrderedMap } from "immutable";
import * as actions from "./actions";
export default createReducer(
{
/* Synchronous Actions */
[actions.setEditing]: (state, payload) => ({
...state,
editing: payload,
editingClean: payload
}),
[actions.discardChanges]: state => ({
...state,
editing: state.editingClean
}),
[actions.setRespondResult]: (state, { respondResult }) => {
if (!state.editing) {
return state;
}
return {
...state,
editing: state.editing
.set("respondResult", respondResult)
.set("dirty", true)
};
},
[actions.setWebhookName]: (state, { name }) => {
if (!state.editing) {
return state;
}
return {
...state,
editing: state.editing.set("name", name).set("dirty", true)
};
},
[actions.setWebhookOptions]: (state, payload) => {
if (!state.editing) {
return state;
}
const newEditing = state.editing
.set("options", payload)
.set("dirty", true);
return { ...state, editing: newEditing };
},
/* Load */
[actions.loadIncomingWebhooksActions.req]: state => ({
...state,
loadWebhooksError: null
}),
[actions.loadIncomingWebhooksActions.rcv]: (state, payload) => ({
...state,
loadWebhooksError: payload.error,
incomingWebhooks: new OrderedMap(payload.payload),
incomingWebhooksClean: new OrderedMap(payload.payload)
}),
[actions.loadIncomingWebhooksActions.fail]: (state, payload) => ({
...state,
loadWebhooksError: payload.error
}),
/* Create */
[actions.createIncomingWebhookActions.req]: state => ({
...state,
createWebhookError: null
}),
[actions.createIncomingWebhookActions.rcv]: state => ({
...state,
createWebhookError: null
}),
[actions.createIncomingWebhookActions.fail]: (state, payload) => ({
...state,
createWebhookError: payload.error
}),
/* Remove */
[actions.removeIncomingWebhookActions.req]: state => ({
...state,
removeWebhookError: null
}),
[actions.removeIncomingWebhookActions.rcv]: state => ({
...state,
removeWebhookError: null
}),
[actions.removeIncomingWebhookActions.fail]: (state, { error }) => ({
...state,
removeWebhookError: error
}),
/* Update */
[actions.updateIncomingWebhookActions.req]: state => ({
...state,
saveWebhookError: null,
savingWebhook: true
}),
[actions.updateIncomingWebhookActions.rcv]: state => ({
...state,
saveWebhookError: null,
savingWebhook: false
}),
[actions.updateIncomingWebhookActions.fail]: (state, payload) => ({
...state,
saveWebhookError: payload.error
})
},
{
saveWebhookError: null,
removeWebhookError: null,
createWebhookError: null,
loadWebhooksError: null,
error: null,
editing: null,
savingWebhook: false,
incomingWebhooks: new OrderedMap(),
incomingWebhooksClean: new OrderedMap()
}
);