Skip to content

Commit

Permalink
feat: make banner for warnings, info and errors
Browse files Browse the repository at this point in the history
closes #98
  • Loading branch information
juancarlosfarah committed Jun 14, 2019
1 parent 3778518 commit e04951a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
7 changes: 0 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { connect } from 'react-redux';
import ReduxToastr from 'react-redux-toastr';
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
import red from '@material-ui/core/colors/red';
import { withTranslation } from 'react-i18next';
import Home from './Home';
import VisitSpace from './components/VisitSpace';
Expand Down Expand Up @@ -39,12 +38,6 @@ const theme = createMuiTheme({
primary: { light: '#5050d2', main: '#5050d2', dark: '#5050d2' },
secondary: { light: '#00b904', main: '#00b904', dark: '#00b904' },
},
status: {
danger: {
background: red,
color: '#fff',
},
},
});

export class App extends Component {
Expand Down
5 changes: 0 additions & 5 deletions src/Styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ const Styles = theme => ({
screenTitle: {
marginBottom: theme.spacing(2),
},
alert: {
backgroundColor: theme.status.danger.background[500],
color: theme.status.danger.color,
textAlign: 'center',
},
spaceDescription: {
marginBottom: theme.spacing(3),
},
Expand Down
32 changes: 22 additions & 10 deletions src/components/common/Banner.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import Avatar from '@material-ui/core/Avatar';
import Divider from '@material-ui/core/Divider';
import CssBaseline from '@material-ui/core/CssBaseline';
import WarningIcon from '@material-ui/icons/Warning';
import ErrorIcon from '@material-ui/icons/Error';
import InfoIcon from '@material-ui/icons/Info';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import Box from '@material-ui/core/Box';
Expand All @@ -15,6 +16,9 @@ const styles = theme => ({
banner: {
marginBottom: theme.spacing(2),
},
paper: {
padding: theme.spacing(2),
},
});

const renderButton = buttonText => (
Expand All @@ -25,20 +29,26 @@ const renderButton = buttonText => (
</Grid>
);

const Banner = ({ text, buttonText, classes }) => {
const renderIcon = type => {
switch (type) {
case 'warning':
return <WarningIcon color="error" fontSize="large" />;
case 'error':
return <ErrorIcon color="error" fontSize="large" />;
case 'info':
default:
return <InfoIcon color="primary" fontSize="large" />;
}
};

const Banner = ({ text, buttonText, classes, type }) => {
return (
<div className={classes.banner}>
<CssBaseline />
<Paper elevation={0}>
<Paper elevation={0} className={classes.paper}>
<Box pt={2} pr={1} pb={1} pl={2}>
<Grid container spacing={6} alignItems="center" wrap="nowrap">
<Grid item>
<Box bgcolor="primary.main" clone>
<Avatar>
<WarningIcon />
</Avatar>
</Box>
</Grid>
<Grid item>{renderIcon(type)}</Grid>
<Grid item>
<Typography>{text}</Typography>
</Grid>
Expand All @@ -52,12 +62,14 @@ const Banner = ({ text, buttonText, classes }) => {
};

Banner.propTypes = {
type: PropTypes.oneOf(['warning', 'error', 'info']),
text: PropTypes.string,
buttonText: PropTypes.string,
classes: PropTypes.shape({ banner: PropTypes.string.isRequired }).isRequired,
};

Banner.defaultProps = {
type: 'info',
text: null,
buttonText: null,
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/DeveloperSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Loader from './Loader';

const styles = theme => ({
formControl: {
margin: theme.spacing.unit,
margin: theme.spacing(),
minWidth: 120,
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/LanguageSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Loader from './Loader';

const styles = theme => ({
formControl: {
margin: theme.spacing.unit,
margin: theme.spacing(),
minWidth: 120,
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/MediaCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const styles = theme => ({
height: 300,
},
leftIcon: {
marginRight: theme.spacing.unit,
marginRight: theme.spacing(),
},
});

Expand Down
9 changes: 5 additions & 4 deletions src/components/developer/DeveloperScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PropTypes from 'prop-types';
import MainMenu from '../common/MainMenu';
import DatabaseEditor from './DatabaseEditor';
import Styles from '../../Styles';
import Banner from '../common/Banner';

class DeveloperScreen extends Component {
state = {
Expand Down Expand Up @@ -98,12 +99,12 @@ class DeveloperScreen extends Component {
{t('Developer')}
</Typography>
<br />
<Typography variant="h6" className={classes.alert}>
{t(
<Banner
text={t(
'Danger Zone! Proceed with caution as changes to this section might lead to data loss.'
)}
</Typography>
<br />
type="error"
/>
<DatabaseEditor />
</main>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/space/SpaceDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Banner from '../common/Banner';
const renderPreviewWarning = t => {
return (
<Banner
type="warning"
text={t(
'Warning: You are previewing this space. Any input or changes will not be saved.'
)}
Expand Down

0 comments on commit e04951a

Please sign in to comment.