Skip to content

Commit b034cf5

Browse files
committed
[v1.2.0]
- API connecting - fetching menu list from database - added axios - started working redux
1 parent 9082404 commit b034cf5

File tree

6 files changed

+103
-32
lines changed

6 files changed

+103
-32
lines changed

package-lock.json

+56-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"dev": "webpack-dev-server --open",
9-
"build": "npx webpack",
9+
"build": "npx webpack --env.mode=production",
1010
"storybook": "start-storybook"
1111
},
1212
"author": "cadenzah",
@@ -34,7 +34,10 @@
3434
"@material-ui/icons": "^4.5.1",
3535
"@storybook/addon-actions": "^5.2.6",
3636
"@storybook/addons": "^5.2.6",
37+
"axios": "^0.19.0",
3738
"clsx": "^1.0.4",
39+
"moment": "^2.24.0",
40+
"moment-timezone": "^0.5.27",
3841
"react": "^16.11.0",
3942
"react-dom": "^16.8.6",
4043
"react-redux": "^7.1.3",

src/components/common/item/MenuItem/MenuItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ const MenuItem = (props) => {
4141
<Typography
4242
variant="h5"
4343
>
44-
{props.item.name}
44+
{props.item.menu_name}
4545
</Typography>
4646
</Grid>
4747
<Grid item>
4848
<Typography
4949
variant="subtitle1"
5050
>
51-
{props.item.price}
51+
{props.item.menu_price}
5252
</Typography>
5353
</Grid>
5454
</Grid>

src/containers/MenuContainer.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import { withRouter } from 'react-router-dom'
3+
34
import { connect } from 'react-redux'
45
import { bindActionCreators } from 'redux'
6+
import * as appActions from '../redux/modules/app'
57

68
import PageWrapper from '../components/base/PageWrapper'
79
import PageListWrapper from '../components/common/templates/PageListWrapper'
810
import PageTitle from '../components/common/typography/PageTitle'
911
import MenuItem from '../components/common/item/MenuItem'
1012

13+
14+
1115
import menu from '../utils/temp/menu'
1216

1317
// # TODOS
@@ -16,17 +20,20 @@ import menu from '../utils/temp/menu'
1620
// - 메뉴 Update / Delete에 활용
1721

1822
const MenuContainer = (props) => {
23+
useEffect(() => {
24+
props.appActions.getMenuList(1)
25+
}, [])
1926
return (
2027
<>
2128
<PageWrapper>
2229
<PageTitle>메뉴 목록</PageTitle>
23-
<PageListWrapper items={menu}>
30+
<PageListWrapper items={props.menuList}>
2431
{
2532
(item) => (
2633
<MenuItem
2734
item={item}
28-
key={item.name}
29-
handleClick={() => props.history.push(`/menu/edit/${item.id}`)}
35+
key={item.menu_name}
36+
handleClick={() => props.history.push(`/menu/edit/${item.menu_id}`)}
3037
/>
3138
)
3239
}
@@ -36,4 +43,15 @@ const MenuContainer = (props) => {
3643
)
3744
}
3845

39-
export default withRouter(MenuContainer)
46+
const mapStateToProps = ({ app }) => ({
47+
menuList: app.menuList
48+
})
49+
50+
const mapDispatchToProps = (dispatch) => ({
51+
appActions: bindActionCreators(appActions, dispatch)
52+
})
53+
54+
export default connect(
55+
mapStateToProps,
56+
mapDispatchToProps
57+
)(withRouter(MenuContainer))

src/redux/modules/app.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
import { createAction, handleActions } from 'redux-actions'
2+
import axios from 'axios'
23

34
// action types
45
const EXAMPLE_INCREASE = 'app/EXAMPLE_INCREASE'
56
const EXAMPLE_DECREASE = 'app/EXAMPLE_DECREASE'
67

8+
const UPDATE_MENU_LIST = 'app/UPDATE_MENU_LIST'
9+
710
// action generator functions
811
// names will be re-used with `bindActionCreators`
9-
export const increment = createAction(EXAMPLE_INCREASE)
10-
export const decrement = createAction(EXAMPLE_DECREASE, value => ({ value }))
12+
export const getMenuList = (store_id) => (dispatch) => {
13+
axios.get(`http://visquit.ga/menu?store_id=${store_id}`)
14+
.then(({ data: { results } }) => {
15+
dispatch(updateMenuList({ menuList: results[0] }))
16+
})
17+
}
18+
const updateMenuList = createAction(UPDATE_MENU_LIST, payload => ({ menuList: payload.menuList }))
1119

1220
// default state for this slice state
1321
const initialState = {
14-
value: 0
22+
menuList: [],
1523
}
1624

1725
// reducer for this slice state
1826
export default handleActions({
19-
[EXAMPLE_INCREASE]: (state, action) => ({
20-
value: state.value + action.payload
21-
}),
22-
[EXAMPLE_DECREASE]: (state, action) => ({
23-
value: state.value - action.payload.value
24-
}),
27+
[UPDATE_MENU_LIST]: (state, action) => ({
28+
...state,
29+
menuList: action.payload.menuList
30+
})
2531
}, initialState)

webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const HTMLWebpackPlugin = require('html-webpack-plugin')
55
const ManifestPlugin = require('webpack-manifest-plugin')
66
const CopyWebpackPlugin = require('copy-webpack-plugin')
77

8-
module.exports = {
8+
module.exports = env => ({
99
entry: ["core-js/stable", "regenerator-runtime/runtime", "./src/index.js"],
1010
output: {
1111
publicPath: '/',
1212
filename: '[name].[chunkhash].js',
1313
path: path.resolve(`${__dirname}/build`)
1414
},
15-
mode: "none",
15+
mode: env ? env.mode : "none",
1616
optimization: {
1717
runtimeChunk: 'single',
1818

@@ -73,4 +73,4 @@ module.exports = {
7373
// KEY: JSON.stringify('<VALUE>'),
7474
// })
7575
]
76-
}
76+
})

0 commit comments

Comments
 (0)