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
b15d2820
Commit
b15d2820
authored
May 14, 2021
by
Ben Anderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated routing
parent
d4bee319
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22172 additions
and
1006 deletions
+22172
-1006
package-lock.json
package-lock.json
+22139
-973
App.js
src/App.js
+10
-14
AuthRoute.jsx
src/component/AuthRoute.jsx
+10
-13
Main.jsx
src/component/Main.jsx
+1
-1
ProductForm.jsx
src/component/ProductForm.jsx
+6
-4
ProductRow.jsx
src/component/ProductRow.jsx
+6
-1
No files found.
package-lock.json
View file @
b15d2820
This diff is collapsed.
Click to expand it.
src/App.js
View file @
b15d2820
...
...
@@ -4,35 +4,31 @@ import Main from "./component/Main";
import
AuthRoute
from
"./component/AuthRoute"
;
import
{
Switch
}
from
"react-router"
;
import
Login
from
"./component/Login"
;
import
'semantic-ui-css/semantic.min.css'
import
React
,
{
useState
,
createContext
,
useEffect
}
from
'react'
;
import
"semantic-ui-css/semantic.min.css"
;
import
React
,
{
useState
,
createContext
,
useEffect
}
from
"react"
;
export
const
AuthContext
=
createContext
();
function
App
()
{
const
[
isLoggedIn
,
setIsLoggedIn
]
=
useState
(
false
);
const
[
user
,
setUser
]
=
useState
(
null
);
const
[
isLoggedIn
,
setIsLoggedIn
]
=
useState
(
false
);
const
[
user
,
setUser
]
=
useState
(
null
);
console
.
log
(
user
);
const
state
=
{
user
,
setUser
,
isLoggedIn
,
setIsLoggedIn
}
useEffect
(()
=>
{
localStorage
.
setItem
(
"loggedIn"
,
isLoggedIn
)
setIsLoggedIn
,
};
},
[
isLoggedIn
])
useEffect
(()
=>
{
localStorage
.
setItem
(
"loggedIn"
,
isLoggedIn
);
},
[
isLoggedIn
]);
return
(
<
AuthContext
.
Provider
value
=
{
state
}
>
<
div
>
<
Switch
>
<
AuthRoute
path
=
"/login"
>
<
AuthRoute
exact
path
=
"/login"
>
<
Login
/>
<
/AuthRoute
>
<
AuthRoute
>
...
...
src/component/AuthRoute.jsx
View file @
b15d2820
import
{
useEffect
,
useContext
}
from
"react"
;
import
{
useEffect
,
useContext
}
from
"react"
;
import
React
from
"react"
;
import
{
Redirect
,
Route
}
from
"react-router"
;
import
{
AuthContext
}
from
'../App'
;
export
default
function
AuthRoute
({
children
,
...
rest
})
{
const
{
isLoggedIn
}
=
useContext
(
AuthContext
)
import
{
AuthContext
}
from
"../App"
;
export
default
function
AuthRoute
({
children
,
...
rest
})
{
const
{
isLoggedIn
}
=
useContext
(
AuthContext
);
return
(
<
Route
...
...
@@ -14,14 +12,13 @@ export default function AuthRoute({children, ...rest}) {
render=
{
({
location
})
=>
{
if
(
isLoggedIn
)
{
if
(
location
.
pathname
===
"/login"
)
{
return
<
Redirect
to=
"/"
/>;
}
else
{
return
children
;
}
}
else
if
(
location
.
pathname
!==
"/login"
)
{
return
<
Redirect
to=
"/login"
/>
;
return
<
Redirect
to=
"/
products
"
/>;
}
else
return
children
;
}
else
{
if
(
location
.
pathname
!==
"/login"
)
{
return
<
Redirect
to=
"/login"
/>;
}
else
return
children
;
}
return
children
;
}
}
/>
);
...
...
src/component/Main.jsx
View file @
b15d2820
...
...
@@ -15,7 +15,7 @@ export default function Main() {
<
AuthRoute
exact
path=
"/products/new"
>
<
ProductForm
method=
"POST"
/>
</
AuthRoute
>
<
AuthRoute
exact
path=
"/products/
edit/:productId
"
>
<
AuthRoute
exact
path=
"/products/
:productId/update
"
>
<
ProductForm
method=
"PUT"
/>
</
AuthRoute
>
<
AuthRoute
...
...
src/component/ProductForm.jsx
View file @
b15d2820
import
React
,
{
useEffect
,
useState
}
from
"react"
;
import
{
useHistory
,
useParams
}
from
"react-router"
;
import
emptyProduct
from
"../emptProduct"
;
import
Config
from
'../config'
;
import
Config
from
"../config"
;
const
emptyForm
=
{
...
emptyProduct
,
...
...
@@ -21,7 +21,7 @@ export default function ProductForm(props) {
const
{
productId
}
=
useParams
(
"productId"
);
useEffect
(()
=>
{
fetch
(
`
http://localhost:8080/api/products
/
${
productId
}
/`
).
then
((
res
)
=>
{
fetch
(
`
${
Config
.
inventoryUrl
}
/
${
productId
}
/`
).
then
((
res
)
=>
{
if
(
res
.
ok
)
{
console
.
log
(
res
);
res
.
json
().
then
((
data
)
=>
{
...
...
@@ -40,7 +40,7 @@ export default function ProductForm(props) {
const
validate
=
()
=>
{
setErrors
([]);
const
errs
=
[];
console
.
log
(
form
)
console
.
log
(
form
)
;
if
(
form
.
sku
.
length
<
3
)
{
errs
.
push
(
"SKU must be at least 3 characters"
);
}
...
...
@@ -238,7 +238,9 @@ export default function ProductForm(props) {
className=
"form-control"
id=
"stock"
value=
{
form
.
availableStock
}
onChange=
{
(
e
)
=>
setForm
({
...
form
,
availableStock
:
e
.
target
.
value
})
}
onChange=
{
(
e
)
=>
setForm
({
...
form
,
availableStock
:
e
.
target
.
value
})
}
/>
</
div
>
</
div
>
...
...
src/component/ProductRow.jsx
View file @
b15d2820
import
React
,
{
useState
}
from
"react"
;
import
"./../styles/ProductRow.css"
;
import
{
Modal
,
Button
,
Alert
}
from
"react-bootstrap"
;
import
{
useHistory
}
from
"react-router"
;
export
default
function
ProductRow
({
product
,
handleDelete
})
{
const
[
show
,
setShow
]
=
useState
(
false
);
const
[
showConfirm
,
setShowConfirm
]
=
useState
(
false
);
const
history
=
useHistory
();
const
handleClose
=
()
=>
{
setShow
(
false
);
...
...
@@ -60,7 +62,10 @@ export default function ProductRow({ product, handleDelete }) {
>
Delete product
</
Button
>
<
Button
variant=
"primary"
href=
{
`/products/edit/${product.sku}`
}
>
<
Button
variant=
"primary"
onClick=
{
()
=>
history
.
push
(
`/products/${product.sku}/update`
)
}
>
Edit Product
</
Button
>
...
...
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