import { Map } from "immutable";
import React from "react";
import Snackbar from "material-ui/Snackbar";
import { connect } from "react-redux";
import { shouldComponentUpdate } from "react-immutable-render-mixin";
import { getLastError } from "../ErrorReducer";

class ErrorSnackbar extends React.PureComponent {
  static defaultProps = {
    error: null
  };

  constructor(props) {
    super(props);
    this.shouldComponentUpdate = shouldComponentUpdate.bind(this);
    this.state = {
      open: false
    };
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.error !== nextProps.error) {
      this.setState({ open: true });
    }
  }

  handleRequestClose = () => {
    this.setState({ open: false });
  };

  render() {
    const { error } = this.props;
    const { open } = this.state;
    let message = "";
    if (typeof error === "string") {
      message = error;
    } else if (Map.isMap(error)) {
      message =
        error.get("message") ||
        error.get("errmsg") ||
        error.get("msg") ||
        error.get("name");
    }
    return (
      <Snackbar
        bodyStyle={{
          backgroundColor: "rgba(100, 0, 0, 0.87)"
        }}
        open={message ? open : false}
        message={message}
        autoHideDuration={3333}
        onRequestClose={this.handleRequestClose}
      />
    );
  }
}

function mapStateToProps(store) {
  const error = getLastError(store);
  return { error };
}

export default connect(mapStateToProps)(ErrorSnackbar);

@@ -256,16 +256,163 @@
 ucer%22;%0A%0A
+export function getStyles() %7B%0A  const styles = %7B%0A    snackbarBody: %7B%0A      backgroundColor: %22rgba(100, 0, 0, 0.87)%22%0A    %7D%0A  %7D;%0A  return styles;%0A%7D%0A%0A
 class Er
@@ -877,24 +877,56 @@
  render() %7B%0A
+    const styles = getStyles();%0A
     const %7B 
@@ -999,13 +999,8 @@
 sage
- = %22%22
 ;%0A  
@@ -1226,16 +1226,49 @@
 name%22);%0A
+    %7D else %7B%0A      message = %22%22;%0A
     %7D%0A  
@@ -1317,70 +1317,27 @@
 le=%7B
-%7B%0A          backgroundColor: %22rgba(100, 0, 0, 0.87)%22%0A        %7D
+styles.snackbarBody
 %7D%0A  

Tidy ErrorSnackbar.