Skip to content

Commit b3ff2e4

Browse files
author
Juliano Reis
authored
Merge pull request #56 from naveteam/feature/CRUD-SAMPLE
Feature/crud sample
2 parents af10902 + 7cfd856 commit b3ff2e4

56 files changed

Lines changed: 1500 additions & 153 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
"quotes": [2, "single"],
77
"semi": [2, "never"],
88
"comma-dangle": [2, "never"],
9+
"no-console": "warn",
10+
"no-debugger": "warn",
911
"no-trailing-spaces": [2],
1012
"jsx-quotes": ["error", "prefer-single"],
1113
"react/jsx-boolean-value": [0],
1214
"react-hooks/rules-of-hooks": "error",
15+
"react-hooks/exhaustive-deps": "warn",
1316
"prettier/prettier": [
1417
"error",
1518
{

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,30 @@
77
"private": true,
88
"dependencies": {
99
"@apollo/client": "^3.3.7",
10+
"@hookform/resolvers": "^1.3.4",
1011
"@naveteam/dispatcher": "^1.1.0",
11-
"@naveteam/pandora-frontend": "^1.0.2",
12+
"@naveteam/pandora-frontend": "^1.0.4",
1213
"@sentry/browser": "5.14",
1314
"@styled-system/prop-types": "^5.1.5",
1415
"@welldone-software/why-did-you-render": "^6.0.0-rc.1",
1516
"apollo-cache-inmemory": "^1.6.6",
1617
"axios": "^0.19.0",
18+
"date-fns": "^2.18.0",
1719
"graphql": "^15.5.0",
1820
"graphql-anywhere": "^4.2.7",
1921
"graphql-tag": "^2.11.0",
20-
"react": "^16.9.0",
22+
"react": "^17.0.1",
2123
"react-apollo": "^3.1.5",
2224
"react-app-polyfill": "^1.0.6",
23-
"react-dom": "^16.9.0",
25+
"react-datepicker": "^3.6.0",
26+
"react-dom": "^17.0.1",
2427
"react-helmet": "^5.2.1",
25-
"react-hook-form": "^5.5.3",
28+
"react-hook-form": "^6.15.1",
2629
"react-is": "^16.13.1",
27-
"react-query": "^2.26.2",
28-
"react-query-devtools": "^2.6.3",
30+
"react-query": "^3.9.8",
2931
"react-router-dom": "^5.0.1",
3032
"react-scripts": "^3.3.0",
33+
"react-text-mask": "^5.4.3",
3134
"sanitize.css": "^11.0.0",
3235
"styled-components": "^5.0.1",
3336
"styled-system": "^5.1.5",

public/menu.png

3.37 KB
Loading

src/App.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { useEffect, Suspense, lazy } from 'react'
1+
import React, { Suspense, lazy } from 'react'
22
import { BrowserRouter as Router } from 'react-router-dom'
3-
import { ReactQueryDevtools } from 'react-query-devtools'
3+
import { ReactQueryDevtools } from 'react-query/devtools'
4+
45
import { createGlobalStyle } from 'styled-components'
56
import { ApolloProvider } from '@apollo/client'
67
import Helmet from 'react-helmet'
@@ -14,8 +15,7 @@ import Theme from 'theme'
1415

1516
import 'sanitize.css/sanitize.css'
1617

17-
const loadAuthenticatedApp = () => import('./AuthenticatedApp')
18-
const AuthenticatedApp = lazy(loadAuthenticatedApp)
18+
const AuthenticatedApp = lazy(() => import('./AuthenticatedApp'))
1919
const UnauthenticatedApp = lazy(() => import('./UnauthenticatedApp'))
2020

2121
const GlobalStyle = createGlobalStyle`
@@ -38,20 +38,19 @@ button, a {
3838
const App = () => {
3939
const { user, isLoading } = useUser()
4040

41-
useEffect(() => {
42-
loadAuthenticatedApp()
43-
}, [])
41+
if (isLoading) {
42+
return <Loader />
43+
}
4444

4545
return (
4646
<ApolloProvider client={apolloClient}>
4747
<Theme>
4848
<Helmet titleTemplate='Nave.rs | %s' />
4949
<GlobalStyle />
5050
<Suspense fallback={<Loader />}>
51-
{isLoading && <Loader />}
5251
<Router>{user ? <AuthenticatedApp /> : <UnauthenticatedApp />}</Router>
5352
</Suspense>
54-
<ReactQueryDevtools initialIsOpen={false} />
53+
<ReactQueryDevtools />
5554
</Theme>
5655
</ApolloProvider>
5756
)

src/AuthenticatedApp.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import { Route, Redirect, Switch } from 'react-router-dom'
33

44
import Home from 'routes/Home'
55
import Dashboard from 'routes/Dashboard'
6+
import UsersList from 'routes/UsersList'
7+
import UserForm from 'routes/UserForm'
8+
9+
import Drawer from 'components/Drawer'
610

711
const AuthenticatedApp = () => (
8-
<Switch>
9-
<Route path='/home' component={Home} />
10-
<Route path='/dashboard' component={Dashboard} />
11-
<Redirect to='/home' />
12-
</Switch>
12+
<Drawer>
13+
<Switch>
14+
<Route path='/home' component={Home} />
15+
<Route path='/dashboard' component={Dashboard} />
16+
<Route exact path='/usuarios' component={UsersList} />
17+
<Route exact path={['/usuarios/criar', '/usuarios/:id']} component={UserForm} />
18+
<Redirect to='/home' />
19+
</Switch>
20+
</Drawer>
1321
)
1422

1523
export default AuthenticatedApp

src/components/Button/Button.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import propTypes from '@styled-system/prop-types'
66

77
import Loader from 'components/Loader'
88

9-
const ButtonComponent = ({ children, isLoading, ...props }) => (
10-
<Button {...props}>{isLoading ? <Loader /> : children}</Button>
9+
const ButtonComponent = ({ children, disabled, isLoading, ...props }) => (
10+
<Button {...props} disabled={disabled || isLoading}>
11+
{isLoading ? <Loader /> : children}
12+
</Button>
1113
)
1214

1315
const Button = styled.button(space, layout, typography, color, border)
@@ -16,7 +18,8 @@ ButtonComponent.defaultProps = {
1618
width: 'regular',
1719
height: 'small',
1820
borderRadius: 4,
19-
color: 'white'
21+
color: 'white',
22+
backgroundColor: 'primary.main'
2023
}
2124

2225
ButtonComponent.propTypes = {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { forwardRef } from 'react'
2+
import PropTypes from 'prop-types'
3+
import styled from 'styled-components'
4+
import Datepicker from 'react-datepicker'
5+
6+
import Column from 'components/Column'
7+
import Text from 'components/Text'
8+
9+
const DatepickerComponent = forwardRef(
10+
({ label, error, containerProps, dateFormat = 'dd/MM/yyyy', value, ...props }, ref) => {
11+
return (
12+
<Column {...containerProps}>
13+
{label && <Text mb={5}>{label}</Text>}
14+
<Column height={60} position='relative'>
15+
<StyledDatepicker ref={ref} dateFormat={dateFormat} selected={value} {...props} />
16+
<Text position='absolute' bottom={0} color='red' variant='small'>
17+
{error}
18+
</Text>
19+
</Column>
20+
</Column>
21+
)
22+
}
23+
)
24+
25+
const StyledDatepicker = styled(Datepicker)`
26+
height: 40px;
27+
border: 1px solid black;
28+
border-radius: 4px;
29+
padding: 4px 8px;
30+
width: 100%;
31+
`
32+
33+
DatepickerComponent.propTypes = {
34+
label: PropTypes.string,
35+
error: PropTypes.string,
36+
containerProps: PropTypes.object,
37+
dateFormat: PropTypes.string
38+
}
39+
40+
export default DatepickerComponent

src/components/Datepicker/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Datepicker'

src/components/Drawer/Drawer.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React, { useState } from 'react'
2+
import styled, { css } from 'styled-components'
3+
import { Link as RouterLink } from 'react-router-dom'
4+
5+
const NAV_BAR_HEIGHT = 60
6+
const SIDE_BAR_WIDTH = 200
7+
const ROUTES = [
8+
{
9+
path: '/usuarios',
10+
label: 'Usuários'
11+
},
12+
{
13+
path: '/usuarios/criar',
14+
label: 'Criar usuário'
15+
}
16+
]
17+
18+
const DrawerComponent = ({ children }) => {
19+
const [isOpen, setIsOpen] = useState(true)
20+
21+
return (
22+
<Container>
23+
<NavBar>
24+
<BurgerMenu src='/menu.png' onClick={() => setIsOpen(!isOpen)} />
25+
</NavBar>
26+
<SideBar isOpen={isOpen}>
27+
{ROUTES.map(route => (
28+
<Link key={route.path} to={route.path}>
29+
{route.label}
30+
</Link>
31+
))}
32+
</SideBar>
33+
<Content isOpen={isOpen}>{children}</Content>
34+
</Container>
35+
)
36+
}
37+
38+
const Container = styled.div`
39+
width: 100vw;
40+
height: 100vh;
41+
`
42+
43+
const Content = styled.div`
44+
padding: 20px;
45+
padding-top: ${NAV_BAR_HEIGHT + 20}px;
46+
padding-left: ${({ isOpen }) => (isOpen ? SIDE_BAR_WIDTH + 20 : 20)}px;
47+
height: 100vh;
48+
width: 100vw;
49+
overflow: auto;
50+
background-color: #fafafa;
51+
transition: all 0.3s ease-in-out;
52+
`
53+
54+
const Link = styled(RouterLink)`
55+
color: black;
56+
text-decoration: none;
57+
`
58+
59+
const NavBar = styled.div`
60+
position: absolute;
61+
display: flex;
62+
align-items: center;
63+
height: ${NAV_BAR_HEIGHT}px;
64+
width: 100%;
65+
z-index: 2;
66+
padding: 0 20px;
67+
background-color: ${({ theme }) => theme.colors.primary.main};
68+
`
69+
70+
const BurgerMenu = styled.img`
71+
cursor: pointer;
72+
width: 20px;
73+
height: 20px;
74+
`
75+
76+
const SideBar = styled.div`
77+
${({ isOpen, theme }) => css`
78+
position: absolute;
79+
height: 100%;
80+
background-color: white;
81+
border-right: 1px solid lightgray;
82+
overflow: hidden;
83+
white-space: nowrap;
84+
transition: all 0.3s ease-in-out;
85+
display: flex;
86+
flex-direction: column;
87+
${isOpen
88+
? css`
89+
width: ${SIDE_BAR_WIDTH}px;
90+
padding: 20px;
91+
padding-top: ${NAV_BAR_HEIGHT + 20}px;
92+
`
93+
: css`
94+
width: 0px;
95+
`};
96+
`}
97+
`
98+
99+
export default DrawerComponent

src/components/Drawer/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Drawer'

0 commit comments

Comments
 (0)