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
b27449cb
Commit
b27449cb
authored
May 10, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-12] Got search by name working
parent
89b7e0ed
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
13 deletions
+10
-13
apiRequests.js
src/actions/apiRequests.js
+3
-3
Main.jsx
src/component/Main.jsx
+1
-1
Search.jsx
src/component/Search.jsx
+5
-8
SearchResults.jsx
src/component/SearchResults.jsx
+1
-1
No files found.
src/actions/apiRequests.js
View file @
b27449cb
...
@@ -10,9 +10,9 @@ export const getAllProducts = async data => {
...
@@ -10,9 +10,9 @@ export const getAllProducts = async data => {
export
const
getFilteredProducts
=
async
(
searchTerm
)
=>
{
export
const
getFilteredProducts
=
async
(
searchTerm
)
=>
{
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
const
res
=
await
axios
.
get
(
`
${
Config
.
inventoryUrl
}
`
);
return
res
.
data
.
filter
(
product
=>
{
return
res
.
data
.
filter
(
product
=>
{
const
productName
=
product
.
n
ame
.
toLowerCase
();
const
productName
=
product
.
productN
ame
.
toLowerCase
();
console
.
log
(
"Search Term: "
+
searchTerm
);
console
.
log
(
"Search Term: "
+
searchTerm
);
console
.
log
(
"Found Product Name: "
+
productName
.
includes
(
searchTerm
));
console
.
log
(
"Found Product Name: "
+
productName
.
includes
(
searchTerm
.
toLowerCase
()
));
return
productName
.
includes
(
searchTerm
);
return
productName
.
includes
(
searchTerm
.
toLowerCase
()
);
});
});
}
}
\ No newline at end of file
src/component/Main.jsx
View file @
b27449cb
...
@@ -22,7 +22,7 @@ export default function Main() {
...
@@ -22,7 +22,7 @@ export default function Main() {
return
(
return
(
<
div
>
<
div
>
<
Switch
>
<
Switch
>
<
AuthRoute
path=
"/searchResults"
><
SearchResults
/></
AuthRoute
>
<
AuthRoute
path=
"/searchResults"
component=
{
SearchResults
}
/
>
<
AuthRoute
exact
path=
"/products/new"
>
<
AuthRoute
exact
path=
"/products/new"
>
<
ProductForm
method=
"POST"
/>
<
ProductForm
method=
"POST"
/>
</
AuthRoute
>
</
AuthRoute
>
...
...
src/component/Search.jsx
View file @
b27449cb
import
React
from
'react'
;
import
React
from
'react'
;
import
{
Redirect
,
withRouter
}
from
"react-router-dom"
;
import
{
withRouter
,
Redirect
}
from
"react-router-dom"
;
import
{
getFilteredProducts
}
from
'../actions/apiRequests'
;
import
{
getFilteredProducts
}
from
'../actions/apiRequests'
;
class
Search
extends
React
.
Component
{
class
Search
extends
React
.
Component
{
...
@@ -19,14 +19,13 @@ class Search extends React.Component {
...
@@ -19,14 +19,13 @@ class Search extends React.Component {
}
}
async
submit
(
event
){
async
submit
(
event
){
console
.
log
(
this
.
state
.
searchTerm
);
event
.
preventDefault
(
);
const
data
=
await
getFilteredProducts
(
this
.
state
.
searchTerm
)
const
data
=
await
getFilteredProducts
(
this
.
state
.
searchTerm
)
.
then
(
res
=>
{
.
then
(
res
=>
{
this
.
setState
({
result
:
res
.
data
},
()
=>
{
this
.
setState
({
results
:
res
});
this
.
props
.
history
.
push
(
"/searchResults"
);
});
})
})
.
catch
(
err
=>
console
.
log
(
err
));
.
catch
(
err
=>
console
.
log
(
err
));
this
.
props
.
history
.
push
(
"/searchResults"
,
this
.
state
);
}
}
//Need to search by name or SKU
//Need to search by name or SKU
...
@@ -38,18 +37,16 @@ class Search extends React.Component {
...
@@ -38,18 +37,16 @@ class Search extends React.Component {
type=
"search"
type=
"search"
className=
"form-control me-2"
className=
"form-control me-2"
placeholder=
"Search for item..."
placeholder=
"Search for item..."
onChange=
{
this
.
changeTerm
}
onChange=
{
event
=>
this
.
changeTerm
(
event
)
}
/>
/>
<
button
className=
"btn btn-light"
type=
"submit"
>
<
button
className=
"btn btn-light"
type=
"submit"
>
GO
GO
</
button
>
</
button
>
</
form
>
</
form
>
{
/* {
<
Redirect
to=
{
{
<
Redirect
to=
{
{
pathname
:
'/searchResults'
,
pathname
:
'/searchResults'
,
state
:
{
results
:
this
.
state
.
results
}
state
:
{
results
:
this
.
state
.
results
}
}
}
/>
}
}
/>
} */
}
</
div
>
</
div
>
);
);
}
}
...
...
src/component/SearchResults.jsx
View file @
b27449cb
...
@@ -7,7 +7,7 @@ export default class SearchResults extends React.Component{
...
@@ -7,7 +7,7 @@ export default class SearchResults extends React.Component{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
this
.
state
=
{
this
.
state
=
{
results
:
[]
results
:
this
.
props
.
history
.
location
.
state
.
results
}
}
}
}
...
...
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