-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provide better error handling for invalid space ids
closes #81
- Loading branch information
1 parent
f016419
commit 81a952c
Showing
8 changed files
with
155 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,124 @@ | ||
import React from 'react'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withRouter } from 'react-router'; | ||
import Button from '@material-ui/core//Button'; | ||
import { HOME_PATH } from '../../config/paths'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import classNames from 'classnames'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import MenuIcon from '@material-ui/icons/Menu'; | ||
import Drawer from '@material-ui/core/Drawer'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import { withStyles } from '@material-ui/core'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import MainMenu from '../common/MainMenu'; | ||
import Styles from '../../Styles'; | ||
import { HOME_PATH, VISIT_PATH } from '../../config/paths'; | ||
|
||
const SpaceNotFound = ({ history: { replace } }) => { | ||
return ( | ||
<div> | ||
Space not found. | ||
<Button onClick={() => replace(HOME_PATH)}>Home</Button> | ||
</div> | ||
); | ||
}; | ||
class SpaceNotFound extends Component { | ||
state = { | ||
open: false, | ||
}; | ||
|
||
SpaceNotFound.propTypes = { | ||
history: PropTypes.shape({ length: PropTypes.number.isRequired }).isRequired, | ||
}; | ||
static propTypes = { | ||
classes: PropTypes.shape({}).isRequired, | ||
theme: PropTypes.shape({}).isRequired, | ||
history: PropTypes.shape({ length: PropTypes.number.isRequired }) | ||
.isRequired, | ||
}; | ||
|
||
export default withRouter(SpaceNotFound); | ||
handleDrawerOpen = () => { | ||
this.setState({ open: true }); | ||
}; | ||
|
||
handleDrawerClose = () => { | ||
this.setState({ open: false }); | ||
}; | ||
|
||
render() { | ||
const { open } = this.state; | ||
const { | ||
history: { replace }, | ||
classes, | ||
theme, | ||
} = this.props; | ||
return ( | ||
<div className={classes.root}> | ||
<CssBaseline /> | ||
<AppBar | ||
position="fixed" | ||
className={classNames(classes.appBar, { | ||
[classes.appBarShift]: open, | ||
})} | ||
> | ||
<Toolbar disableGutters={!open}> | ||
<IconButton | ||
color="inherit" | ||
aria-label="Open drawer" | ||
onClick={this.handleDrawerOpen} | ||
className={classNames(classes.menuButton, open && classes.hide)} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
</Toolbar> | ||
</AppBar> | ||
<Drawer | ||
className={classes.drawer} | ||
variant="persistent" | ||
anchor="left" | ||
open={open} | ||
classes={{ | ||
paper: classes.drawerPaper, | ||
}} | ||
> | ||
<div className={classes.drawerHeader}> | ||
<IconButton onClick={this.handleDrawerClose}> | ||
{theme.direction === 'ltr' ? ( | ||
<ChevronLeftIcon /> | ||
) : ( | ||
<ChevronRightIcon /> | ||
)} | ||
</IconButton> | ||
</div> | ||
<Divider /> | ||
<MainMenu /> | ||
</Drawer> | ||
<main | ||
className={classNames(classes.content, { | ||
[classes.contentShift]: open, | ||
})} | ||
> | ||
<div className={classes.drawerHeader} /> | ||
<div> | ||
<Typography variant="h5" color="inherit" style={{ margin: '2rem' }}> | ||
Space Not Found | ||
</Typography> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
className={classes.button} | ||
onClick={() => replace(HOME_PATH)} | ||
> | ||
Home | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
className={classes.button} | ||
onClick={() => replace(VISIT_PATH)} | ||
> | ||
Visit Another Space | ||
</Button> | ||
</div> | ||
</main> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const StyledComponent = withStyles(Styles, { withTheme: true })(SpaceNotFound); | ||
|
||
export default withRouter(StyledComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ObjectId from 'bson-objectid'; | ||
import { SHORT_ID_LENGTH } from '../config/constants'; | ||
|
||
const isValidSpaceShortId = id => { | ||
return id.length === SHORT_ID_LENGTH && /^[a-z0-9]+$/i.test(id); | ||
}; | ||
|
||
const isValidLongSpaceId = id => ObjectId.isValid(id); | ||
|
||
const isValidSpaceId = id => isValidLongSpaceId(id) || isValidSpaceShortId(id); | ||
|
||
export { isValidSpaceId, isValidLongSpaceId, isValidSpaceShortId }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters