• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / knights-ecomm-fe / 10060387859

23 Jul 2024 10:55AM UTC coverage: 90.757% (+0.09%) from 90.671%
10060387859

push

github

web-flow
Merge pull request #73 from atlp-rwanda/ft-order-management

#68 Implement vendor and admin order management feature

1079 of 1360 branches covered (79.34%)

Branch coverage included in aggregate %.

1519 of 1727 new or added lines in 21 files covered. (87.96%)

3 existing lines in 2 files now uncovered.

11332 of 12315 relevant lines covered (92.02%)

12.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.27
/src/Routes/Router.tsx
1
import React, { useEffect } from 'react';
1✔
2
import { Navigate, Route, Routes } from 'react-router-dom';
1✔
3
import PageTitle from '../components/PageTitle';
1✔
4
import Register from '../pages/Authentication/Register';
1✔
5
import RegisterVendor from '../pages/Authentication/RegisterVendor';
1✔
6
import VerifyEmail from '../pages/Authentication/VerifyEmail';
1✔
7
import Login, { DecodedToken } from '../pages/Authentication/Login';
1✔
8
import { useDispatch, useSelector } from 'react-redux';
1✔
9
import { RootState } from '../redux/store';
1✔
10
import GoogleLoginSuccess from '../pages/Authentication/GoogleLoginSuccess';
1✔
11
import { useJwt } from 'react-jwt';
1✔
12
import OtpPage from '../pages/Authentication/OtpPage';
1✔
13
import SuspendedAccount from '../components/SuspendedAccount/SuspendedAccount';
1✔
14
import { ForgotPassword } from '../pages/Authentication/ForgotPassword';
1✔
15
import { ResetPassword } from '../pages/Authentication/ResetPassword';
1✔
16
import DashboardLayout from '../layout/DashboardLayout';
1✔
17
import DashboarInnerLayout from '../layout/DashboarInnerLayout';
1✔
18
import DashboardProducts from '../components/Products/DashboardProducts/DashboardProducts';
1✔
19
import DashboardSingleProduct from '../components/Products/DashboardSingleProduct/DashboardSingleProduct';
1✔
20
import DashboardNewProducts from '../components/Products/DashboardNewProducts/DashboardNewProducts';
1✔
21
import MainLayout from '../layout/MainLayout';
1✔
22
import Home from '../pages/LandingPage/Home';
1✔
23
import SearchPage from '../pages/searchPage';
1✔
24
import SingleProduct from '../components/SingleProduct/SingleProduct';
1✔
25
import Cart from '../components/Cart/Cart';
1✔
26
import DashboardEditProducts from '../components/Products/DashboardEditProducts/DashboardEditProducts';
1✔
27
import WishlistPage from '../pages/WishlistPage/WishlistPage';
1✔
28
import { setOnWishlistPage } from '../redux/reducers/wishlistReducer';
1✔
29
import { useLocation } from 'react-router-dom';
1✔
30
import BuyerOrders from '../pages/Orders/BuyerOrders';
1✔
31
import SingleBuyerOrder from '../pages/Orders/SingleBuyerOrder';
1✔
32
import Users from '../components/Dashboard/adminDashbord/Users';
1✔
33
import SingleUser from '../components/Dashboard/adminDashbord/SingleUser';
1✔
34
import CheckOutMain from '../pages/Cart/checkOutMain';
1✔
35
import PaymentOk from '../pages/PaymentOk';
1✔
36
import ProtectedRoute from './ProtectedRoute';
1✔
37
import NotFound from './NotFound';
1✔
38
import DashboardAccount from '../components/Dashboard/DashboardAccount/DashboardAccount';
1✔
39
import VendorOrder from '../pages/Orders/VendorOrder';
1✔
40
import SingleVendorOrder from '../pages/Orders/SingleVendorOrder';
1✔
41
import AdminOrders from '../pages/Orders/AdminOrders';
1✔
42
import SingleAdminOrder from '../pages/Orders/SingleAdminOrder';
1✔
43

1✔
44
const Router = () => {
1✔
45
  const { userToken } = useSelector((state: RootState) => state.auth);
6✔
46
  const { decodedToken } = useJwt<DecodedToken>(userToken);
6✔
47

6✔
48
  const isAdmin = decodedToken?.role.toLowerCase() === 'admin';
6!
49
  const isVendor = decodedToken?.role.toLowerCase() === 'vendor';
6!
50
  const isBuyer = decodedToken?.role.toLowerCase() === 'buyer';
6!
51

6✔
52
  const location = useLocation();
6✔
53
  const dispatch = useDispatch();
6✔
54

6✔
55
  useEffect(() => {
6✔
56
    if (userToken && location.pathname === '/wishlist') {
3!
57
      dispatch(setOnWishlistPage(true));
×
58
    } else {
3✔
59
      dispatch(setOnWishlistPage(false));
3✔
60
    }
3✔
61
  }, [location.pathname, dispatch, userToken]);
6✔
62

6✔
63
  return (
6✔
64
    <Routes>
6✔
65
      <Route
6✔
66
        path="/"
6✔
67
        element={
6✔
68
          <MainLayout>
6✔
69
            <PageTitle title="Knights Store" />
6✔
70
            <Home />
6✔
71
          </MainLayout>
6✔
72
        }
6✔
73
      />
6✔
74

6✔
75
      <Route
6✔
76
        path="/register"
6✔
77
        element={
6✔
78
          <MainLayout>
6✔
79
            <PageTitle title="Knights Store | Register" />
6✔
80
            <Register />
6✔
81
          </MainLayout>
6✔
82
        }
6✔
83
      />
6✔
84

6✔
85
      <Route
6✔
86
        path="/register-vendor"
6✔
87
        element={
6✔
88
          <MainLayout>
6✔
89
            <PageTitle title="Knights Store | Register Vendor" />
6✔
90
            <RegisterVendor />
6✔
91
          </MainLayout>
6✔
92
        }
6✔
93
      />
6✔
94

6✔
95
      <Route
6✔
96
        path="/verify-email/:token"
6✔
97
        element={
6✔
98
          <MainLayout>
6✔
99
            <PageTitle title="Knights Store | Verify Email" />
6✔
100
            <VerifyEmail />
6✔
101
          </MainLayout>
6✔
102
        }
6✔
103
      />
6✔
104

6✔
105
      <Route
6✔
106
        path="/forgot-password"
6✔
107
        element={
6✔
108
          <MainLayout>
6✔
109
            <PageTitle title="Knights Store | Forgot Password" />
6✔
110
            <ForgotPassword />
6✔
111
            {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
112
            {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
113
            {userToken && isBuyer && <Navigate to="/" />}
6!
114
          </MainLayout>
6✔
115
        }
6✔
116
      />
6✔
117

6✔
118
      <Route
6✔
119
        path="/reset-password"
6✔
120
        element={
6✔
121
          <MainLayout>
6✔
122
            <PageTitle title="Knights Store | Reset Password" />
6✔
123
            <ResetPassword />
6✔
124
            {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
125
            {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
126
            {userToken && isBuyer && <Navigate to="/" />}
6!
127
          </MainLayout>
6✔
128
        }
6✔
129
      />
6✔
130

6✔
131
      <Route
6✔
132
        path="/login"
6✔
133
        element={
6✔
134
          <MainLayout>
6✔
135
            <PageTitle title="Knights Store | Login" />
6✔
136
            {userToken && isAdmin && <Navigate to="/admin/dashboard/users" />}
6!
137
            {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
138
            {userToken && isBuyer && <Navigate to="/" />}
6!
139
            {!userToken && <Login />}
6✔
140
          </MainLayout>
6✔
141
        }
6✔
142
      />
6✔
143
      <Route
6✔
144
        path="/login/google-auth"
6✔
145
        element={
6✔
146
          <MainLayout>
6✔
147
            <PageTitle title="Knights Store | Login" />
6✔
148
            {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
149
            {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
150
            {userToken && isBuyer && <Navigate to="/" />}
6!
151
            {!userToken && <GoogleLoginSuccess />}
6✔
152
          </MainLayout>
6✔
153
        }
6✔
154
      />
6✔
155
      <Route
6✔
156
        path="/suspended-account"
6✔
157
        element={
6✔
158
          <MainLayout>
6✔
159
            <PageTitle title="Knights Store | Suspended Account" />
6✔
160
            {userToken && <Navigate to="/" />}
6!
161
            <SuspendedAccount />
6✔
162
          </MainLayout>
6✔
163
        }
6✔
164
      />
6✔
165
      <Route
6✔
166
        path="/otp-verficaton"
6✔
167
        element={
6✔
168
          <MainLayout>
6✔
169
            <PageTitle title="Knights Store | Verify OTP" />
6✔
170
            <OtpPage />
6✔
171
            {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
172
            {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
173
            {userToken && isBuyer && <Navigate to="/" />}
6!
174
          </MainLayout>
6✔
175
        }
6✔
176
      />
6✔
177

6✔
178
      <Route
6✔
179
        path="/wishlist"
6✔
180
        element={
6✔
181
          <MainLayout>
6✔
182
            <PageTitle title="Knights Store | Wishlist" />
6✔
183
            {userToken ? <WishlistPage /> : <Navigate to="/" />}
6!
184
          </MainLayout>
6✔
185
        }
6✔
186
      />
6✔
187

6✔
188
      {isVendor && (
6!
NEW
189
        <Route path="/vendor/dashboard" element={<DashboardLayout />}>
×
NEW
190
          <Route path="products" element={<DashboarInnerLayout />}>
×
NEW
191
            <Route path="" element={<DashboardProducts />} />
×
NEW
192
            <Route path="new" element={<DashboardNewProducts />} />
×
NEW
193
            <Route path=":id" element={<DashboardSingleProduct />} />
×
NEW
194
            <Route path=":id/edit" element={<DashboardEditProducts />} />
×
NEW
195
          </Route>
×
NEW
196
          <Route path="orders" element={<DashboarInnerLayout />}>
×
NEW
197
            <Route path="" element={<VendorOrder />} />
×
NEW
198
            <Route path=":orderId" element={<SingleVendorOrder />} />
×
NEW
199
          </Route>
×
NEW
200
        </Route>
×
201
      )}
6✔
202

6✔
203
      <Route
6✔
204
        path="/search"
6✔
205
        element={
6✔
206
          <MainLayout>
6✔
207
            <PageTitle title="Knights Store | Search" />
6✔
208
            <SearchPage />
6✔
209
          </MainLayout>
6✔
210
        }
6✔
211
      />
6✔
212

6✔
213
      <Route
6✔
214
        path="/product/:id"
6✔
215
        element={
6✔
216
          <MainLayout>
6✔
217
            <PageTitle title="Knights Store | View Product " />
6✔
218
            <SingleProduct />
6✔
219
          </MainLayout>
6✔
220
        }
6✔
221
      />
6✔
222
      {/*  Protected routes 1 . Vendor pages */}
6✔
223
      <Route
6✔
224
        path="/vendor/dashboard/*"
6✔
225
        element={
6✔
226
          <ProtectedRoute requiredRole="vendor">
6✔
227
            <DashboardLayout />
6✔
228
          </ProtectedRoute>
6✔
229
        }
6✔
230
      >
6✔
231
        <Route index element={<DashboardProducts />} />
6✔
232
        <Route path="account" element={<DashboarInnerLayout />}>
6✔
233
          <Route index element={<DashboardAccount />} />
6✔
234
        </Route>
6✔
235
        <Route path="products" element={<DashboarInnerLayout />}>
6✔
236
          <Route index element={<DashboardProducts />} />
6✔
237
          <Route path="new" element={<DashboardNewProducts />} />
6✔
238
          <Route path=":id" element={<DashboardSingleProduct />} />
6✔
239
          <Route path=":id/edit" element={<DashboardEditProducts />} />
6✔
240
        </Route>
6✔
241
        <Route path="*" element={<NotFound />} />
6✔
242
      </Route>
6✔
243

6✔
244
      <Route
6✔
245
        path="/cart"
6✔
246
        element={
6✔
247
          <MainLayout>
6✔
248
            <PageTitle title="Knights Store | Cart" />
6✔
249
            <Cart />
6✔
250
          </MainLayout>
6✔
251
        }
6✔
252
      />
6✔
253
      {/*  Protected routes 2 . Buyer pages */}
6✔
254

6✔
255
      <Route element={<ProtectedRoute requiredRole="buyer" />}>
6✔
256
        <Route
6✔
257
          path="/checkout"
6✔
258
          element={
6✔
259
            <MainLayout>
6✔
260
              <PageTitle title="Knights Store | Create Order" />
6✔
261
              {userToken && isBuyer && <CheckOutMain />}
6!
262
              {!userToken && <Navigate to="/login" />}
6✔
263
            </MainLayout>
6✔
264
          }
6✔
265
        />
6✔
266
        <Route
6✔
267
          path="/completion"
6✔
268
          element={
6✔
269
            <MainLayout>
6✔
270
              <PageTitle title="Knights Store | Payment successful" />
6✔
271
              <PaymentOk />
6✔
272
            </MainLayout>
6✔
273
          }
6✔
274
        />
6✔
275
        <Route
6✔
276
          path="/orders"
6✔
277
          element={
6✔
278
            <MainLayout>
6✔
279
              <PageTitle title="Knights Store | Orders" />
6✔
280
              {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
281
              {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
282
              {userToken && isBuyer && <BuyerOrders />}
6!
283
              {!userToken && <Navigate to="/login" />}
6✔
284
            </MainLayout>
6✔
285
          }
6✔
286
        />
6✔
287

6✔
288
        <Route
6✔
289
          path="/orders/:orderId"
6✔
290
          element={
6✔
291
            <MainLayout>
6✔
292
              <PageTitle title="Knights Store | Orders" />
6✔
293
              {userToken && isAdmin && <Navigate to="/admin/dashboard" />}
6!
294
              {userToken && isVendor && <Navigate to="/vendor/dashboard" />}
6!
295
              {userToken && isBuyer && <SingleBuyerOrder />}
6!
296
              {!userToken && <Navigate to="/login" />}
6✔
297
            </MainLayout>
6✔
298
          }
6✔
299
        />
6✔
300
        <Route path="*" element={<NotFound />} />
6✔
301
      </Route>
6✔
302
      {/*  Protected routes 3 . Admin pages */}
6✔
303

6✔
304
      <Route element={<ProtectedRoute requiredRole="admin" />}>
6✔
305
        <Route path="/Admin/dashboard" element={<DashboardLayout />}>
6✔
306
          <Route path="" element={<DashboarInnerLayout />}>
6✔
307
            <Route path="" element={<Users />} />
6✔
308
          </Route>
6✔
309
          <Route path="users" element={<DashboarInnerLayout />}>
6✔
310
            <Route path="" element={<Users />} />
6✔
311
            <Route path=":id" element={<SingleUser />} />
6✔
312
            <Route path="account" element={<DashboardAccount />} />
6✔
313
          </Route>
6✔
314
          <Route path="orders" element={<DashboarInnerLayout />}>
6✔
315
            <Route path="" element={<AdminOrders />} />
6✔
316
            <Route path=":orderId" element={<SingleAdminOrder />} />
6✔
317
          </Route>
6✔
318
        </Route>
6✔
319
      </Route>
6✔
320

6✔
321
      <Route path="*" element={<NotFound />} />
6✔
322
    </Routes>
6✔
323
  );
6✔
324
};
6✔
325

1✔
326
export default Router;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc