Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mernStack
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
Venkaiah Naidu Singamchetty
mernStack
Commits
8ff8f226
Commit
8ff8f226
authored
Feb 19, 2024
by
Venkaiah Naidu Singamchetty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
navbar updated'
parent
15d7fa43
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
32 deletions
+78
-32
server.js
server.js
+9
-8
Hero.tsx
src/components/Banner/Hero.tsx
+2
-2
Login.tsx
src/components/Login/Login.tsx
+1
-1
NavButtons.tsx
src/components/Navbar/NavButtons.tsx
+30
-0
Navbar.tsx
src/components/Navbar/Navbar.tsx
+13
-15
Product.tsx
src/components/catelog/Product.tsx
+17
-2
Products.tsx
src/components/catelog/Products.tsx
+2
-1
updatecartSlice.ts
src/reduxstore/updatecartSlice.ts
+2
-1
userDetailsslice.ts
src/reduxstore/userDetailsslice.ts
+2
-2
No files found.
server.js
View file @
8ff8f226
...
@@ -119,12 +119,13 @@ app.get('/cartItems/:userid', (req, res) => {
...
@@ -119,12 +119,13 @@ app.get('/cartItems/:userid', (req, res) => {
app
.
post
(
'/updateCartItems/:userid'
,
(
req
,
res
)
=>
{
app
.
post
(
'/updateCartItems/:userid'
,
(
req
,
res
)
=>
{
const
userid
=
req
.
params
.
userid
const
userid
=
req
.
params
.
userid
const
newCartItems
=
req
.
body
const
newCartItems
=
req
.
body
.
ObjectId
if
(
isNaN
(
userid
)){
console
.
log
(
req
.
body
,
userid
)
db
.
collection
(
'cartitems'
).
updateOne
({
userId
:
userid
},{
$set
:{
cartItems
:
newCartItems
}})
// if(isNaN(userid)){
.
then
(
result
=>
{
res
.
send
(
result
).
status
(
200
)
})
// db.collection('cartitems').updateOne({userId: userid},{$set:{cartItems:[newCartItems]}})
.
catch
(
error
=>
res
.
status
(
500
).
send
(
error
))
// .then(result => { res.send(result).status(200) })
}
else
{
// .catch(error => res.status(500).send(error))
res
.
status
(
500
).
json
({
error
:
'Invalid UserId'
})
// } else {
}
// res.status(500).json({ error: 'Invalid UserId' })
// }
})
})
\ No newline at end of file
src/components/Banner/Hero.tsx
View file @
8ff8f226
...
@@ -11,7 +11,7 @@ const Hero = () => {
...
@@ -11,7 +11,7 @@ const Hero = () => {
<
h2
>
NEW ARRIVALS ONLY
</
h2
>
<
h2
>
NEW ARRIVALS ONLY
</
h2
>
<
div
>
<
div
>
<
div
className=
'hand-hand-icon'
>
<
div
className=
'hand-hand-icon'
>
<
p
>
n
ew
</
p
>
<
p
>
N
ew
</
p
>
<
img
src=
{
hand_icon
}
alt=
''
/>
<
img
src=
{
hand_icon
}
alt=
''
/>
</
div
>
</
div
>
<
p
>
Collections
</
p
>
<
p
>
Collections
</
p
>
...
@@ -24,7 +24,7 @@ const Hero = () => {
...
@@ -24,7 +24,7 @@ const Hero = () => {
</
div
>
</
div
>
<
div
className=
'hero-right'
>
<
div
className=
'hero-right'
>
<
img
src=
{
hero_image
}
alt=
""
/>
<
img
src=
{
hero_image
}
alt=
""
className=
'h-100'
/>
</
div
>
</
div
>
...
...
src/components/Login/Login.tsx
View file @
8ff8f226
...
@@ -78,7 +78,7 @@ const Login: React.FC = memo(() => {
...
@@ -78,7 +78,7 @@ const Login: React.FC = memo(() => {
<
button
type=
"submit"
>
Login
</
button
>
<
button
type=
"submit"
>
Login
</
button
>
</
form
>
</
form
>
<
p
className=
'loginsignup-login'
>
<
p
className=
'loginsignup-login'
>
<
span
>
If new user please
<
Link
to=
"/register"
>
Register
</
Link
></
span
>
<
span
>
New user
<
Link
to=
"/register"
>
Register
</
Link
></
span
>
</
p
>
</
p
>
</
div
>
</
div
>
...
...
src/components/Navbar/NavButtons.tsx
0 → 100644
View file @
8ff8f226
import
React
,
{
memo
}
from
'react'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
RootState
}
from
'../../reduxstore/store'
;
import
{
Link
}
from
'react-router-dom'
;
type
NavButtonsProps
=
{
handleLogout
:
()
=>
void
;
}
const
NavButtons
=
memo
((
props
:
NavButtonsProps
)
=>
{
const
user
=
useSelector
((
state
:
RootState
)
=>
state
.
userDetails
.
userDetails
);
return
(
<
div
>
{
user
&&
(
Object
.
keys
(
user
).
length
===
0
&&
user
.
constructor
===
Object
)
?(
<
div
className=
'nav-login-cart'
>
<
Link
to=
"/login"
><
button
>
Login
</
button
></
Link
>
<
Link
to=
"/register"
>
<
button
>
Register
</
button
></
Link
>
</
div
>
):
(
<
Link
to=
"/"
>
<
button
className=
'btn btn-danger'
onClick=
{
props
.
handleLogout
}
>
Logout
</
button
>
</
Link
>
)
}
</
div
>
);
});
export
default
NavButtons
;
\ No newline at end of file
src/components/Navbar/Navbar.tsx
View file @
8ff8f226
import
React
,
{
useState
}
from
'react'
;
import
React
,
{
use
Effect
,
use
State
}
from
'react'
;
import
'./Navbar.css'
import
'./Navbar.css'
import
logo
from
'./logo.png'
import
logo
from
'./logo.png'
import
{
Link
}
from
'react-router-dom'
;
import
{
Link
}
from
'react-router-dom'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
RootState
}
from
'../../reduxstore/store'
;
import
{
loginUser
,
logoutUser
}
from
'../../reduxstore/userDetailsslice'
;
import
NavButtons
from
'./NavButtons'
;
const
Navbar
=
()
=>
{
const
Navbar
=
()
=>
{
// const [menu,setMenu]=useState("Shop")
const
user
=
useSelector
((
state
:
RootState
)
=>
state
.
userDetails
.
userDetails
)
const
dispatch
=
useDispatch
()
const
handleLogout
=
()
=>
{
dispatch
(
logoutUser
());
}
return
(
return
(
<
div
className=
'navbar'
>
<
div
className=
'navbar'
>
<
div
className=
'nav-logo'
>
<
div
className=
'nav-logo'
>
<
img
src=
{
logo
}
alt=
""
/>
<
img
src=
{
logo
}
alt=
""
/>
<
p
>
SHOPPER
</
p
>
<
p
>
SHOPPER
</
p
>
</
div
>
</
div
>
<
NavButtons
handleLogout=
{
handleLogout
}
/>
{
/* <ul className="nav-menu">
<li onClick={()=>setMenu("Shop")} ><Link style={{textDecoration:"none"}} to="/">Shop</Link> {menu==="Shop"?<hr/>:<></>}</li>
<li onClick={()=>setMenu("mens")} ><Link style={{textDecoration:"none"}} to="/mens">Men</Link> {menu==="mens"?<hr/>:<></>}</li>
<li onClick={()=>setMenu("Womens")}><Link style={{textDecoration:"none"}} to="/Womens">Women</Link> {menu==="Womens"?<hr/>:<></>}</li>
<li onClick={()=>setMenu("kids")}><Link style={{textDecoration:"none"}} to="/Kids">Kids</Link> {menu==="kids"?<hr/>:<></>}</li>
</ul> */
}
<
div
className=
'nav-login-cart'
>
<
Link
to=
"/login"
><
button
>
Login
</
button
>
</
Link
>
<
Link
to=
"/register"
><
button
>
Register
</
button
>
</
Link
>
</
div
>
</
div
>
</
div
>
);
);
...
...
src/components/catelog/Product.tsx
View file @
8ff8f226
import
React
,
{
memo
}
from
'react'
;
import
React
,
{
memo
}
from
'react'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
updateCartItems
}
from
'../../reduxstore/updatecartSlice'
;
import
{
RootState
}
from
'../../reduxstore/store'
;
type
ProductType
=
{
type
ProductType
=
{
_id
:
string
_id
:
string
...
@@ -15,9 +18,21 @@ type ProductType = {
...
@@ -15,9 +18,21 @@ type ProductType = {
type
ProductPropsType
=
{
type
ProductPropsType
=
{
product
:
ProductType
|
null
product
:
ProductType
|
null
}
}
const
Product
=
memo
((
props
:
ProductPropsType
)
=>
{
const
Product
=
memo
((
props
:
ProductPropsType
)
=>
{
console
.
log
(
props
.
product
)
const
user
=
useSelector
((
state
:
RootState
)
=>
state
.
userDetails
.
userDetails
)
const
dispatch
=
useDispatch
()
const
{
id
,
title
,
description
,
category
,
image
,
rating
:{
rate
,
count
},
qty
,
price
}:
ProductType
=
props
.
product
!
;
const
{
id
,
title
,
description
,
category
,
image
,
rating
:{
rate
,
count
},
qty
,
price
}:
ProductType
=
props
.
product
!
;
const
handleAddtoCart
=
()
=>
{
if
(
Object
.
keys
(
user
).
length
!=
0
){
dispatch
(
updateCartItems
({
userId
:
user
.
userId
,
updateCartItems
:
props
.
product
}))
}
}
return
(<
div
className=
'col-lg-4 col-md-2 col-sm-1 my-2'
style=
{
{
width
:
"300px"
}
}
>
return
(<
div
className=
'col-lg-4 col-md-2 col-sm-1 my-2'
style=
{
{
width
:
"300px"
}
}
>
<
div
className=
"card"
>
<
div
className=
"card"
>
<
img
src=
{
image
}
className=
"img-fluid"
style=
{
{
width
:
"100%"
,
height
:
"200px"
}
}
alt=
"..."
/>
<
img
src=
{
image
}
className=
"img-fluid"
style=
{
{
width
:
"100%"
,
height
:
"200px"
}
}
alt=
"..."
/>
...
@@ -31,7 +46,7 @@ const Product = memo((props: ProductPropsType) => {
...
@@ -31,7 +46,7 @@ const Product = memo((props: ProductPropsType) => {
<
li
className=
"list-group-item"
>
Price :
{
price
}
</
li
>
<
li
className=
"list-group-item"
>
Price :
{
price
}
</
li
>
</
ul
>
</
ul
>
<
div
className=
"card-body"
>
<
div
className=
"card-body"
>
<
button
className=
'btn btn-danger w-100'
>
Add To Cart
</
button
>
<
button
className=
'btn btn-danger w-100'
onClick=
{
handleAddtoCart
}
>
Add To Cart
</
button
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
src/components/catelog/Products.tsx
View file @
8ff8f226
...
@@ -11,7 +11,7 @@ const Products = memo(() => {
...
@@ -11,7 +11,7 @@ const Products = memo(() => {
const
dispatch
=
useDispatch
()
const
dispatch
=
useDispatch
()
const
products
=
useSelector
((
state
:
RootState
)
=>
state
.
products
);
const
products
=
useSelector
((
state
:
RootState
)
=>
state
.
products
);
const
user
=
useSelector
((
state
:
RootState
)
=>
state
.
userDetails
.
userDetails
)
const
user
=
useSelector
((
state
:
RootState
)
=>
state
.
userDetails
.
userDetails
)
console
.
log
(
products
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
user
!==
null
)
{
if
(
user
!==
null
)
{
const
isEmpty
=
Object
.
keys
(
user
).
length
===
0
&&
user
.
constructor
===
Object
;
const
isEmpty
=
Object
.
keys
(
user
).
length
===
0
&&
user
.
constructor
===
Object
;
...
@@ -19,6 +19,7 @@ const Products = memo(() => {
...
@@ -19,6 +19,7 @@ const Products = memo(() => {
navigate
(
'/login'
);
navigate
(
'/login'
);
}
else
{
}
else
{
dispatch
(
fetchProducts
());
dispatch
(
fetchProducts
());
console
.
log
(
user
)
}
}
}
else
{
}
else
{
navigate
(
'/login'
);
navigate
(
'/login'
);
...
...
src/reduxstore/updatecartSlice.ts
View file @
8ff8f226
...
@@ -9,7 +9,7 @@ type updateCartStateType = {
...
@@ -9,7 +9,7 @@ type updateCartStateType = {
type
CartItemType
=
{
type
CartItemType
=
{
userId
:
string
,
userId
:
string
,
updateCartlist
:
any
[]
updateCartlist
:
any
}
}
const
initialState
:
updateCartStateType
=
{
const
initialState
:
updateCartStateType
=
{
...
@@ -19,6 +19,7 @@ const initialState: updateCartStateType = {
...
@@ -19,6 +19,7 @@ const initialState: updateCartStateType = {
};
};
export
const
updateCartItems
:
any
=
createAsyncThunk
(
'updatecart/updateCartItems'
,
async
({
userId
,
updateCartlist
}:
CartItemType
)
=>
{
export
const
updateCartItems
:
any
=
createAsyncThunk
(
'updatecart/updateCartItems'
,
async
({
userId
,
updateCartlist
}:
CartItemType
)
=>
{
console
.
log
(
updateCartlist
)
return
await
axios
.
post
(
`http://localhost:4000/updateCartItems/
${
userId
}
`
,
updateCartlist
)
return
await
axios
.
post
(
`http://localhost:4000/updateCartItems/
${
userId
}
`
,
updateCartlist
)
.
then
(
response
=>
response
.
data
);
.
then
(
response
=>
response
.
data
);
});
});
...
...
src/reduxstore/userDetailsslice.ts
View file @
8ff8f226
import
{
createSlice
}
from
"@reduxjs/toolkit"
import
{
createSlice
}
from
"@reduxjs/toolkit"
export
type
UserDetailsType
=
{
export
type
UserDetailsType
=
{
userDetails
:
{}
|
null
userDetails
:
any
|
null
}
}
const
initialState
:
UserDetailsType
=
{
const
initialState
:
UserDetailsType
=
{
userDetails
:{},
userDetails
:{},
...
@@ -14,7 +14,7 @@ const userDetailsSlice=createSlice({
...
@@ -14,7 +14,7 @@ const userDetailsSlice=createSlice({
state
.
userDetails
=
action
.
payload
state
.
userDetails
=
action
.
payload
},
},
logoutUser
:(
state
)
=>
{
logoutUser
:(
state
)
=>
{
state
.
userDetails
=
[]
state
.
userDetails
=
{}
},
},
},
},
})
})
...
...
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