Update the alert reducer from switch to map

Switch to immutable while we're here
This commit is contained in:
Grégoire Delattre 2017-06-02 20:58:38 +02:00
parent b61be889dd
commit e286f5d2da
2 changed files with 23 additions and 25 deletions

View File

@ -1,17 +1,16 @@
import React from 'react'
import SweetAlert from 'react-bootstrap-sweetalert';
import React from "react"
import SweetAlert from "react-bootstrap-sweetalert";
export default function Alert(props) {
if (!props.alerts.show) {
if (!props.alerts.get("show")) {
return null
}
return (
<SweetAlert
type={props.alerts.type}
type={props.alerts.get("type")}
title={props.alerts.get("message")}
onConfirm={props.dismissAlert}
title={props.alerts.message}
/>
)
}

View File

@ -1,30 +1,29 @@
const defaultState = {
import { Map } from "immutable"
const defaultState = Map({
show: false,
message: "",
type: "",
};
});
export default function Alert(state = defaultState, action) {
switch (action.type) {
case 'ADD_ALERT_ERROR':
return Object.assign({}, state, {
const handlers = {
"ADD_ALERT_ERROR": (state, action) => state.merge(Map({
message: action.payload.message,
show: true,
type: "error",
})
case 'ADD_ALERT_OK':
return Object.assign({}, state, {
})),
"ADD_ALERT_OK": (state, action) => state.merge(Map({
message: action.payload.message,
show: true,
type: "success",
})
case 'DISMISS_ALERT':
return Object.assign({}, state, {
})),
"DISMISS_ALERT": state => state.merge(Map({
message: "",
show: false,
type: "",
})
default:
return state;
}
})),
}
export default (state = defaultState, action) =>
handlers[action.type] ? handlers[action.type](state, action) : state;