-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
150 lines (113 loc) · 5.48 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import './App.css';
import { BrowserRouter, Routes, Route } from "react-router-dom"
import WebFont from "webfontloader"
import { useEffect, useState } from 'react';
import Header from './component/layout/Header/Header';
import Footer from './component/layout/Footer/Footer';
import Home from './component/Home/Home';
import ProductDetails from './component/Product/ProductDetails';
import Products from './component/Product/Products';
import Search from "./component/Product/Search";
import store from "./store"
import { loadUser } from "./actions/userAction"
import LoginSignUp from './component/User/LoginSignUp';
import { useSelector } from 'react-redux';
import UserOptions from './component/layout/Header/UserOptions';
import Profile from './component/User/Profile';
import axios from 'axios';
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";
import Payment from "./component/Cart/Payment";
import OrderSuccess from "./component/Cart/OrderSuccess";
import MyOrders from "./component/Order/MyOrders";
import OrderDetails from "./component/Order/OrderDetails";
import ForgotPassword from "./component/User/ForgotPassword";
import ResetPassword from "./component/User/ResetPassword";
import Cart from "./component/Cart/Cart";
import Shipping from "./component/Cart/Shipping";
import ConfirmOrder from "./component/Cart/ConfirmOrder";
import UpdateProfile from "./component/User/UpdateProfile";
import UpdatePassword from "./component/User/UpdatePassword";
import ProtectedRoute from "./component/Route/ProtectedRoute";
import Dashboard from "./component/Admin/Dashboard.js";
import ProductList from "./component/Admin/ProductList.js";
import NewProduct from "./component/Admin/NewProduct";
import UpdateProduct from "./component/Admin/UpdateProduct";
import OrderList from "./component/Admin/OrderList";
import ProcessOrder from "./component/Admin/ProcessOrder";
import UsersList from "./component/Admin/UsersList";
import UpdateUser from "./component/Admin/UpdateUser";
import ProductReviews from "./component/Admin/ProductReviews";
import Navbar from './component/layout/Header/navbar';
import Contact from './component/layout/Contact/Contact';
function App() {
const { isAuthenticated, user, loading } = useSelector((state) => state.user)
const [stripeApiKey, setStripeApiKey] = useState("")
async function getStripeApiKey() {
const { data } = await axios.get("/api/v1/stripeapikey")
setStripeApiKey(data.stripeApiKey)
}
useEffect(() => {
WebFont.load({
google: {
families: ["Roboto", "Droid Sans", "Chilanka"],
},
});
store.dispatch(loadUser())
getStripeApiKey()
}, [])
return (
<BrowserRouter>
{/* <Header/> */}
<Navbar isAuthenticated={isAuthenticated} />
{isAuthenticated && <UserOptions user={user} />}
<Routes>
{stripeApiKey && (
<Route path="/process/payment" element={<Elements stripe={loadStripe(stripeApiKey)}> <Payment /> </Elements>} />
)}
{/* <Route path="/orders" element={<ProtectedRoute isAuthenticated={isAuthenticated}> <MyOrders /></ProtectedRoute>
}
/> */}
<Route element={<ProtectedRoute user={user} isAuthenticated={isAuthenticated} loading={loading} />}>
<Route path="/me/update" element={<UpdateProfile />} />
<Route path="/password/update" element={<UpdatePassword />} />
<Route path="/shipping" element={<Shipping />} />
<Route path="/success" element={<OrderSuccess />} />
<Route path="/orders" element={<MyOrders />} />
<Route path="/order/confirm" element={<ConfirmOrder />} />
<Route path="/order/:id" element={<OrderDetails />} />
<Route path="/account" element={<Profile />} />
</Route>
<Route element={<ProtectedRoute user={user} isAdmin={true} isAuthenticated={isAuthenticated} loading={loading} />}>
<Route path="/admin/dashboard" element={<Dashboard />} />
<Route path="/admin/products" element={<ProductList />} />
<Route path="/admin/product" element={<NewProduct />} />
<Route path="/admin/product/:id" element={<UpdateProduct />} />
<Route path="/admin/orders" element={<OrderList />} />
<Route path="/admin/order/:id" element={<ProcessOrder />} />
<Route path="/admin/users" element={<UsersList />} />
<Route path="/admin/user/:id" element={<UpdateUser />} />
<Route path="/admin/reviews" element={<ProductReviews />} />
</Route>
<Route path="/" element={<Home />} />
<Route path="/product/:id" element={<ProductDetails />} />
<Route path="/products" element={<Products />} />
<Route path="/products/:keyword" element={<Products />} />
<Route path="/search" element={<Search />} />
<Route path="/contact" element={<Contact />} />
{/* <Route path="/contact" element= {<Contact/>} />
<Route path="/about" element= {<About/>} /> */}
{/* <Route path="/account" element= {<Profile/>} /> */}
<Route path="/password/forgot" element={<ForgotPassword />} />
<Route path="/password/reset/:token" element={<ResetPassword />} />
<Route path="/login" element={<LoginSignUp />} />
<Route path="/cart" element={<Cart />} />
{/* <Route path="/account" element={<ProtectedRoute isAuthenticated={isAuthenticated}> <Profile /></ProtectedRoute>
}
/> */}
</Routes>
<Footer />
</BrowserRouter>
);
}
export default App;