Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-frontend
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
coding-brunch-hh
inventory-frontend
Commits
036dc8a5
Commit
036dc8a5
authored
Aug 07, 2018
by
Martin Fahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
connects add to backend and adds codecentric favicon
parent
f4fa1d80
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
16 deletions
+71
-16
public/favicon.png
public/favicon.png
+0
-0
src/actions/index.js
src/actions/index.js
+30
-4
src/components/AddDialog/AddDialog.js
src/components/AddDialog/AddDialog.js
+6
-2
src/container/AddDialogContainer/AddDialogContainer.js
src/container/AddDialogContainer/AddDialogContainer.js
+25
-4
src/reducers/addDialog.js
src/reducers/addDialog.js
+8
-4
src/reducers/items.js
src/reducers/items.js
+2
-2
No files found.
public/favicon.png
0 → 100644
View file @
036dc8a5
3.36 KB
src/actions/index.js
View file @
036dc8a5
// actions
export
const
ADD
=
'
ADD_ITEM
'
;
export
const
ITEM_ADDED
=
'
ITEM_ADDED
'
;
export
const
UPDATE_FILTER
=
'
UPDATE_FILTER
'
;
export
const
DELETE_ITEM
=
'
DELETE_ITEM
'
;
export
const
INCREMENT
=
'
INREMENT_ITEM
'
;
export
const
DECREMENT
=
'
DECREMENT_ITEM
'
;
export
const
ITEMS_LOADED
=
'
ITEMS_LOADED
'
;
export
const
UPDATE_ADD_DIALOG_NAME
=
'
UPDATE_ADD_DIALOG_NAME
'
;
export
const
UPDATE_ADD_DIALOG_QUANTITY
=
'
UPDATE_ADD_DIALOG_QUANTITY
'
;
export
const
OPEN_ADD_DIALOG
=
'
OPEN_ADD_DIALOG
'
;
export
const
CLOSE_ADD_DIALOG
=
'
CLOSE_ADD_DIALOG
'
;
export
const
ad
d
=
(
id
,
name
,
quantity
)
=>
({
type
:
AD
D
,
export
const
itemAdde
d
=
(
id
,
name
,
quantity
)
=>
({
type
:
ITEM_ADDE
D
,
id
,
name
:
name
,
name
,
quantity
})
...
...
@@ -43,6 +45,16 @@ export const closeAddDialog = () => ({
type
:
CLOSE_ADD_DIALOG
})
export
const
updateAddDialogName
=
(
name
)
=>
({
type
:
UPDATE_ADD_DIALOG_NAME
,
name
})
export
const
updateAddDialogQuantity
=
(
quantity
)
=>
({
type
:
UPDATE_ADD_DIALOG_QUANTITY
,
quantity
})
export
const
itemsLoaded
=
(
items
)
=>
({
type
:
ITEMS_LOADED
,
items
...
...
@@ -52,4 +64,18 @@ export const getAllItems = () => dispatch => {
fetch
(
'
/api/items
'
)
.
then
(
response
=>
response
.
json
())
.
then
(
json
=>
dispatch
(
itemsLoaded
(
json
)))
}
export
const
addItem
=
(
name
,
quantity
)
=>
dispatch
=>
{
var
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
open
(
"
POST
"
,
"
/api/items
"
);
xmlhttp
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
xmlhttp
.
onreadystatechange
=
()
=>
{
if
(
xmlhttp
.
readyState
===
4
&&
xmlhttp
.
status
===
200
)
{
var
json
=
JSON
.
parse
(
xmlhttp
.
responseText
);
dispatch
(
itemAdded
(
json
.
id
,
json
.
name
,
json
.
quantity
))
}
}
xmlhttp
.
send
(
JSON
.
stringify
({
name
,
quantity
}))
}
\ No newline at end of file
src/components/AddDialog/AddDialog.js
View file @
036dc8a5
...
...
@@ -2,7 +2,7 @@ import React from "react";
import
PropTypes
from
"
prop-types
"
;
import
{
Button
,
TextField
,
Dialog
,
DialogActions
,
DialogContent
,
DialogTitle
,
Grid
}
from
'
@material-ui/core/
'
;
const
AddDialog
=
({
isOpen
,
handleClose
,
handleCancel
,
handleAdd
})
=>
(
const
AddDialog
=
({
name
,
quantity
,
isOpen
,
handleClose
,
handleCancel
,
handleAdd
,
updateName
,
updateQuantity
})
=>
(
<
Dialog
open
=
{
isOpen
}
onClose
=
{
handleClose
}
...
...
@@ -19,6 +19,7 @@ const AddDialog = ({ isOpen, handleClose, handleCancel, handleAdd }) => (
id
=
"
name
"
label
=
"
Name
"
type
=
"
string
"
onChange
=
{
updateName
}
/
>
<
/Grid
>
<
Grid
item
>
...
...
@@ -27,6 +28,7 @@ const AddDialog = ({ isOpen, handleClose, handleCancel, handleAdd }) => (
id
=
"
quantity
"
label
=
"
Quantity
"
type
=
"
number
"
onChange
=
{
updateQuantity
}
/
>
<
/Grid
>
<
/Grid
>
...
...
@@ -38,7 +40,7 @@ const AddDialog = ({ isOpen, handleClose, handleCancel, handleAdd }) => (
<
Button
onClick
=
{()
=>
handleCancel
()}
color
=
"
primary
"
>
Cancel
<
/Button
>
<
Button
onClick
=
{()
=>
handleAdd
()}
color
=
"
primary
"
>
<
Button
onClick
=
{()
=>
handleAdd
(
name
,
quantity
)}
color
=
"
primary
"
>
Add
<
/Button
>
<
/DialogActions
>
...
...
@@ -46,6 +48,8 @@ const AddDialog = ({ isOpen, handleClose, handleCancel, handleAdd }) => (
)
AddDialog
.
propTypes
=
{
name
:
PropTypes
.
string
,
quantity
:
PropTypes
.
number
,
isOpen
:
PropTypes
.
bool
.
isRequired
,
handleClose
:
PropTypes
.
func
.
isRequired
,
handleCancel
:
PropTypes
.
func
.
isRequired
,
...
...
src/container/AddDialogContainer/AddDialogContainer.js
View file @
036dc8a5
import
{
connect
}
from
'
react-redux
'
import
AddDialog
from
'
../../components/AddDialog/AddDialog
'
import
{
createSelector
}
from
'
reselect
'
import
{
closeAddDialog
}
from
'
../../actions
'
import
{
closeAddDialog
,
updateAddDialogName
,
updateAddDialogQuantity
,
addItem
}
from
'
../../actions
'
const
getAddDialog
=
state
=>
state
.
addDialog
;
...
...
@@ -12,14 +12,35 @@ const getIsOpen = createSelector(
}
)
const
getNewName
=
createSelector
(
[
getAddDialog
],
(
addDialog
)
=>
{
return
addDialog
.
name
}
)
const
getNewQuantity
=
createSelector
(
[
getAddDialog
],
(
addDialog
)
=>
{
return
addDialog
.
quantity
}
)
const
mapStateToProps
=
state
=>
({
isOpen
:
getIsOpen
(
state
)
isOpen
:
getIsOpen
(
state
),
name
:
getNewName
(
state
),
quantity
:
getNewQuantity
(
state
)
})
const
mapDispatchToProps
=
dispatch
=>
({
const
mapDispatchToProps
=
(
dispatch
)
=>
({
handleClose
:
()
=>
dispatch
(
closeAddDialog
()),
handleCancel
:
()
=>
dispatch
(
closeAddDialog
()),
handleAdd
:
()
=>
dispatch
(
closeAddDialog
())
handleAdd
:
(
name
,
quantity
)
=>
{
dispatch
(
closeAddDialog
());
dispatch
(
addItem
(
name
,
quantity
))
},
updateName
:
event
=>
dispatch
(
updateAddDialogName
(
event
.
target
.
value
)),
updateQuantity
:
event
=>
dispatch
(
updateAddDialogQuantity
(
Number
(
event
.
target
.
value
)))
})
export
default
connect
(
...
...
src/reducers/addDialog.js
View file @
036dc8a5
import
{
OPEN_ADD_DIALOG
,
CLOSE_ADD_DIALOG
}
from
'
../actions
'
import
{
OPEN_ADD_DIALOG
,
CLOSE_ADD_DIALOG
,
UPDATE_ADD_DIALOG_NAME
,
UPDATE_ADD_DIALOG_QUANTITY
}
from
'
../actions
'
const
addDialog
=
(
state
=
{
isOpen
:
false
},
action
)
=>
{
const
addDialog
=
(
state
=
{
isOpen
:
false
,
name
:
""
,
quantity
:
0
},
action
)
=>
{
switch
(
action
.
type
)
{
case
OPEN_ADD_DIALOG
:
return
{
isOpen
:
true
}
return
{
...
state
,
isOpen
:
true
}
case
CLOSE_ADD_DIALOG
:
return
{
isOpen
:
false
}
return
{...
state
,
isOpen
:
false
,
name
:
""
,
quantity
:
0
}
case
UPDATE_ADD_DIALOG_NAME
:
return
{...
state
,
name
:
action
.
name
}
case
UPDATE_ADD_DIALOG_QUANTITY
:
return
{...
state
,
quantity
:
action
.
quantity
}
default
:
return
state
}
...
...
src/reducers/items.js
View file @
036dc8a5
import
{
ADD
,
DELETE_ITEM
,
INCREMENT
,
DECREMENT
,
ITEMS_LOA
DED
}
from
'
../actions
'
;
import
{
DELETE_ITEM
,
INCREMENT
,
DECREMENT
,
ITEMS_LOADED
,
ITEM_AD
DED
}
from
'
../actions
'
;
const
items
=
(
state
=
[],
action
)
=>
{
switch
(
action
.
type
)
{
case
ITEMS_LOADED
:
return
action
.
items
case
AD
D
:
case
ITEM_ADDE
D
:
return
[
...
state
,
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment