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
c184820a
Commit
c184820a
authored
May 07, 2021
by
Sumaiyya Burney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fetches products from DB and outputs as table
parent
290c7a9b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
2 deletions
+59
-2
apiRequests.js
src/actions/apiRequests.js
+8
-0
Main.jsx
src/component/Main.jsx
+17
-2
ProductGrid.jsx
src/component/ProductGrid.jsx
+28
-0
config.js
src/config.js
+6
-0
No files found.
src/actions/apiRequests.js
0 → 100644
View file @
c184820a
import
Config
from
'../config'
;
import
axios
from
'axios'
;
export
const
getAllProducts
=
async
data
=>
{
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
// console.log(res.data);
return
res
.
data
;
}
\ No newline at end of file
src/component/Main.jsx
View file @
c184820a
import
React
from
"react"
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
Redirect
,
Switch
}
from
"react-router"
;
import
{
Redirect
,
Switch
}
from
"react-router"
;
import
AuthRoute
from
"./AuthRoute"
;
import
AuthRoute
from
"./AuthRoute"
;
import
ProductForm
from
"./ProductForm"
;
import
ProductForm
from
"./ProductForm"
;
import
ProductGrid
from
"./ProductGrid"
;
import
{
getAllProducts
}
from
"../actions/apiRequests.js"
export
default
function
Main
()
{
export
default
function
Main
()
{
const
[
productData
,
setproductData
]
=
useState
([]);
useEffect
(()
=>
{
loadProducts
();
},
[]);
const
loadProducts
=
async
(
event
)
=>
{
const
data
=
await
getAllProducts
();
setproductData
(
data
);
}
return
(
return
(
<
div
>
<
div
>
<
Switch
>
<
Switch
>
...
@@ -11,7 +24,9 @@ export default function Main() {
...
@@ -11,7 +24,9 @@ export default function Main() {
<
ProductForm
/>
<
ProductForm
/>
</
AuthRoute
>
</
AuthRoute
>
<
AuthRoute
exact
path=
"/promos/new"
>
NEW PROMO
</
AuthRoute
>
<
AuthRoute
exact
path=
"/promos/new"
>
NEW PROMO
</
AuthRoute
>
<
AuthRoute
exact
path=
"/products"
>
PRODUCTS
</
AuthRoute
>
<
AuthRoute
exact
path=
"/products"
>
<
ProductGrid
productData=
{
productData
}
/>
</
AuthRoute
>
<
AuthRoute
path=
"/promos"
>
PROMOS
</
AuthRoute
>
<
AuthRoute
path=
"/promos"
>
PROMOS
</
AuthRoute
>
<
AuthRoute
exact
path=
"/"
>
<
AuthRoute
exact
path=
"/"
>
<
Redirect
to=
"/products"
/>
<
Redirect
to=
"/products"
/>
...
...
src/component/ProductGrid.jsx
0 → 100644
View file @
c184820a
import
React
from
'react'
export
default
function
ProductGrid
({
productData
})
{
return
(
<
div
>
PRODUCT GRID
<
div
id=
"prod-grid"
>
<
table
>
<
tbody
>
{
productData
.
map
((
product
)
=>
{
return
(
<
tr
>
<
td
><
img
src=
{
product
.
productImageUrl
}
alt=
"product"
/></
td
>
<
td
>
{
product
.
productName
}
</
td
>
<
td
>
{
product
.
price
}
</
td
>
<
td
>
{
product
.
sku
}
</
td
>
<
td
>
{
product
.
description
}
</
td
>
</
tr
>
)
})
}
</
tbody
>
</
table
>
</
div
>
</
div
>
)
}
src/config.js
0 → 100644
View file @
c184820a
class
Config
{
static
inventoryUrl
=
"http://localhost:8080/api/products"
;
static
promotionsUrl
=
"http://localhost:8081/api/promos"
;
}
export
default
Config
;
\ No newline at end of file
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