remove www directory, as it is a build artefact
replace custom made notification component with notistack
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { withNotifier } from '../components/SnackbarNotification';
|
||||
import { withSnackbar } from 'notistack';
|
||||
import { redirectingAuthorizedFetch } from '../authentication/Authentication';
|
||||
/*
|
||||
* It is unlikely this application will grow complex enough to require redux.
|
||||
@ -10,7 +10,7 @@ import { redirectingAuthorizedFetch } from '../authentication/Authentication';
|
||||
*/
|
||||
export const restComponent = (endpointUrl, FormComponent) => {
|
||||
|
||||
return withNotifier(
|
||||
return withSnackbar(
|
||||
class extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
@ -51,7 +51,9 @@ export const restComponent = (endpointUrl, FormComponent) => {
|
||||
})
|
||||
.then(json => { this.setState({ data: json, fetched: true }) })
|
||||
.catch(error => {
|
||||
this.props.raiseNotification("Problem fetching: " + error.message);
|
||||
this.props.enqueueSnackbar("Problem fetching: " + error.message, {
|
||||
variant: 'error',
|
||||
});
|
||||
this.setState({ data: null, fetched: true, errorMessage: error.message });
|
||||
});
|
||||
}
|
||||
@ -72,10 +74,14 @@ export const restComponent = (endpointUrl, FormComponent) => {
|
||||
throw Error("Invalid status code: " + response.status);
|
||||
})
|
||||
.then(json => {
|
||||
this.props.raiseNotification("Changes successfully applied.");
|
||||
this.props.enqueueSnackbar("Changes successfully applied.", {
|
||||
variant: 'success',
|
||||
});
|
||||
this.setState({ data: json, fetched: true });
|
||||
}).catch(error => {
|
||||
this.props.raiseNotification("Problem saving: " + error.message);
|
||||
this.props.enqueueSnackbar("Problem saving: " + error.message, {
|
||||
variant: 'error',
|
||||
});
|
||||
this.setState({ data: null, fetched: true, errorMessage: error.message });
|
||||
});
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
import React, {Fragment} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Snackbar from '@material-ui/core/Snackbar';
|
||||
import IconButton from '@material-ui/core/IconButton';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
|
||||
const styles = theme => ({
|
||||
close: {
|
||||
padding: theme.spacing(0.5),
|
||||
},
|
||||
});
|
||||
|
||||
class SnackbarNotification extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.raiseNotification=this.raiseNotification.bind(this);
|
||||
}
|
||||
|
||||
static childContextTypes = {
|
||||
raiseNotification: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
getChildContext = () => {
|
||||
return {raiseNotification : this.raiseNotification};
|
||||
};
|
||||
|
||||
state = {
|
||||
open: false,
|
||||
message: null
|
||||
};
|
||||
|
||||
raiseNotification = (message) => {
|
||||
this.setState({ open: true, message:message });
|
||||
};
|
||||
|
||||
handleClose = (event, reason) => {
|
||||
if (reason === 'clickaway') {
|
||||
return;
|
||||
}
|
||||
this.setState({ open: false });
|
||||
};
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
return (
|
||||
<Fragment>
|
||||
<Snackbar
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'left',
|
||||
}}
|
||||
open={this.state.open}
|
||||
autoHideDuration={6000}
|
||||
onClose={this.handleClose}
|
||||
ContentProps={{
|
||||
'aria-describedby': 'message-id',
|
||||
}}
|
||||
message={<span id="message-id">{this.state.message}</span>}
|
||||
action={
|
||||
<IconButton
|
||||
aria-label="Close"
|
||||
color="inherit"
|
||||
className={classes.close}
|
||||
onClick={this.handleClose}
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
{this.props.children}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SnackbarNotification.propTypes = {
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default withStyles(styles)(SnackbarNotification);
|
||||
|
||||
export function withNotifier(WrappedComponent) {
|
||||
return class extends React.Component {
|
||||
static contextTypes = {
|
||||
raiseNotification: PropTypes.func.isRequired
|
||||
};
|
||||
render() {
|
||||
return <WrappedComponent raiseNotification={this.context.raiseNotification} {...this.props} />;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user