This repository was archived by the owner on Jan 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Not Found Component #170
Merged
Merged
Not Found Component #170
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3b6d104
refactor: updated not found component
priscilawebdev 391768b
chore: removed react-router
priscilawebdev bc3495d
Merge branch 'master' into refactor/update_not_found_component
juanpicado 7f50980
Merge branch 'master' into refactor/update_not_found_component
priscilawebdev 6571eee
refactored: applied feedbacks
priscilawebdev cbaeca3
fix: removed doc folder
priscilawebdev 88e28e5
refactor: rollback yarn.lock
priscilawebdev 67ff4cb
Merge branch 'master' into refactor/update_not_found_component
juanpicado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ Dockerfile | |
| *.html | ||
| *.scss | ||
| *.png | ||
| doc | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ npm-debug.log | |
| verdaccio-*.tgz | ||
| .DS_Store | ||
| build/ | ||
| doc | ||
|
|
||
| ### | ||
| node_modules | ||
| package-lock.json | ||
|
|
||
This file contains hidden or 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,53 +1,47 @@ | ||
| import ListItem from '@material-ui/core/ListItem'; | ||
| import Box from '@material-ui/core/Box'; | ||
| import Typography from '@material-ui/core/Typography'; | ||
| import withWidth, { isWidthUp, WithWidthProps } from '@material-ui/core/withWidth'; | ||
| import styled from 'react-emotion'; | ||
| import React, { useCallback } from 'react'; | ||
| import { RouteComponentProps, withRouter } from 'react-router-dom'; | ||
| import { useHistory } from 'react-router-dom'; | ||
|
|
||
| import Button from '../../muiComponents/Button'; | ||
| import colors from '../../utils/styles/colors'; | ||
| import { spacings } from '../../utils/styles/spacings'; | ||
|
|
||
| import PackageImg from './img/package.svg'; | ||
| import { Card, EmptyPackage, Heading, Inner, List, Wrapper } from './styles'; | ||
|
|
||
| export const NOT_FOUND_TEXT = `Sorry, we couldn't find it...`; | ||
| export const LABEL_NOT_FOUND = `The page you're looking for doesn't exist.`; | ||
| export const LABEL_FOOTER_NOT_FOUND = 'Perhaps these links will help find what you are looking for:'; | ||
| export const NOT_FOUND_TEXT = "Sorry, we couldn't find it..."; | ||
| export const LABEL_NOT_FOUND = "The page you're looking for doesn't exist."; | ||
| export const GO_TO_HOME_PAGE = 'Go to the home page'; | ||
|
|
||
| export type NotFoundProps = RouteComponentProps & WithWidthProps; | ||
| const EmptyPackage = styled('img')({ | ||
| width: '150px', | ||
| margin: '0 auto', | ||
| }); | ||
|
|
||
| const HOME_LABEL = 'Home'; | ||
| const StyledHeading = styled(Typography)({ | ||
| color: colors.primary, | ||
| marginBottom: spacings.sm, | ||
| }); | ||
|
|
||
| const renderSubTitle = (): JSX.Element => ( | ||
| <Typography variant="subtitle1"> | ||
| <div>{LABEL_NOT_FOUND}</div> | ||
| <div>{LABEL_FOOTER_NOT_FOUND}</div> | ||
| </Typography> | ||
| ); | ||
| const NotFound: React.FC = () => { | ||
| const history = useHistory(); | ||
|
|
||
| const NotFound: React.FC<NotFoundProps> = ({ history, width }) => { | ||
| const handleGomHome = useCallback(() => { | ||
| history.push('/'); | ||
| }, [history]); | ||
|
|
||
| const renderList = (): JSX.Element => ( | ||
| <List> | ||
| <ListItem button={true} divider={true} onClick={handleGomHome}> | ||
| {HOME_LABEL} | ||
| </ListItem> | ||
| </List> | ||
| ); | ||
|
|
||
| /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
| return ( | ||
| <Wrapper data-testid="404"> | ||
| <Inner> | ||
| <EmptyPackage alt="404 - Page not found" src={PackageImg} /> | ||
| <Heading className="not-found-text" variant={isWidthUp('sm', width!) ? 'h2' : 'h4'}> | ||
| {NOT_FOUND_TEXT} | ||
| </Heading> | ||
| {renderSubTitle()} | ||
| <Card>{renderList()}</Card> | ||
| </Inner> | ||
| </Wrapper> | ||
| <Box alignItems="center" data-testid="404" display="flex" flexDirection="column" flexGrow={1} justifyContent="center" p={2}> | ||
| <EmptyPackage alt="404 - Page not found" src={PackageImg} /> | ||
| <StyledHeading className="not-found-text" variant="h4"> | ||
| {NOT_FOUND_TEXT} | ||
| </StyledHeading> | ||
| <Button onClick={handleGomHome} variant="contained"> | ||
| {GO_TO_HOME_PAGE} | ||
| </Button> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default withRouter<NotFoundProps, React.ComponentType<NotFoundProps>>(withWidth()(NotFound)); | ||
| export default NotFound; |
This file contains hidden or 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,18 +1,17 @@ | ||
| import React from 'react'; | ||
| import { BrowserRouter as Router } from 'react-router-dom'; | ||
| import { shallow } from 'enzyme'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import NotFound from './NotFound'; | ||
|
|
||
| console.error = jest.fn(); | ||
|
|
||
| describe('<NotFound /> component', () => { | ||
| test('should load the component in default state', () => { | ||
| const routerWrapper = shallow( | ||
| const { container } = render( | ||
| <Router> | ||
| <NotFound /> | ||
| </Router> | ||
| ); | ||
| expect(routerWrapper.find(NotFound)).toMatchSnapshot(); | ||
| expect(container.firstChild).toMatchSnapshot(); | ||
| }); | ||
| test.todo('Test Button Click'); | ||
| }); | ||
32 changes: 31 additions & 1 deletion
32
src/components/NotFound/__snapshots__/Notfound.test.tsx.snap
This file contains hidden or 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,3 +1,33 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`<NotFound /> component should load the component in default state 1`] = `<withRouter(WithWidth(NotFound)) />`; | ||
| exports[`<NotFound /> component should load the component in default state 1`] = ` | ||
| <div | ||
| class="MuiBox-root MuiBox-root-2" | ||
| data-testid="404" | ||
| > | ||
| <img | ||
| alt="404 - Page not found" | ||
| class="css-17y48z2 emotion-0" | ||
| src="[object Object]" | ||
| /> | ||
| <h4 | ||
| class="MuiTypography-root not-found-text css-7pe7kh emotion-1 MuiTypography-h4" | ||
| > | ||
| Sorry, we couldn't find it... | ||
| </h4> | ||
| <button | ||
| class="MuiButtonBase-root MuiButton-root MuiButton-contained" | ||
| tabindex="0" | ||
| type="button" | ||
| > | ||
| <span | ||
| class="MuiButton-label" | ||
| > | ||
| Go to the home page | ||
| </span> | ||
| <span | ||
| class="MuiTouchRipple-root" | ||
| /> | ||
| </button> | ||
| </div> | ||
| `; |
This file contains hidden or 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 +1 @@ | ||
| export { default } from './NotFound'; | ||
| export { default, NOT_FOUND_TEXT } from './NotFound'; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ | |
|
|
||
| export const spacings = { | ||
| lg: '30px', | ||
| sm: '16px', | ||
| }; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.