Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Authenticate NotFound page #3243

Merged
merged 1 commit into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ra-core/src/RoutesWithLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ const RoutesWithLayout: SFC<Props> = ({
/>
) : null}
<Route
render={() =>
render={routeProps =>
createElement(catchAll, {
...routeProps,
title,
})
}
Expand Down
45 changes: 24 additions & 21 deletions packages/ra-ui-materialui/src/layout/NotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import HotTub from '@material-ui/icons/HotTub';
import History from '@material-ui/icons/History';
import classnames from 'classnames';

import { useTranslate } from 'ra-core';
import { useTranslate, Authenticated } from 'ra-core';
import Title from './Title';

const styles = theme =>
Expand All @@ -16,56 +16,59 @@ const styles = theme =>
flexDirection: 'column',
justifyContent: 'center',
[theme.breakpoints.up('md')]: {
height: '100%',
height: '100%'
},
[theme.breakpoints.down('sm')]: {
height: '100vh',
marginTop: '-3em',
},
marginTop: '-3em'
}
},
icon: {
width: '9em',
height: '9em',
height: '9em'
},
message: {
textAlign: 'center',
fontFamily: 'Roboto, sans-serif',
opacity: 0.5,
margin: '0 1em',
margin: '0 1em'
},
toolbar: {
textAlign: 'center',
marginTop: '2em',
},
marginTop: '2em'
}
});

function goBack() {
history.go(-1);
}

const NotFound = ({ classes, className, title, ...rest }) => {
const NotFound = ({ classes, className, title, location, ...rest }) => {
const translate = useTranslate();
return (
<div className={classnames(classes.container, className)} {...rest}>
<Title defaultTitle={title} />
<div className={classes.message}>
<HotTub className={classes.icon} />
<h1>{translate('ra.page.not_found')}</h1>
<div>{translate('ra.message.not_found')}.</div>
</div>
<div className={classes.toolbar}>
<Button variant="contained" icon={<History />} onClick={goBack}>
{translate('ra.action.back')}
</Button>
<Authenticated location={location}>
<div className={classnames(classes.container, className)} {...rest}>
<Title defaultTitle={title} />
<div className={classes.message}>
<HotTub className={classes.icon} />
<h1>{translate('ra.page.not_found')}</h1>
<div>{translate('ra.message.not_found')}.</div>
</div>
<div className={classes.toolbar}>
<Button variant="contained" icon={<History />} onClick={goBack}>
{translate('ra.action.back')}
</Button>
</div>
</div>
</div>
</Authenticated>
);
};

NotFound.propTypes = {
classes: PropTypes.object,
className: PropTypes.string,
title: PropTypes.string,
location: PropTypes.object
};

export default withStyles(styles)(NotFound);