Skip to content

Commit 8602e49

Browse files
committed
Rewire react
1 parent 0eee0cd commit 8602e49

File tree

6 files changed

+65
-18
lines changed

6 files changed

+65
-18
lines changed

config-overrides.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
// The Webpack config to use when compiling your react app for development or production.
5+
webpack: function(config, env) {
6+
// ...add your webpack config
7+
config.resolve.alias = {
8+
...config.resolve.alias,
9+
'@': path.resolve('./src'),
10+
}
11+
12+
return config
13+
},
14+
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"start": "react-scripts start",
7-
"build": "react-scripts build",
8-
"test": "react-scripts test",
6+
"start": "react-app-rewired start",
7+
"build": "react-app-rewired build",
8+
"test": "react-app-rewired test",
99
"eject": "react-scripts eject",
1010
"deploy": "npm run build-preview && npm run build-docs && gh-pages -d build --repo [email protected]:modularcode/modular-material-admin-react.git --branch gh-pages",
1111
"build-preview": "cross-env PUBLIC_PATH='/' npm run build && echo modular-material-admin-react.modularcode.io > ./build/CNAME",
@@ -57,6 +57,7 @@
5757
"fork-ts-checker-webpack-plugin": "^3.1.1",
5858
"gh-pages": "^2.2.0",
5959
"prettier": "1.18.2",
60+
"react-app-rewired": "^2.1.5",
6061
"react-docgen-typescript-loader": "^3.6.0",
6162
"ts-loader": "^6.2.1"
6263
},

src/Administration/Users/UsersList/UsersList.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TableFooter,
1414
} from '@material-ui/core'
1515

16-
import api from '../../../_api'
16+
import api from '@/_api'
1717

1818
import BasePageContainer from '../../../_common/BasePageContainer'
1919
import BasePageToolbar from '../../../_common/BasePageToolbar'
@@ -23,21 +23,32 @@ import UsersListTableBody from './UsersListTableBody'
2323

2424
const UsersList = ({ match }) => {
2525
const classes = useStyles()
26-
const [usersData, setUsersData] = useState({ users: [], count: 0 })
27-
useEffect(() => {
28-
api.users.getList().then(res => setUsersData(res))
29-
}, [])
3026

3127
const [page, setPage] = React.useState(0)
28+
const [usersData, setUsersData] = useState({ users: [], count: 0 })
3229
const [rowsPerPage, setRowsPerPage] = React.useState(10)
30+
31+
useEffect(() => {
32+
async function fetchUsers() {
33+
const userDataRes = await api.users.getList({
34+
limit: rowsPerPage,
35+
offset: page * rowsPerPage,
36+
})
37+
38+
setUsersData(userDataRes)
39+
}
40+
41+
fetchUsers()
42+
}, [page, rowsPerPage])
43+
3344
const handleChangePage = (event, newPage) => {
3445
setPage(newPage)
3546
}
3647

37-
// const handleChangeRowsPerPage = event => {
38-
// setRowsPerPage(parseInt(event.target.value, 10))
39-
// setPage(0)
40-
// }
48+
const handleChangeRowsPerPage = event => {
49+
setRowsPerPage(parseInt(event.target.value, 10))
50+
setPage(0)
51+
}
4152

4253
const { users, count } = usersData
4354

@@ -66,6 +77,7 @@ const UsersList = ({ match }) => {
6677
rowsPerPage={rowsPerPage}
6778
count={count}
6879
onChangePage={handleChangePage}
80+
onChangeRowsPerPage={handleChangeRowsPerPage}
6981
/>
7082
</TableRow>
7183
</TableFooter>

src/_common/BaseTable/BaseTablePagination.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import { TablePagination, IconButton } from '@material-ui/core'
4-
import { useTheme } from '@material-ui/core/styles'
4+
import { useTheme, makeStyles } from '@material-ui/core/styles'
55

66
import {
77
FirstPage as FirstPageIcon,
@@ -11,6 +11,7 @@ import {
1111
} from '@material-ui/icons/'
1212

1313
const BaseTablePaginationActions = props => {
14+
const classes = useStyles()
1415
const theme = useTheme()
1516
const { count, page, itemsPerPage, onChangePage } = props
1617

@@ -31,7 +32,7 @@ const BaseTablePaginationActions = props => {
3132
}
3233

3334
return (
34-
<div>
35+
<div className={classes.root}>
3536
<IconButton
3637
onClick={handleFirstPageButtonClick}
3738
disabled={page === 0}
@@ -65,7 +66,7 @@ const BaseTablePaginationActions = props => {
6566
}
6667

6768
const BaseTablePagination = props => {
68-
const { count, page, rowsPerPage, onChangePage } = props
69+
const { count, page, rowsPerPage, onChangePage, onChangeRowsPerPage = () => {} } = props
6970

7071
return (
7172
<TablePagination
@@ -79,16 +80,25 @@ const BaseTablePagination = props => {
7980
native: true,
8081
}}
8182
onChangePage={onChangePage}
83+
onChangeRowsPerPage={onChangeRowsPerPage}
8284
ActionsComponent={BaseTablePaginationActions}
8385
/>
8486
)
8587
}
8688

89+
const useStyles = makeStyles(theme => ({
90+
root: {
91+
flexShrink: 0,
92+
marginLeft: theme.spacing(2.5),
93+
},
94+
}))
95+
8796
BaseTablePagination.propTypes = {
8897
count: PropTypes.number.isRequired,
89-
onChangePage: PropTypes.func.isRequired,
9098
page: PropTypes.number.isRequired,
9199
rowsPerPage: PropTypes.number.isRequired,
100+
onChangePage: PropTypes.func.isRequired,
101+
onChangeRowsPerPage: PropTypes.func,
92102
}
93103

94104
export default BaseTablePagination

tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
"isolatedModules": true,
2020
"noEmit": true,
2121
"jsx": "preserve",
22-
"typeRoots" : ["./node_modules/@types/", "./src/_types", "./src/_api/_types"]
22+
"typeRoots": [
23+
"./node_modules/@types/",
24+
"./src/_types",
25+
"./src/_api/_types"
26+
]
2327
},
2428
"include": [
2529
"src"
@@ -28,4 +32,3 @@
2832
"node_modules/@nivo/line/index.d.ts"
2933
]
3034
}
31-

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11696,6 +11696,13 @@ react-app-polyfill@^1.0.4:
1169611696
regenerator-runtime "^0.13.3"
1169711697
whatwg-fetch "^3.0.0"
1169811698

11699+
react-app-rewired@^2.1.5:
11700+
version "2.1.5"
11701+
resolved "https://registry.yarnpkg.com/react-app-rewired/-/react-app-rewired-2.1.5.tgz#592ec2eae5c3c5cd96c80930b5dc3f6c34da1dc6"
11702+
integrity sha512-Gr8KfCeL9/PTQs8Vvxc7v8wQ9vCFMnYPhcAkrMlzkLiMFXS+BgSwm11MoERjZm7dpA2WjTi+Pvbu/w7rujAV+A==
11703+
dependencies:
11704+
semver "^5.6.0"
11705+
1169911706
react-chartjs-2@^2.9.0:
1170011707
version "2.9.0"
1170111708
resolved "https://registry.yarnpkg.com/react-chartjs-2/-/react-chartjs-2-2.9.0.tgz#d054dbdd763fbe9a76296a4ae0752ea549b76d9e"

0 commit comments

Comments
 (0)