Update the alert reducer from switch to map
Switch to immutable while we're here
This commit is contained in:
parent
b61be889dd
commit
e286f5d2da
@ -1,17 +1,16 @@
|
|||||||
import React from 'react'
|
import React from "react"
|
||||||
|
import SweetAlert from "react-bootstrap-sweetalert";
|
||||||
import SweetAlert from 'react-bootstrap-sweetalert';
|
|
||||||
|
|
||||||
export default function Alert(props) {
|
export default function Alert(props) {
|
||||||
if (!props.alerts.show) {
|
if (!props.alerts.get("show")) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SweetAlert
|
<SweetAlert
|
||||||
type={props.alerts.type}
|
type={props.alerts.get("type")}
|
||||||
|
title={props.alerts.get("message")}
|
||||||
onConfirm={props.dismissAlert}
|
onConfirm={props.dismissAlert}
|
||||||
title={props.alerts.message}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,29 @@
|
|||||||
const defaultState = {
|
import { Map } from "immutable"
|
||||||
|
|
||||||
|
const defaultState = Map({
|
||||||
show: false,
|
show: false,
|
||||||
message: "",
|
message: "",
|
||||||
type: "",
|
type: "",
|
||||||
};
|
});
|
||||||
|
|
||||||
export default function Alert(state = defaultState, action) {
|
|
||||||
switch (action.type) {
|
const handlers = {
|
||||||
case 'ADD_ALERT_ERROR':
|
"ADD_ALERT_ERROR": (state, action) => state.merge(Map({
|
||||||
return Object.assign({}, state, {
|
message: action.payload.message,
|
||||||
message: action.payload.message,
|
show: true,
|
||||||
show: true,
|
type: "error",
|
||||||
type: "error",
|
})),
|
||||||
})
|
"ADD_ALERT_OK": (state, action) => state.merge(Map({
|
||||||
case 'ADD_ALERT_OK':
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
message: action.payload.message,
|
message: action.payload.message,
|
||||||
show: true,
|
show: true,
|
||||||
type: "success",
|
type: "success",
|
||||||
})
|
})),
|
||||||
case 'DISMISS_ALERT':
|
"DISMISS_ALERT": state => state.merge(Map({
|
||||||
return Object.assign({}, state, {
|
|
||||||
message: "",
|
message: "",
|
||||||
show: false,
|
show: false,
|
||||||
type: "",
|
type: "",
|
||||||
})
|
})),
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default (state = defaultState, action) =>
|
||||||
|
handlers[action.type] ? handlers[action.type](state, action) : state;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user