Skip to content

Commit 6f0e5a1

Browse files
checkout page functionality (grabing form values) done
1 parent 6300124 commit 6f0e5a1

File tree

7 files changed

+494
-472
lines changed

7 files changed

+494
-472
lines changed

data.json

Lines changed: 60 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,137 +1913,96 @@
19131913
{
19141914
"id": "cb1b",
19151915
"email": "test@123.com",
1916-
"password": "Murtaza123"
1916+
"password": "Murtaza123",
1917+
"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+
},
1927+
{
1928+
"name": "Murtaza Tankiwala",
1929+
"email": "murtazashabbir14@gmail.com",
1930+
"phone": "07869558609",
1931+
"street": "1109 - Noorani Nagar - Near M.Shabbir bhai Khergonewala",
1932+
"city": "Indore",
1933+
"state": "Madhya Pradesh",
1934+
"pinCode": "452002"
1935+
}
1936+
]
19171937
},
19181938
{
19191939
"id": "0afe",
19201940
"email": "test2@gmail.com",
1921-
"password": "Tankiwala123"
1941+
"password": "Tankiwala123",
1942+
"addresses": []
19221943
}
19231944
],
19241945
"cart": [
19251946
{
1926-
"id": "1",
1927-
"title": "Essence Mascara Lash Princess",
1928-
"description": "The Essence Mascara Lash Princess is a popular mascara known for its volumizing and lengthening effects. Achieve dramatic lashes with this long-lasting and cruelty-free formula.",
1929-
"category": "beauty",
1930-
"price": 9.99,
1931-
"discountPercentage": 7.17,
1932-
"rating": 4.94,
1933-
"stock": 5,
1934-
"tags": [
1935-
"beauty",
1936-
"mascara"
1937-
],
1938-
"brand": "Essence",
1939-
"sku": "RCH45Q1A",
1940-
"weight": 2,
1941-
"dimensions": {
1942-
"width": 23.17,
1943-
"height": 14.43,
1944-
"depth": 28.01
1945-
},
1946-
"warrantyInformation": "1 month warranty",
1947-
"shippingInformation": "Ships in 1 month",
1948-
"availabilityStatus": "Low Stock",
1949-
"reviews": [
1950-
{
1951-
"rating": 2,
1952-
"comment": "Very unhappy with my purchase!",
1953-
"date": "2024-05-23T08:56:21.618Z",
1954-
"reviewerName": "John Doe",
1955-
"reviewerEmail": "john.doe@x.dummyjson.com"
1956-
},
1957-
{
1958-
"rating": 2,
1959-
"comment": "Not as described!",
1960-
"date": "2024-05-23T08:56:21.618Z",
1961-
"reviewerName": "Nolan Gonzalez",
1962-
"reviewerEmail": "nolan.gonzalez@x.dummyjson.com"
1963-
},
1964-
{
1965-
"rating": 5,
1966-
"comment": "Very satisfied!",
1967-
"date": "2024-05-23T08:56:21.618Z",
1968-
"reviewerName": "Scarlett Wright",
1969-
"reviewerEmail": "scarlett.wright@x.dummyjson.com"
1970-
}
1971-
],
1972-
"returnPolicy": "30 days return policy",
1973-
"minimumOrderQuantity": 24,
1974-
"meta": {
1975-
"createdAt": "2024-05-23T08:56:21.618Z",
1976-
"updatedAt": "2024-05-23T08:56:21.618Z",
1977-
"barcode": "9164035109868",
1978-
"qrCode": "https://dummyjson.com/public/qr-code.png"
1979-
},
1980-
"images": [
1981-
"https://cdn.dummyjson.com/products/images/beauty/Essence%20Mascara%20Lash%20Princess/1.png"
1982-
],
1983-
"thumbnail": "https://cdn.dummyjson.com/products/images/beauty/Essence%20Mascara%20Lash%20Princess/thumbnail.png",
1984-
"quantity": 1,
1985-
"user": "cb1b"
1986-
},
1987-
{
1988-
"id": "2",
1989-
"title": "Eyeshadow Palette with Mirror",
1990-
"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.",
1947+
"id": "6a4c",
1948+
"title": "Red Lipstick",
1949+
"description": "The Red Lipstick is a classic and bold choice for adding a pop of color to your lips. With a creamy and pigmented formula, it provides a vibrant and long-lasting finish.",
19911950
"category": "beauty",
1992-
"price": 19.99,
1993-
"discountPercentage": 5.5,
1994-
"rating": 3.28,
1995-
"stock": 44,
1951+
"price": 12.99,
1952+
"discountPercentage": 19.03,
1953+
"rating": 2.51,
1954+
"stock": 68,
19961955
"tags": [
19971956
"beauty",
1998-
"eyeshadow"
1957+
"lipstick"
19991958
],
2000-
"brand": "Glamour Beauty",
2001-
"sku": "MVCFH27F",
2002-
"weight": 3,
1959+
"brand": "Chic Cosmetics",
1960+
"sku": "O5IF1NTA",
1961+
"weight": 5,
20031962
"dimensions": {
2004-
"width": 12.42,
2005-
"height": 8.63,
2006-
"depth": 29.13
1963+
"width": 14.37,
1964+
"height": 13.94,
1965+
"depth": 14.6
20071966
},
2008-
"warrantyInformation": "1 year warranty",
1967+
"warrantyInformation": "Lifetime warranty",
20091968
"shippingInformation": "Ships in 2 weeks",
20101969
"availabilityStatus": "In Stock",
20111970
"reviews": [
20121971
{
2013-
"rating": 4,
2014-
"comment": "Very satisfied!",
2015-
"date": "2024-05-23T08:56:21.618Z",
2016-
"reviewerName": "Liam Garcia",
2017-
"reviewerEmail": "liam.garcia@x.dummyjson.com"
1972+
"rating": 5,
1973+
"comment": "Great product!",
1974+
"date": "2024-05-23T08:56:21.619Z",
1975+
"reviewerName": "Leo Rivera",
1976+
"reviewerEmail": "leo.rivera@x.dummyjson.com"
20181977
},
20191978
{
2020-
"rating": 1,
2021-
"comment": "Very disappointed!",
2022-
"date": "2024-05-23T08:56:21.618Z",
2023-
"reviewerName": "Nora Russell",
2024-
"reviewerEmail": "nora.russell@x.dummyjson.com"
1979+
"rating": 4,
1980+
"comment": "Very pleased!",
1981+
"date": "2024-05-23T08:56:21.619Z",
1982+
"reviewerName": "Oscar Powers",
1983+
"reviewerEmail": "oscar.powers@x.dummyjson.com"
20251984
},
20261985
{
20271986
"rating": 5,
2028-
"comment": "Highly impressed!",
2029-
"date": "2024-05-23T08:56:21.618Z",
2030-
"reviewerName": "Elena Baker",
2031-
"reviewerEmail": "elena.baker@x.dummyjson.com"
1987+
"comment": "Very pleased!",
1988+
"date": "2024-05-23T08:56:21.619Z",
1989+
"reviewerName": "Carter Rivera",
1990+
"reviewerEmail": "carter.rivera@x.dummyjson.com"
20321991
}
20331992
],
2034-
"returnPolicy": "30 days return policy",
2035-
"minimumOrderQuantity": 32,
1993+
"returnPolicy": "90 days return policy",
1994+
"minimumOrderQuantity": 6,
20361995
"meta": {
2037-
"createdAt": "2024-05-23T08:56:21.618Z",
2038-
"updatedAt": "2024-05-23T08:56:21.618Z",
2039-
"barcode": "2817839095220",
1996+
"createdAt": "2024-05-23T08:56:21.619Z",
1997+
"updatedAt": "2024-05-23T08:56:21.619Z",
1998+
"barcode": "9444582199406",
20401999
"qrCode": "https://dummyjson.com/public/qr-code.png"
20412000
},
20422001
"images": [
2043-
"https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/1.png"
2002+
"https://cdn.dummyjson.com/products/images/beauty/Red%20Lipstick/1.png"
20442003
],
2045-
"thumbnail": "https://cdn.dummyjson.com/products/images/beauty/Eyeshadow%20Palette%20with%20Mirror/thumbnail.png",
2046-
"quantity": 3,
2004+
"thumbnail": "https://cdn.dummyjson.com/products/images/beauty/Red%20Lipstick/thumbnail.png",
2005+
"quantity": 1,
20472006
"user": "cb1b"
20482007
}
20492008
]

src/features/auth/authAPI.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ 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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
2-
import { checkUser, createUser } from "./authAPI";
2+
import { checkUser, createUser, updateUser } from "./authAPI";
33

44
const initialState = {
55
loggedInUser: null,
@@ -15,6 +15,14 @@ export const createUserAsync = createAsyncThunk(
1515
return response.data;
1616
}
1717
);
18+
export const updateUserAsync = createAsyncThunk(
19+
"user/updateUser",
20+
async (update) => {
21+
const response = await updateUser(update);
22+
// The value we return becomes the `fulfilled` action payload
23+
return response.data;
24+
}
25+
);
1826
export const checkUserAsync = createAsyncThunk(
1927
"user/checkUser",
2028
async (loginInfo) => {
@@ -51,6 +59,13 @@ export const authSlice = createSlice({
5159
.addCase(checkUserAsync.rejected, (state, action) => {
5260
state.status = "idle";
5361
state.erorr = action.error;
62+
})
63+
.addCase(updateUserAsync.pending, (state) => {
64+
state.status = "loading";
65+
})
66+
.addCase(updateUserAsync.fulfilled, (state, action) => {
67+
state.status = "idle";
68+
state.loggedInUser = action.payload;
5469
});
5570
},
5671
});

src/features/auth/components/Signup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export default function Signup() {
3535
className="space-y-6"
3636
onSubmit={handleSubmit((data) => {
3737
dispatch(
38-
createUserAsync({ email: data.email, password: data.password })
38+
createUserAsync({
39+
email: data.email,
40+
password: data.password,
41+
addresses: [],
42+
})
3943
);
4044
console.log(data);
4145
})}

src/features/cart/Cart.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { Dialog, Transition } from "@headlessui/react";
99
import { XMarkIcon } from "@heroicons/react/24/outline";
1010
import { Link } from "react-router-dom";
11+
import { Navigate } from "react-router-dom";
1112

1213
export default function Cart() {
1314
const dispatch = useDispatch();
@@ -27,6 +28,7 @@ export default function Cart() {
2728
};
2829
return (
2930
<>
31+
{!items.length && <Navigate to="/" replace={true}></Navigate>}
3032
<div>
3133
<div className="mx-auto mt-12 bg-white max-w-7xl px-4 sm:px-6 lg:px-8">
3234
<div className="border-t border-gray-200 px-4 py-6 sm:px-6">

src/features/product/components/ProductDetail.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export default function ProductDetail() {
4545

4646
const handleCart = (e) => {
4747
e.preventDefault();
48-
dispatch(addToCartAsync({ ...product, quantity: 1, user: user.id }));
48+
const newItem = { ...product, quantity: 1, user: user.id };
49+
delete newItem["id"]; // to avoid creating same id on adding same product to cart....
50+
dispatch(addToCartAsync(newItem));
4951
};
5052

5153
useEffect(() => {

0 commit comments

Comments
 (0)