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
b9216aab
Commit
b9216aab
authored
Jul 30, 2020
by
zarina
🌊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#5
, добавила возможность просмотра одного товара, возможность удаления товаров
parent
3c11c7eb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
3 deletions
+93
-3
Toolbar.js
src/components/UI/Toolbar/Toolbar.js
+1
-1
App.js
src/containers/App.js
+3
-0
FullProduct.css
src/containers/FullProduct/FullProduct.css
+0
-0
FullProduct.js
src/containers/FullProduct/FullProduct.js
+60
-0
Products.css
src/containers/Products/Products.css
+0
-1
Products.js
src/containers/Products/Products.js
+1
-1
productsActions.js
src/store/actions/productsActions.js
+28
-0
No files found.
src/components/UI/Toolbar/Toolbar.js
View file @
b9216aab
...
@@ -13,7 +13,7 @@ const Toolbar = ({user, logout}) => {
...
@@ -13,7 +13,7 @@ const Toolbar = ({user, logout}) => {
return
(
return
(
<
Navbar
color
=
"dark"
dark
expand
=
"md"
>
<
Navbar
color
=
"dark"
dark
expand
=
"md"
>
<
Container
>
<
Container
>
<
NavbarBrand
tag
=
{
RouterNavLink
}
to
=
"/"
>
M
arket
<
/NavbarBrand
>
<
NavbarBrand
tag
=
{
RouterNavLink
}
to
=
"/"
>
Some
m
arket
<
/NavbarBrand
>
<
Nav
className
=
"ml-auto"
navbar
>
<
Nav
className
=
"ml-auto"
navbar
>
...
...
src/containers/App.js
View file @
b9216aab
...
@@ -9,6 +9,8 @@ import Register from "./Register/Register";
...
@@ -9,6 +9,8 @@ import Register from "./Register/Register";
import
Login
from
"./Login/Login"
;
import
Login
from
"./Login/Login"
;
import
AddProductForm
from
"./AddProductForm/AddProductForm"
;
import
AddProductForm
from
"./AddProductForm/AddProductForm"
;
import
{
logoutUser
}
from
"../store/actions/usersActions"
;
import
{
logoutUser
}
from
"../store/actions/usersActions"
;
import
FullProduct
from
"./FullProduct/FullProduct"
;
class
App
extends
Component
{
class
App
extends
Component
{
...
@@ -31,6 +33,7 @@ class App extends Component {
...
@@ -31,6 +33,7 @@ class App extends Component {
<
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
}
/
>
<
Route
path
=
"/products/:id"
exact
component
=
{
FullProduct
}
/
>
<
/Switch
>
<
/Switch
>
<
/Container
>
<
/Container
>
<
/main
>
<
/main
>
...
...
src/containers/FullProduct/FullProduct.css
0 → 100644
View file @
b9216aab
src/containers/FullProduct/FullProduct.js
0 → 100644
View file @
b9216aab
import
React
,
{
Component
}
from
"react"
;
import
{
connect
}
from
"react-redux"
;
import
config
from
"../../config"
;
import
'./FullProduct.css'
import
{
Badge
,
Button
}
from
"reactstrap"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
{
deleteProduct
,
getFullProduct
}
from
"../../store/actions/productsActions"
;
class
FullProduct
extends
Component
{
componentDidMount
()
{
this
.
props
.
getFullProduct
(
this
.
props
.
match
.
params
.
id
)
}
render
()
{
return
(
<>
{(
this
.
props
.
fullProduct
&&
this
.
props
.
fullProduct
.
author
)
?
(
<>
<
img
width
=
"500"
className
=
'postImage'
src
=
{
config
.
apiURL
+
'/uploads/'
+
this
.
props
.
fullProduct
.
image
}
alt
=
""
/>
<
h2
>
product
name
:
{
this
.
props
.
fullProduct
.
title
}
<
/h2
>
<
h5
>
price
:
{
this
.
props
.
fullProduct
.
price
}
$
<
/h5
>
<
h5
>
category
:
{
this
.
props
.
fullProduct
.
category
.
title
}
<
/h5
>
<
h5
>
description
:
{
this
.
props
.
fullProduct
.
description
}
<
/h5
>
<
h6
className
=
'mt-3'
>
author
:
{
this
.
props
.
fullProduct
.
author
.
displayName
}
<
/h6
>
<
h6
>
phone
:
{
this
.
props
.
fullProduct
.
author
.
phone
}
<
/h6
>
<
/
>
)
:
null
}
{(
this
.
props
.
fullProduct
&&
this
.
props
.
fullProduct
.
author
&&
this
.
props
.
user
&&
this
.
props
.
user
.
username
===
this
.
props
.
fullProduct
.
author
.
username
)
?
(
<
Button
className
=
'mt-4'
color
=
'danger'
onClick
=
{()
=>
this
.
props
.
deleteProduct
(
this
.
props
.
match
.
params
.
id
)}
>
Delete
product
<
/Button>
)
: null
}
<
/
>
);
}
}
const
mapStateToProps
=
state
=>
{
return
{
fullProduct
:
state
.
products
.
fullProduct
,
user
:
state
.
users
.
user
}
};
const
mapDispatchToProps
=
dispatch
=>
{
return
{
getFullProduct
:
(
id
)
=>
dispatch
(
getFullProduct
(
id
)),
deleteProduct
:
(
id
)
=>
dispatch
(
deleteProduct
(
id
))
}
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
FullProduct
);
src/containers/Products/Products.css
View file @
b9216aab
.Products
{
.Products
{
display
:
flex
;
display
:
flex
;
}
}
.Products_categories
{
.Products_categories
{
width
:
30%
;
width
:
30%
;
}
}
...
...
src/containers/Products/Products.js
View file @
b9216aab
...
@@ -45,7 +45,7 @@ class Products extends Component {
...
@@ -45,7 +45,7 @@ class Products extends Component {
title
=
{
product
.
title
}
title
=
{
product
.
title
}
price
=
{
product
.
price
}
/
>
price
=
{
product
.
price
}
/
>
);
);
}))
:
<
h
1
>
Nothing
to
see
here
<
/h1
>
}))
:
<
h
5
>
No
products
in
this
category
<
/h5
>
}
}
<
/Row
>
<
/Row
>
<
/div
>
<
/div
>
...
...
src/store/actions/productsActions.js
View file @
b9216aab
...
@@ -44,6 +44,18 @@ export const fetchProducts = (category) => {
...
@@ -44,6 +44,18 @@ 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
)
=>
{
...
@@ -62,3 +74,19 @@ export const createProduct = product => {
...
@@ -62,3 +74,19 @@ 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