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
b3fda0f1
Commit
b3fda0f1
authored
May 12, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'AFP-141' into 'dev'
Afp 141 See merge request
!15
parents
7d32de39
7436c8a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
15 deletions
+53
-15
ProductForm.jsx
src/component/ProductForm.jsx
+0
-1
ProductIndex.jsx
src/component/ProductIndex.jsx
+44
-5
ProductTable.jsx
src/component/ProductTable.jsx
+9
-9
No files found.
src/component/ProductForm.jsx
View file @
b3fda0f1
...
...
@@ -128,7 +128,6 @@ export default function ProductForm(props) {
type=
"text"
className=
"form-control"
id=
"productSku"
disabled=
{
method
===
"PUT"
?
true
:
false
}
value=
{
form
.
sku
}
onChange=
{
(
e
)
=>
setForm
({
...
form
,
sku
:
e
.
target
.
value
})
}
/>
...
...
src/component/ProductIndex.jsx
View file @
b3fda0f1
import
React
,
{
useEffect
,
useState
}
from
"react"
;
import
ProductTable
from
"./ProductTable.jsx"
import
ProductTable
from
"./ProductTable.jsx"
;
import
Config
from
"../config.js"
;
import
{
Link
}
from
"react-router-dom"
;
export
default
function
ProductIndex
()
{
const
[
products
,
setProducts
]
=
useState
([]);
const
[
displayProducts
,
setDisplayProducts
]
=
useState
([]);
const
[
categories
,
setCategories
]
=
useState
([]);
const
[
activeCategory
,
setActiveCategory
]
=
useState
(
""
);
console
.
log
(
displayProducts
);
const
fetchProducts
=
async
()
=>
{
const
res
=
await
fetch
(
`
${
Config
.
inventoryUrl
}
`
);
if
(
res
.
ok
)
{
const
data
=
await
res
.
json
();
setProducts
([...
data
]);
setDisplayProducts
([...
data
]);
setCategories
([
...
data
.
reduce
((
acc
,
prod
)
=>
{
if
(
!
acc
.
includes
(
prod
.
category
))
{
acc
.
push
(
prod
.
category
);
}
return
acc
;
},
[]),
]);
}
};
...
...
@@ -26,10 +39,36 @@ export default function ProductIndex() {
+ New Product
</
Link
>
</
div
>
{
products
.
length
>
0
?
<
ProductTable
productData=
{
products
}
/>
:
<
p
>
No products found.
</
p
>
}
{
products
.
length
>
0
?
(
<>
<
select
className=
"form-select w-25 mt-1"
id=
"category-select"
onChange=
{
(
e
)
=>
{
if
(
e
.
target
.
value
===
""
)
{
setDisplayProducts
([...
products
]);
return
;
}
const
filtered
=
products
.
filter
(
(
prod
)
=>
prod
.
category
===
e
.
target
.
value
);
setDisplayProducts
([...
filtered
]);
}
}
>
<
option
value=
""
>
Select Category
</
option
>
{
categories
.
map
((
category
,
i
)
=>
(
<
option
key=
{
i
+
679
}
>
{
category
}
</
option
>
))
}
</
select
>
<
ProductTable
productData=
{
displayProducts
}
fetchProducts=
{
fetchProducts
}
products=
{
displayProducts
}
/>
</>
)
:
(
<
p
>
No products found.
</
p
>
)
}
</
div
>
);
}
src/component/ProductTable.jsx
View file @
b3fda0f1
...
...
@@ -4,16 +4,16 @@ import { Container, Table } from "react-bootstrap";
import
Config
from
"../config.js"
;
import
{
deleteProduct
}
from
"../actions/apiRequests"
;
export
default
function
ProductTable
({
productData
})
{
const
[
products
,
setProducts
]
=
useState
([
productData
]);
export
default
function
ProductTable
({
fetchProducts
,
products
})
{
// const [products, setProducts] = useState([...
productData]);
const
fetchProducts
=
async
()
=>
{
const
res
=
await
fetch
(
`
${
Config
.
inventoryUrl
}
`
);
if
(
res
.
ok
)
{
const
data
=
await
res
.
json
();
setProducts
([...
data
]);
}
};
//
const fetchProducts = async () => {
//
const res = await fetch(`${Config.inventoryUrl}`);
//
if (res.ok) {
//
const data = await res.json();
//
setProducts([...data]);
//
}
//
};
const
handleDelete
=
(
sku
)
=>
{
deleteProduct
(
sku
)
...
...
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