Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
exam_11_front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zarina
exam_11_front
Commits
3c11c7eb
Commit
3c11c7eb
authored
Jul 30, 2020
by
zarina
🌊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
, добавила отображение товаров
parent
611c28ab
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
121 additions
and
34 deletions
+121
-34
Product.js
src/components/Product/Product.js
+29
-0
UserMenu.js
src/components/UI/Toolbar/Menus/UserMenu.js
+1
-1
App.css
src/containers/App.css
+0
-0
App.js
src/containers/App.js
+9
-4
App.test.js
src/containers/App.test.js
+1
-1
Products.css
src/containers/Products/Products.css
+10
-0
Products.js
src/containers/Products/Products.js
+71
-0
productsActions.js
src/store/actions/productsActions.js
+0
-28
No files found.
src/components/Product/Product.js
0 → 100644
View file @
3c11c7eb
import
React
from
"react"
;
import
{
Button
,
Card
,
CardBody
,
CardImg
,
CardText
,
Col
}
from
"reactstrap"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
PropTypes
from
"prop-types"
;
import
config
from
"../../config"
;
const
Product
=
(
props
)
=>
{
return
(
<
Col
md
=
{
5
}
className
=
'mb-3 p-3'
>
<
Card
className
=
'p-3 h-100'
>
<
CardImg
top
className
=
'w-80'
src
=
{
config
.
apiURL
+
'/uploads/'
+
props
.
image
}
alt
=
"Card image cap"
/>
<
CardBody
>
<
h5
className
=
'mb-0 font-weight-bold'
>
{
props
.
title
}
<
/h5
>
<
CardText
>
price
:
{
props
.
price
}
<
/CardText
>
<
Button
tag
=
{
NavLink
}
to
=
{
/
products
/
+
props
.
id
}
>
Show
product
<
/Button
>
<
/CardBody
>
<
/Card
>
<
/Col
>
);
};
Product
.
propTypes
=
{
id
:
PropTypes
.
string
.
isRequired
,
image
:
PropTypes
.
string
.
isRequired
,
title
:
PropTypes
.
string
.
isRequired
,
price
:
PropTypes
.
number
.
isRequired
};
export
default
Product
;
src/components/UI/Toolbar/Menus/UserMenu.js
View file @
3c11c7eb
...
@@ -12,7 +12,7 @@ const UserMenu = ({user, logout}) => {
...
@@ -12,7 +12,7 @@ const UserMenu = ({user, logout}) => {
<
NavItem
>
<
NavItem
>
<
NavLink
tag
=
{
RouterNavLink
}
to
=
"/products/new"
exact
>
Create
product
<
/NavLink
>
<
NavLink
tag
=
{
RouterNavLink
}
to
=
"/products/new"
exact
>
Create
product
<
/NavLink
>
<
/NavItem
>
<
/NavItem
>
<
UncontrolledDropdown
className
=
'ml-5'
nav
navbar
inNavbar
>
<
UncontrolledDropdown
className
=
'ml-5'
>
<
DropdownToggle
nav
caret
>
<
DropdownToggle
nav
caret
>
Hello
,
{
user
.
displayName
}
!
Hello
,
{
user
.
displayName
}
!
<
/DropdownToggle
>
<
/DropdownToggle
>
...
...
src/App.css
→
src/
containers/
App.css
View file @
3c11c7eb
File moved
src/containers/App.js
View file @
3c11c7eb
import
React
,
{
Component
,
Fragment
}
from
'react'
;
import
React
,
{
Component
,
Fragment
}
from
'react'
;
import
Toolbar
from
"../components/UI/Toolbar/Toolbar"
;
import
{
Container
}
from
"reactstrap"
;
import
{
Container
}
from
"reactstrap"
;
import
{
Route
,
Switch
,
withRouter
}
from
"react-router-dom"
;
import
{
Route
,
Switch
,
withRouter
}
from
"react-router-dom"
;
import
Register
from
"./Register/Register"
;
import
Login
from
"./Login/Login"
;
import
{
connect
}
from
"react-redux"
;
import
{
connect
}
from
"react-redux"
;
import
{
NotificationContainer
}
from
"react-notifications"
;
import
{
NotificationContainer
}
from
"react-notifications"
;
import
{
logoutUser
}
from
"../store/actions/usersActions"
;
import
Toolbar
from
"../components/UI/Toolbar/Toolbar"
;
import
Products
from
"./Products/Products"
;
import
Register
from
"./Register/Register"
;
import
Login
from
"./Login/Login"
;
import
AddProductForm
from
"./AddProductForm/AddProductForm"
;
import
AddProductForm
from
"./AddProductForm/AddProductForm"
;
import
{
logoutUser
}
from
"../store/actions/usersActions"
;
class
App
extends
Component
{
class
App
extends
Component
{
render
()
{
render
()
{
...
@@ -23,6 +25,9 @@ class App extends Component {
...
@@ -23,6 +25,9 @@ class App extends Component {
<
main
>
<
main
>
<
Container
className
=
"mt-5"
>
<
Container
className
=
"mt-5"
>
<
Switch
>
<
Switch
>
<
Route
path
=
"/"
exact
component
=
{
Products
}
/
>
<
Route
path
=
"/products"
exact
component
=
{
Products
}
/
>
<
Route
path
=
"/category/:id"
exact
component
=
{
Products
}
/
>
<
Route
path
=
"/register"
exact
component
=
{
Register
}
/
>
<
Route
path
=
"/register"
exact
component
=
{
Register
}
/
>
<
Route
path
=
"/login"
exact
component
=
{
Login
}
/
>
<
Route
path
=
"/login"
exact
component
=
{
Login
}
/
>
<
Route
path
=
"/products/new"
exact
component
=
{
AddProductForm
}
/
>
<
Route
path
=
"/products/new"
exact
component
=
{
AddProductForm
}
/
>
...
...
src/App.test.js
→
src/
containers/
App.test.js
View file @
3c11c7eb
import
React
from
'react'
;
import
React
from
'react'
;
import
{
render
}
from
'@testing-library/react'
;
import
{
render
}
from
'@testing-library/react'
;
import
App
from
'./
containers/
App'
;
import
App
from
'./App'
;
test
(
'renders learn react link'
,
()
=>
{
test
(
'renders learn react link'
,
()
=>
{
const
{
getByText
}
=
render
(
<
App
/>
);
const
{
getByText
}
=
render
(
<
App
/>
);
...
...
src/containers/Products/Products.css
0 → 100644
View file @
3c11c7eb
.Products
{
display
:
flex
;
}
.Products_categories
{
width
:
30%
;
}
.Products_items
{
width
:
70%
;
}
\ No newline at end of file
src/containers/Products/Products.js
0 → 100644
View file @
3c11c7eb
import
React
,
{
Component
}
from
"react"
;
import
{
Nav
,
NavItem
,
Row
}
from
"reactstrap"
;
import
{
connect
}
from
"react-redux"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
'./Products.css'
;
import
Product
from
"../../components/Product/Product"
;
import
{
fetchCategories
}
from
"../../store/actions/categoriesActions"
;
import
{
fetchProducts
}
from
"../../store/actions/productsActions"
;
class
Products
extends
Component
{
componentDidMount
()
{
this
.
props
.
onFetchCategories
();
this
.
props
.
fetchProducts
(
this
.
props
.
match
.
params
.
id
)
}
componentDidUpdate
(
prevProps
)
{
if
(
this
.
props
.
match
.
params
.
id
!==
prevProps
.
match
.
params
.
id
)
{
this
.
props
.
fetchProducts
(
this
.
props
.
match
.
params
.
id
)
}
};
render
()
{
return
(
<
div
className
=
'Products'
>
<
Nav
navbar
c
vertical
className
=
'Products_categories'
>
<
NavItem
>
<
NavLink
to
=
'/'
>
All
items
<
/NavLink
>
<
/NavItem
>
{
this
.
props
.
categories
.
map
(
category
=>
{
return
(
<
NavItem
key
=
{
category
.
_id
}
>
<
NavLink
to
=
{
'/category/'
+
category
.
_id
}
>
{
category
.
title
}
<
/NavLink
>
<
/NavItem>
)
})}
<
/Nav
>
<
div
className
=
'Products_items'
>
<
h3
>
Products
:
<
/h3
>
<
Row
>
{
this
.
props
.
products
.
length
>
0
?
(
this
.
props
.
products
.
map
(
product
=>
{
return
(
<
Product
key
=
{
product
.
_id
}
id
=
{
product
.
_id
}
image
=
{
product
.
image
}
title
=
{
product
.
title
}
price
=
{
product
.
price
}
/
>
);
}))
:
<
h1
>
Nothing
to
see
here
<
/h1
>
}
<
/Row
>
<
/div
>
<
/div
>
);
}
}
const
mapStateToProps
=
state
=>
{
return
{
categories
:
state
.
categories
.
categories
,
products
:
state
.
products
.
products
}
};
const
mapDispatchToProps
=
dispatch
=>
{
return
{
onFetchCategories
:
()
=>
dispatch
(
fetchCategories
()),
fetchProducts
:
(
category
)
=>
dispatch
(
fetchProducts
(
category
)),
}
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Products
);
src/store/actions/productsActions.js
View file @
3c11c7eb
...
@@ -44,18 +44,6 @@ export const fetchProducts = (category) => {
...
@@ -44,18 +44,6 @@ export const fetchProducts = (category) => {
};
};
};
};
export
const
getFullProduct
=
id
=>
{
return
dispatch
=>
{
axios
.
get
(
'/products/'
+
id
)
.
then
(
res
=>
{
dispatch
(
getFullProductSuccess
(
res
.
data
));
})
.
catch
(
e
=>
{
dispatch
(
fetchError
(
e
));
})
};
};
export
const
createProduct
=
product
=>
{
export
const
createProduct
=
product
=>
{
return
(
dispatch
,
getState
)
=>
{
return
(
dispatch
,
getState
)
=>
{
...
@@ -74,19 +62,3 @@ export const createProduct = product => {
...
@@ -74,19 +62,3 @@ export const createProduct = product => {
};
};
export
const
deleteProduct
=
id
=>
{
return
(
dispatch
,
getState
)
=>
{
const
token
=
getState
().
users
.
user
.
token
;
const
headers
=
{
Token
:
token
};
console
.
log
(
headers
)
axios
.
delete
(
'/products/'
+
id
,
{
headers
})
.
then
(()
=>
{
dispatch
(
push
(
'/'
));
NotificationManager
.
success
(
"Deleted!"
);
})
.
catch
(
e
=>
{
dispatch
(
fetchError
(
e
));
})
};
};
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