Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-promotion-react
Project
Project
Details
Activity
Releases
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
Ascend
inventory-promotion-react
Commits
c527f1b9
Commit
c527f1b9
authored
May 11, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-15] Finish work on delete product functionality
parent
227fb9ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
13 deletions
+17
-13
apiRequests.js
src/actions/apiRequests.js
+2
-2
Product.jsx
src/component/Product.jsx
+5
-9
ProductGrid.jsx
src/component/ProductGrid.jsx
+10
-2
No files found.
src/actions/apiRequests.js
View file @
c527f1b9
...
...
@@ -8,8 +8,8 @@ export const getAllProducts = async data => {
}
export
const
deleteProduct
=
async
(
sku
)
=>
{
await
axios
.
delete
(
`
${
Config
.
inventoryUrl
}
/
${
sku
}
`
)
await
axios
.
delete
(
`
${
Config
.
inventoryUrl
}
/
${
sku
}
`
)
.
then
(()
=>
{
return
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
getAllProducts
(
);
});
}
\ No newline at end of file
src/component/Product.jsx
View file @
c527f1b9
import
React
,
{
useState
}
from
"react"
;
import
"./../styles/Product.css"
;
import
{
Modal
,
Button
,
Alert
}
from
"react-bootstrap"
;
import
{
deleteProduct
}
from
"../actions/apiRequests"
;
export
default
function
Product
({
product
})
{
export
default
function
Product
({
product
,
handleDelete
})
{
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
showConfirm
,
setShowConfirm
]
=
useState
(
false
);
...
...
@@ -12,12 +11,9 @@ export default function Product({ product }) {
handleCloseConfirm
();
};
const
handleDelete
=
(
sku
)
=>
{
deleteProduct
(
sku
)
.
then
(
res
=>
{
const
products
=
res
.
data
;
this
.
setState
({
products
});
});
const
handleCloseDelete
=
(
sku
)
=>
{
handleDelete
(
sku
)
handleClose
();
}
...
...
@@ -77,7 +73,7 @@ export default function Product({ product }) {
Cancel
</
Button
>
<
Button
variant=
"danger"
onClick=
{
handl
eDelete
(
product
.
sku
)
}
>
Yes, delete
</
Button
>
<
Button
variant=
"danger"
onClick=
{
()
=>
handleClos
eDelete
(
product
.
sku
)
}
>
Yes, delete
</
Button
>
</
Alert
>
</
Modal
.
Footer
>
</
Modal
>
...
...
src/component/ProductGrid.jsx
View file @
c527f1b9
...
...
@@ -4,6 +4,7 @@ import { Col, Container, Row } from "react-bootstrap";
import
"./../styles/ProductGrid.css"
;
import
Config
from
"../config.js"
;
import
{
Link
}
from
"react-router-dom"
;
import
{
deleteProduct
}
from
"../actions/apiRequests"
;
export
default
function
ProductGrid
({
productData
})
{
const
[
products
,
setProducts
]
=
useState
([]);
...
...
@@ -16,10 +17,17 @@ export default function ProductGrid({ productData }) {
}
};
const
handleDelete
=
(
sku
)
=>
{
deleteProduct
(
sku
)
.
then
(()
=>
{
fetchProducts
();
});
}
useEffect
(()
=>
fetchProducts
(),
[]);
return
(
<
div
class=
"container flex-column d-flex justify-content-center"
>
<
div
class
Name
=
"container flex-column d-flex justify-content-center"
>
<
div
className=
"container mt-3 d-flex justify-content-between align-items-center"
>
<
h1
id=
"title"
className=
"text-center"
>
Inventory
...
...
@@ -33,7 +41,7 @@ export default function ProductGrid({ productData }) {
{
products
.
map
((
product
)
=>
{
return
(
<
Col
key=
{
product
.
sku
}
>
<
Product
product=
{
product
}
/>
<
Product
product=
{
product
}
handleDelete=
{
()
=>
handleDelete
(
product
.
sku
)
}
/>
</
Col
>
);
})
}
...
...
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