-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathroutes.jsx
More file actions
168 lines (158 loc) · 5.37 KB
/
routes.jsx
File metadata and controls
168 lines (158 loc) · 5.37 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* istanbul ignore file */
// NOTE!
// This file is being ignored in the test coverage report for now. It reports `0%` functions
// tested, which brings down the overall coverage and blocks CI. There are tests still, but
// we don't want it to count toward coverage until we figure out how to cover the `functions`
// metric for this file in its test.
import React from 'react'
import loadable from '@loadable/component'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
// Components
import {Skeleton} from '@salesforce/retail-react-app/app/components/shared/ui'
import {configureRoutes} from '@salesforce/retail-react-app/app/utils/routes-utils'
const fallback = <Skeleton height="75vh" width="100%" />
// Pages
const Home = loadable(() => import('./pages/home'), {fallback})
const Login = loadable(() => import('./pages/login'), {fallback})
const Registration = loadable(() => import('./pages/registration'), {
fallback
})
const ResetPassword = loadable(() => import('./pages/reset-password'), {fallback})
const Account = loadable(() => import('./pages/account'), {fallback})
const Cart = loadable(() => import('./pages/cart'), {fallback})
const Checkout = loadable(() => import('./pages/checkout'), {
fallback
})
const CheckoutOneClick = loadable(() => import('./pages/checkout-one-click'), {
fallback
})
const CheckoutConfirmation = loadable(() => import('./pages/confirmation'), {fallback})
const SocialLoginRedirect = loadable(() => import('./pages/social-login-redirect'), {fallback})
const LoginRedirect = loadable(() => import('./pages/login-redirect'), {fallback})
const ProductDetail = loadable(() => import('./pages/product-detail'), {fallback})
const ProductList = loadable(() => import('./pages/product-list'), {
fallback
})
const StoreLocator = loadable(() => import('./pages/store-locator'), {
fallback
})
const Wishlist = loadable(() => import('./pages/account/wishlist'), {
fallback
})
const PaymentProcessing = loadable(() => import('./pages/checkout/payment-processing'), {fallback})
const PageNotFound = loadable(() => import('./pages/page-not-found'))
export const routes = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/login',
component: Login,
exact: true
},
{
path: '/registration',
component: Registration,
exact: true
},
{
path: '/reset-password',
component: ResetPassword,
exact: true
},
{
path: '/account',
component: Account
},
{
path: '/checkout',
component: (props) => {
// One Click Checkout: Saves shipping/payment for returning shoppers. Security required:
// (1) Captcha for passwordless login, (2) OTP for email changes. See config/default.js for details.
const enabled = getConfig()?.app?.oneClickCheckout?.enabled
return enabled ? <CheckoutOneClick {...props} /> : <Checkout {...props} />
},
exact: true
},
{
path: '/checkout/confirmation/:orderNo',
component: CheckoutConfirmation
},
{
path: '/checkout/payment-processing',
component: PaymentProcessing
},
{
path: '/callback',
component: LoginRedirect,
exact: true
},
{
path: '/cart',
component: Cart,
exact: true
},
{
path: '/product/:productId',
component: ProductDetail
},
{
path: '/search',
component: ProductList
},
{
path: '/category/:categoryId',
component: ProductList
},
{
path: '/account/wishlist',
component: Wishlist
},
{
path: '/store-locator',
component: StoreLocator
}
]
export default () => {
const config = getConfig()
const loginConfig = config?.app?.login
const resetPasswordLandingPath = loginConfig?.resetPassword?.landingPath
const socialLoginEnabled = loginConfig?.social?.enabled
const socialRedirectURI = loginConfig?.social?.redirectURI
const passwordlessLoginEnabled = loginConfig?.passwordless?.enabled
const passwordlessLoginLandingPath = loginConfig?.passwordless?.landingPath
// Add dynamic routes conditionally (only if features are enabled and paths are defined)
const dynamicRoutes = [
resetPasswordLandingPath && {
path: resetPasswordLandingPath,
component: ResetPassword,
exact: true
},
passwordlessLoginEnabled &&
passwordlessLoginLandingPath && {
path: passwordlessLoginLandingPath,
component: Login,
exact: true
},
socialLoginEnabled &&
socialRedirectURI && {
path: socialRedirectURI,
component: SocialLoginRedirect,
exact: true
}
].filter(Boolean)
const allRoutes = configureRoutes([...routes, ...dynamicRoutes], config, {
ignoredRoutes: ['/callback'],
fuzzyPathMatching: true
})
// Add catch-all route at the end so it doesn't match before dynamic routes
return [...allRoutes, {path: '*', component: PageNotFound}]
}