Skip to content

Commit 9a7f78d

Browse files
My profile page added/fettchLoogedInUser API created for full details of user
1 parent f6bcaec commit 9a7f78d

File tree

11 files changed

+329
-104
lines changed

11 files changed

+329
-104
lines changed

data.json

Lines changed: 166 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,15 +1915,6 @@
19151915
"email": "test@123.com",
19161916
"password": "Murtaza123",
19171917
"addresses": [
1918-
{
1919-
"name": "Murtaza Tankiwala",
1920-
"email": "murtazashabbir14@gmail.com",
1921-
"phone": "07869558609",
1922-
"street": "1109 - Noorani Nagar - Near M.Shabbir bhai Khergonewala",
1923-
"city": "Indore",
1924-
"state": "Madhya Pradesh",
1925-
"pinCode": "452002"
1926-
},
19271918
{
19281919
"name": "Murtaza Tankiwala",
19291920
"email": "murtazashabbir14@gmail.com",
@@ -1952,70 +1943,7 @@
19521943
]
19531944
}
19541945
],
1955-
"cart": [
1956-
{
1957-
"id": "efca",
1958-
"title": "Eyeshadow Palette with Mirror",
1959-
"description": "The Eyeshadow Palette with Mirror offers a versatile range of eyeshadow shades for creating stunning eye looks. With a built-in mirror, it's convenient for on-the-go makeup application.",
1960-
"category": "beauty",
1961-
"price": 19.99,
1962-
"discountPercentage": 5.5,
1963-
"rating": 3.28,
1964-
"stock": 44,
1965-
"tags": [
1966-
"beauty",
1967-
"eyeshadow"
1968-
],
1969-
"brand": "Glamour Beauty",
1970-
"sku": "MVCFH27F",
1971-
"weight": 3,
1972-
"dimensions": {
1973-
"width": 12.42,
1974-
"height": 8.63,
1975-
"depth": 29.13
1976-
},
1977-
"warrantyInformation": "1 year warranty",
1978-
"shippingInformation": "Ships in 2 weeks",
1979-
"availabilityStatus": "In Stock",
1980-
"reviews": [
1981-
{
1982-
"rating": 4,
1983-
"comment": "Very satisfied!",
1984-
"date": "2024-05-23T08:56:21.618Z",
1985-
"reviewerName": "Liam Garcia",
1986-
"reviewerEmail": "liam.garcia@x.dummyjson.com"
1987-
},
1988-
{
1989-
"rating": 1,
1990-
"comment": "Very disappointed!",
1991-
"date": "2024-05-23T08:56:21.618Z",
1992-
"reviewerName": "Nora Russell",
1993-
"reviewerEmail": "nora.russell@x.dummyjson.com"
1994-
},
1995-
{
1996-
"rating": 5,
1997-
"comment": "Highly impressed!",
1998-
"date": "2024-05-23T08:56:21.618Z",
1999-
"reviewerName": "Elena Baker",
2000-
"reviewerEmail": "elena.baker@x.dummyjson.com"
2001-
}
2002-
],
2003-
"returnPolicy": "30 days return policy",
2004-
"minimumOrderQuantity": 32,
2005-
"meta": {
2006-
"createdAt": "2024-05-23T08:56:21.618Z",
2007-
"updatedAt": "2024-05-23T08:56:21.618Z",
2008-
"barcode": "2817839095220",
2009-
"qrCode": "https://dummyjson.com/public/qr-code.png"
2010-
},
2011-
"images": [
2012-
"https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/1.png"
2013-
],
2014-
"thumbnail": "https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/thumbnail.png",
2015-
"quantity": 1,
2016-
"user": "cb1b"
2017-
}
2018-
],
1946+
"cart": [],
20191947
"orders": [
20201948
{
20211949
"id": "d496",
@@ -2341,6 +2269,171 @@
23412269
},
23422270
"paymentMethod": "card",
23432271
"status": "pending"
2272+
},
2273+
{
2274+
"id": "6cf3",
2275+
"items": [
2276+
{
2277+
"id": "efca",
2278+
"title": "Eyeshadow Palette with Mirror",
2279+
"description": "The Eyeshadow Palette with Mirror offers a versatile range of eyeshadow shades for creating stunning eye looks. With a built-in mirror, it's convenient for on-the-go makeup application.",
2280+
"category": "beauty",
2281+
"price": 19.99,
2282+
"discountPercentage": 5.5,
2283+
"rating": 3.28,
2284+
"stock": 44,
2285+
"tags": [
2286+
"beauty",
2287+
"eyeshadow"
2288+
],
2289+
"brand": "Glamour Beauty",
2290+
"sku": "MVCFH27F",
2291+
"weight": 3,
2292+
"dimensions": {
2293+
"width": 12.42,
2294+
"height": 8.63,
2295+
"depth": 29.13
2296+
},
2297+
"warrantyInformation": "1 year warranty",
2298+
"shippingInformation": "Ships in 2 weeks",
2299+
"availabilityStatus": "In Stock",
2300+
"reviews": [
2301+
{
2302+
"rating": 4,
2303+
"comment": "Very satisfied!",
2304+
"date": "2024-05-23T08:56:21.618Z",
2305+
"reviewerName": "Liam Garcia",
2306+
"reviewerEmail": "liam.garcia@x.dummyjson.com"
2307+
},
2308+
{
2309+
"rating": 1,
2310+
"comment": "Very disappointed!",
2311+
"date": "2024-05-23T08:56:21.618Z",
2312+
"reviewerName": "Nora Russell",
2313+
"reviewerEmail": "nora.russell@x.dummyjson.com"
2314+
},
2315+
{
2316+
"rating": 5,
2317+
"comment": "Highly impressed!",
2318+
"date": "2024-05-23T08:56:21.618Z",
2319+
"reviewerName": "Elena Baker",
2320+
"reviewerEmail": "elena.baker@x.dummyjson.com"
2321+
}
2322+
],
2323+
"returnPolicy": "30 days return policy",
2324+
"minimumOrderQuantity": 32,
2325+
"meta": {
2326+
"createdAt": "2024-05-23T08:56:21.618Z",
2327+
"updatedAt": "2024-05-23T08:56:21.618Z",
2328+
"barcode": "2817839095220",
2329+
"qrCode": "https://dummyjson.com/public/qr-code.png"
2330+
},
2331+
"images": [
2332+
"https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/1.png"
2333+
],
2334+
"thumbnail": "https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/thumbnail.png",
2335+
"quantity": 2,
2336+
"user": "cb1b"
2337+
},
2338+
{
2339+
"id": "f678",
2340+
"title": "Eggs",
2341+
"description": "Fresh eggs, a versatile ingredient for baking, cooking, or breakfast.",
2342+
"category": "groceries",
2343+
"price": 2.99,
2344+
"discountPercentage": 5.8,
2345+
"rating": 4.46,
2346+
"stock": 10,
2347+
"tags": [
2348+
"dairy"
2349+
],
2350+
"sku": "YA617RI7",
2351+
"weight": 4,
2352+
"dimensions": {
2353+
"width": 12.3,
2354+
"height": 10.99,
2355+
"depth": 15.53
2356+
},
2357+
"warrantyInformation": "3 year warranty",
2358+
"shippingInformation": "Ships overnight",
2359+
"availabilityStatus": "In Stock",
2360+
"reviews": [
2361+
{
2362+
"rating": 2,
2363+
"comment": "Very unhappy with my purchase!",
2364+
"date": "2024-05-23T08:56:21.620Z",
2365+
"reviewerName": "Mateo Perez",
2366+
"reviewerEmail": "mateo.perez@x.dummyjson.com"
2367+
},
2368+
{
2369+
"rating": 4,
2370+
"comment": "Very happy with my purchase!",
2371+
"date": "2024-05-23T08:56:21.620Z",
2372+
"reviewerName": "Cameron Perez",
2373+
"reviewerEmail": "cameron.perez@x.dummyjson.com"
2374+
},
2375+
{
2376+
"rating": 5,
2377+
"comment": "Very happy with my purchase!",
2378+
"date": "2024-05-23T08:56:21.620Z",
2379+
"reviewerName": "Aurora Barnes",
2380+
"reviewerEmail": "aurora.barnes@x.dummyjson.com"
2381+
}
2382+
],
2383+
"returnPolicy": "30 days return policy",
2384+
"minimumOrderQuantity": 43,
2385+
"meta": {
2386+
"createdAt": "2024-05-23T08:56:21.620Z",
2387+
"updatedAt": "2024-05-23T08:56:21.620Z",
2388+
"barcode": "7095702028776",
2389+
"qrCode": "https://dummyjson.com/public/qr-code.png"
2390+
},
2391+
"images": [
2392+
"https://cdn.dummyjson.com/products/images/groceries/Eggs/1.png"
2393+
],
2394+
"thumbnail": "https://cdn.dummyjson.com/products/images/groceries/Eggs/thumbnail.png",
2395+
"quantity": 4,
2396+
"user": "cb1b"
2397+
}
2398+
],
2399+
"totalAmount": 51.94,
2400+
"totalItems": 6,
2401+
"user": {
2402+
"id": "cb1b",
2403+
"email": "test@123.com",
2404+
"password": "Murtaza123",
2405+
"addresses": [
2406+
{
2407+
"name": "Murtaza Tankiwala",
2408+
"email": "murtazashabbir14@gmail.com",
2409+
"phone": "07869558609",
2410+
"street": "1109 - Noorani Nagar - Near M.Shabbir bhai Khergonewala",
2411+
"city": "Indore",
2412+
"state": "Madhya Pradesh",
2413+
"pinCode": "452002"
2414+
},
2415+
{
2416+
"name": "Murtaza Tankiwala",
2417+
"email": "murtazashabbir14@gmail.com",
2418+
"phone": "07869558609",
2419+
"street": "1109 - Noorani Nagar - Near M.Shabbir bhai Khergonewala",
2420+
"city": "Indore",
2421+
"state": "Madhya Pradesh",
2422+
"pinCode": "452002"
2423+
}
2424+
]
2425+
},
2426+
"selectedAddress": {
2427+
"name": "Murtaza Tankiwala",
2428+
"email": "murtazashabbir14@gmail.com",
2429+
"phone": "07869558609",
2430+
"street": "1109 - Noorani Nagar - Near M.Shabbir bhai Khergonewala",
2431+
"city": "Indore",
2432+
"state": "Madhya Pradesh",
2433+
"pinCode": "452002"
2434+
},
2435+
"paymentMethod": "card",
2436+
"status": "pending"
23442437
}
23452438
]
23462439
}

src/App.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { fetchItemsByUserIdAsync } from "./features/cart/cartSlice";
2222
import PageNotFound from "./pages/404";
2323
import OrderSuccessPage from "./pages/OrderSuccessPage";
2424
import UserOrderPage from "./pages/UserOrderPage";
25-
import UserOrders from "./features/user/components/UserOrders";
25+
import UserProfilePage from "./pages/UserProfilePage";
26+
import { fetchLoggedInUserAsync } from "./features/user/userSlice";
2627
const router = createBrowserRouter([
2728
{
2829
path: "/",
@@ -73,6 +74,10 @@ const router = createBrowserRouter([
7374
path: "/orders",
7475
element: <UserOrderPage></UserOrderPage>,
7576
},
77+
{
78+
path: "/profile",
79+
element: <UserProfilePage></UserProfilePage>,
80+
},
7681
{
7782
path: "*",
7883
element: <PageNotFound></PageNotFound>,
@@ -86,6 +91,7 @@ function App() {
8691
useEffect(() => {
8792
if (user) {
8893
dispatch(fetchItemsByUserIdAsync(user.id));
94+
dispatch(fetchLoggedInUserAsync(user.id));
8995
}
9096
}, [dispatch, user]);
9197
return (

src/features/auth/authAPI.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,3 @@ export function checkUser(loginInfo) {
3131
// TODO:on server it will only return some info of user (not password)
3232
});
3333
}
34-
// update user address from checkout page....
35-
export function updateUser(update) {
36-
return new Promise(async (resolve) => {
37-
const response = await fetch("http://localhost:8080/users/" + update.id, {
38-
// to get the particular user and address in it
39-
method: "PATCH",
40-
body: JSON.stringify(update),
41-
headers: { "content-type": "application/json" },
42-
});
43-
const data = await response.json();
44-
// TODO:on server it will only return some info of user (not password)
45-
resolve({ data });
46-
});
47-
}

src/features/auth/authSlice.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
2-
import { checkUser, createUser, updateUser } from "./authAPI";
2+
import { checkUser, createUser } from "./authAPI";
3+
import { updateUser } from "../user/userAPI";
34

45
const initialState = {
56
loggedInUser: null,

src/features/navbar/Navbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const navigation = [
2020
{ name: "Team", href: "#", current: false },
2121
];
2222
const userNavigation = [
23-
{ name: "Your Profile", link: "/profile" },
23+
{ name: "My Profile", link: "/profile" },
2424
{ name: "My Orders", link: "/orders" },
2525
{ name: "Sign out", link: "/login" },
2626
];

src/features/user/UserAPI.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@ export function fetchLoggedInUserOrders(userId) {
88
resolve({ data });
99
});
1010
}
11+
export function fetchLoggedInUser(userId) {
12+
return new Promise(async (resolve) => {
13+
const response = await fetch("http://localhost:8080/users/" + userId);
14+
const data = await response.json();
15+
16+
resolve({ data });
17+
});
18+
}
19+
// update user address from checkout page....
20+
export function updateUser(update) {
21+
return new Promise(async (resolve) => {
22+
const response = await fetch("http://localhost:8080/users/" + update.id, {
23+
// to get the particular user and address in it
24+
method: "PATCH",
25+
body: JSON.stringify(update),
26+
headers: { "content-type": "application/json" },
27+
});
28+
const data = await response.json();
29+
// TODO:on server it will only return some info of user (not password)
30+
resolve({ data });
31+
});
32+
}

src/features/user/components/UserOrders.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React, { useEffect } from "react";
22
import { useSelector, useDispatch } from "react-redux";
3-
import { fetchLoggedInUserOrderAsync, selectUserOrders } from "../userSlice";
4-
import { selectLoggedInUser } from "../../auth/authSlice";
3+
import {
4+
fetchLoggedInUserOrderAsync,
5+
selectUserInfo,
6+
selectUserOrders,
7+
} from "../userSlice";
58

69
export default function UserOrders() {
7-
const user = useSelector(selectLoggedInUser);
10+
const user = useSelector(selectUserInfo);
811
const dispatch = useDispatch();
912
const orders = useSelector(selectUserOrders);
1013

0 commit comments

Comments
 (0)