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
734ea5af
Commit
734ea5af
authored
May 11, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Plain Diff
[AFP-15] Fix merge conflict
parents
c527f1b9
aeeffe76
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
12 deletions
+141
-12
apiRequests.js
src/actions/apiRequests.js
+15
-1
Header.jsx
src/component/Header.jsx
+2
-10
Main.jsx
src/component/Main.jsx
+3
-1
Search.jsx
src/component/Search.jsx
+77
-0
SearchResults.jsx
src/component/SearchResults.jsx
+37
-0
Search.css
src/styles/Search.css
+7
-0
No files found.
src/actions/apiRequests.js
View file @
734ea5af
...
@@ -3,7 +3,6 @@ import axios from 'axios';
...
@@ -3,7 +3,6 @@ import axios from 'axios';
export
const
getAllProducts
=
async
data
=>
{
export
const
getAllProducts
=
async
data
=>
{
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
// console.log(res.data);
return
res
.
data
;
return
res
.
data
;
}
}
...
@@ -12,4 +11,19 @@ export const deleteProduct = async (sku) => {
...
@@ -12,4 +11,19 @@ export const deleteProduct = async (sku) => {
.
then
(()
=>
{
.
then
(()
=>
{
getAllProducts
();
getAllProducts
();
});
});
}
export
const
getFilteredProducts
=
async
(
searchTerm
,
searchBy
)
=>
{
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
return
res
.
data
.
filter
(
product
=>
{
let
productFiltered
;
if
(
searchBy
===
"name"
){
productFiltered
=
product
.
productName
.
toLowerCase
();
}
else
if
(
searchBy
===
"sku"
){
productFiltered
=
product
.
sku
.
toLowerCase
();
}
return
productFiltered
.
includes
(
searchTerm
.
toLowerCase
());
});
}
}
\ No newline at end of file
src/component/Header.jsx
View file @
734ea5af
import
React
,
{
useState
}
from
"react"
;
import
React
,
{
useState
}
from
"react"
;
import
{
Link
}
from
"react-router-dom"
;
import
{
Link
}
from
"react-router-dom"
;
import
Search
from
"./Search"
;
const
Header
=
()
=>
{
const
Header
=
()
=>
{
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
show
,
setShow
]
=
useState
(
false
);
...
@@ -38,16 +39,7 @@ const Header = () => {
...
@@ -38,16 +39,7 @@ const Header = () => {
</
Link
>
</
Link
>
</
li
>
</
li
>
</
ul
>
</
ul
>
<
form
className=
"d-flex"
>
<
Search
/>
<
input
type=
"search"
className=
"form-control me-2"
placeholder=
"search"
/>
<
button
className=
"btn btn-light"
type=
"submit"
>
GO
</
button
>
</
form
>
</
div
>
</
div
>
</
div
>
</
div
>
</
nav
>
</
nav
>
...
...
src/component/Main.jsx
View file @
734ea5af
...
@@ -3,7 +3,8 @@ import { Redirect, Switch } from "react-router";
...
@@ -3,7 +3,8 @@ 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
ProductGrid
from
"./ProductGrid"
;
import
{
getAllProducts
}
from
"../actions/apiRequests.js"
;
import
SearchResults
from
"./SearchResults"
;
import
{
getAllProducts
}
from
"../actions/apiRequests.js"
import
PromotionNewFormComponent
from
"./promotionforms/PromotionNewFormComponent"
;
import
PromotionNewFormComponent
from
"./promotionforms/PromotionNewFormComponent"
;
export
default
function
Main
()
{
export
default
function
Main
()
{
...
@@ -37,6 +38,7 @@ export default function Main() {
...
@@ -37,6 +38,7 @@ export default function Main() {
<
AuthRoute
exact
path=
"/"
>
<
AuthRoute
exact
path=
"/"
>
<
Redirect
to=
"/products"
/>
<
Redirect
to=
"/products"
/>
</
AuthRoute
>
</
AuthRoute
>
<
AuthRoute
path=
"/searchResults"
component=
{
SearchResults
}
/>
<
AuthRoute
>
<
AuthRoute
>
<
h1
>
404 Page Not Found
</
h1
>
<
h1
>
404 Page Not Found
</
h1
>
</
AuthRoute
>
</
AuthRoute
>
...
...
src/component/Search.jsx
0 → 100644
View file @
734ea5af
import
React
from
'react'
;
import
{
withRouter
,
Link
}
from
"react-router-dom"
;
import
{
getFilteredProducts
}
from
'../actions/apiRequests'
;
import
"./../styles/Search.css"
;
class
Search
extends
React
.
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
searchTerm
:
''
,
searchBy
:
'name'
,
results
:
[],
};
this
.
submit
=
this
.
submit
.
bind
(
this
);
this
.
changeTerm
=
this
.
changeTerm
.
bind
(
this
);
this
.
handleRadioButton
=
this
.
handleRadioButton
.
bind
(
this
);
}
changeTerm
(
event
)
{
this
.
setState
({
searchTerm
:
event
.
target
.
value
});
}
handleRadioButton
(
value
)
{
this
.
setState
({
searchBy
:
value
});
}
async
submit
(
event
){
event
.
preventDefault
();
const
data
=
await
getFilteredProducts
(
this
.
state
.
searchTerm
,
this
.
state
.
searchBy
)
.
then
(
res
=>
{
this
.
setState
({
results
:
res
});
})
.
catch
(
err
=>
console
.
log
(
err
));
if
(
this
.
props
.
location
.
pathname
===
"/searchResults"
){
this
.
props
.
history
.
push
(
"/products"
,
this
.
state
);
}
this
.
props
.
history
.
push
(
"/searchResults"
,
this
.
state
);
}
//Need to search by name or SKU
render
(){
return
(
<
div
>
<
form
className=
"d-flex"
onSubmit=
{
this
.
submit
}
>
<
input
type=
"search"
className=
"form-control me-2"
placeholder=
"Search for item..."
onChange=
{
event
=>
this
.
changeTerm
(
event
)
}
/>
<
div
className=
"form-check form-check-inline"
>
<
input
className=
"form-check-input"
type=
"radio"
name=
"inlineRadioOptions"
checked=
{
this
.
state
.
searchBy
===
"name"
}
onChange=
{
()
=>
this
.
handleRadioButton
(
"name"
)
}
id=
"searchByName"
value=
"name"
/>
<
label
className=
"form-check-label"
htmlFor=
"searchByName"
>
Name
</
label
>
</
div
>
<
div
className=
"form-check form-check-inline"
>
<
input
className=
"form-check-input"
type=
"radio"
name=
"inlineRadioOptions"
checked=
{
this
.
state
.
searchBy
===
"sku"
}
onChange=
{
()
=>
this
.
handleRadioButton
(
"sku"
)
}
id=
"searchBySku"
value=
"sku"
/>
<
label
className=
"form-check-label"
htmlFor=
"searchBySKU"
>
Sku
</
label
>
</
div
>
<
button
className=
"btn btn-light"
type=
"submit"
>
GO
</
button
>
</
form
>
<
Link
to=
{
{
pathname
:
'/searchResults'
,
state
:
{
results
:
this
.
state
.
results
}
}
}
/>
</
div
>
);
}
}
export
default
withRouter
(
Search
);
\ No newline at end of file
src/component/SearchResults.jsx
0 → 100644
View file @
734ea5af
import
React
from
"react"
;
import
Product
from
"./Product.jsx"
;
import
{
Col
,
Container
,
Row
}
from
"react-bootstrap"
;
import
"./../styles/ProductGrid.css"
;
export
default
class
SearchResults
extends
React
.
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
results
:
this
.
props
.
history
.
location
.
state
.
results
}
}
render
(){
return
(
<
div
>
<
h1
id=
"title"
className=
"text-center"
>
Search Results
</
h1
>
<
Container
id=
"prod-grid"
className=
"mt-3"
>
<
Row
xs=
{
1
}
sm=
{
2
}
md=
{
3
}
lg=
{
4
}
>
{
this
.
state
.
results
.
length
>
0
?
this
.
state
.
results
.
map
((
product
)
=>
{
return
(
<
Col
key=
{
product
.
sku
}
>
<
Product
product=
{
product
}
/>
</
Col
>
);
})
:
<
Col
>
<
p
>
Unable to find any matching products.
</
p
>
<
/
Col
>
}
</
Row
>
</
Container
>
</
div
>
);
}
}
\ No newline at end of file
src/styles/Search.css
0 → 100644
View file @
734ea5af
.form-check-label
{
color
:
rgba
(
255
,
255
,
255
,
0.55
)
}
.form-check.form-check-inline
{
margin-top
:
0.35rem
;
}
\ 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