File tree Expand file tree Collapse file tree 4 files changed +85
-11
lines changed Expand file tree Collapse file tree 4 files changed +85
-11
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
1010 Route ,
1111 Link ,
1212} from "react-router-dom" ;
13- import Cart from "./features/cart/Cart" ;
13+
1414import CartPage from "./pages/CartPage" ;
1515import Checkout from "./pages/Checkout" ;
1616import ProductDetailPage from "./pages/ProductDetailPage" ;
@@ -19,6 +19,8 @@ import { useEffect } from "react";
1919import { useDispatch , useSelector } from "react-redux" ;
2020import { selectLoggedInUser } from "./features/auth/authSlice" ;
2121import { fetchItemsByUserIdAsync } from "./features/cart/cartSlice" ;
22+ import PageNotFound from "./pages/404" ;
23+ import OrderSuccessPage from "./pages/OrderSuccessPage" ;
2224const router = createBrowserRouter ( [
2325 {
2426 path : "/" ,
@@ -61,6 +63,14 @@ const router = createBrowserRouter([
6163 </ Protected >
6264 ) ,
6365 } ,
66+ {
67+ path : "/order-success" ,
68+ element : < OrderSuccessPage > </ OrderSuccessPage > ,
69+ } ,
70+ {
71+ path : "*" ,
72+ element : < PageNotFound > </ PageNotFound > ,
73+ } ,
6474] ) ;
6575
6676function App ( ) {
Original file line number Diff line number Diff line change 1+ import { Link } from "react-router-dom" ;
2+ function PageNotFound ( ) {
3+ return (
4+ < main className = "grid min-h-full place-items-center bg-white px-6 py-24 sm:py-32 lg:px-8" >
5+ < div className = "text-center" >
6+ < p className = "text-base font-semibold text-indigo-600" > 404</ p >
7+ < h1 className = "mt-4 text-3xl font-bold tracking-tight text-gray-900 sm:text-5xl" >
8+ Page not found
9+ </ h1 >
10+ < p className = "mt-6 text-base leading-7 text-gray-600" >
11+ Sorry, we couldn’t find the page you’re looking for.
12+ </ p >
13+ < div className = "mt-10 flex items-center justify-center gap-x-6" >
14+ < Link
15+ to = "/"
16+ href = "#"
17+ className = "rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
18+ >
19+ Go back home
20+ </ Link >
21+ </ div >
22+ </ div >
23+ </ main >
24+ ) ;
25+ }
26+
27+ export default PageNotFound ;
Original file line number Diff line number Diff line change @@ -51,16 +51,20 @@ function Checkout() {
5151 setpaymentMethod ( e . target . value ) ; // cash/card
5252 } ;
5353 const handleOrder = ( e ) => {
54- const order = {
55- items,
56- totalAmount,
57- totalItems,
58- user,
59- selectedAddress,
60- paymentMethod,
61- } ;
62- dispatch ( createOrderAsync ( order ) ) ;
63- // TODO: redirect to order success page
54+ if ( selectedAddress && paymentMethod ) {
55+ const order = {
56+ items,
57+ totalAmount,
58+ totalItems,
59+ user,
60+ selectedAddress,
61+ paymentMethod,
62+ } ;
63+ dispatch ( createOrderAsync ( order ) ) ;
64+ // TODO: redirect to order success page
65+ } else {
66+ alert ( "Enter Address and Payment Method" ) ;
67+ }
6468 // TODO: clear cart after order
6569 // TODO: on server change the stock number of items
6670 } ;
Original file line number Diff line number Diff line change 1+ import { Link } from "react-router-dom" ;
2+ import { Navigate } from "react-router-dom" ;
3+ function OrderSuccessPage ( { order } ) {
4+ return (
5+ < >
6+ { ! order && < Navigate to = "/" replace = { true } > </ Navigate > }
7+ < main className = "grid min-h-full place-items-center bg-white px-6 py-24 sm:py-32 lg:px-8" >
8+ < div className = "text-center" >
9+ < p className = "text-base font-semibold text-indigo-600" >
10+ Order Successfully Placed
11+ </ p >
12+ < h1 className = "mt-4 text-3xl font-bold tracking-tight text-gray-900 sm:text-5xl" >
13+ Order Number #{ order ?. id }
14+ </ h1 >
15+ < p className = "mt-6 text-base leading-7 text-gray-600" >
16+ You can check your order in My Account > My Orders
17+ </ p >
18+ < div className = "mt-10 flex items-center justify-center gap-x-6" >
19+ < Link
20+ to = "/"
21+ href = "#"
22+ className = "rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
23+ >
24+ Go back home
25+ </ Link >
26+ </ div >
27+ </ div >
28+ </ main >
29+ </ >
30+ ) ;
31+ }
32+
33+ export default OrderSuccessPage ;
You can’t perform that action at this time.
0 commit comments