-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathsetup-app.ts
More file actions
62 lines (51 loc) · 2.06 KB
/
setup-app.ts
File metadata and controls
62 lines (51 loc) · 2.06 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
/*
* Copyright (c) 2024, 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
*/
// Third-Party
import React from 'react'
import {RouteProps} from 'react-router-dom'
// Platform Imports
import {ApplicationExtension} from '@salesforce/pwa-kit-extension-sdk/react'
import {applyHOCs} from '@salesforce/pwa-kit-extension-sdk/react/utils'
// Local Imports
import {withOptionalChakra} from './components/with-optional-chakra-provider'
import {withOptionalCommerceSdkReactProvider} from './components/with-optional-commerce-sdk-react-provider'
import {withStoreLocator} from './components/with-store-locator'
import {Config} from './types'
import StoreLocatorPage from './pages/store-locator'
import {logger} from './logger'
import extensionMeta from '../extension-meta.json'
class StoreLocatorExtension extends ApplicationExtension<Config> {
static readonly id = extensionMeta.id
extendApp<T extends React.ComponentType<T>>(
App: React.ComponentType<T>
): React.ComponentType<T> {
const config = this.getConfig()
if (!config.supportedCountries || config.supportedCountries.length === 0) {
logger.error(
'[extension-chakra-store-locator] Missing supportedCountries, this extension will not work.'
)
}
const HOCs = [
(component: React.ComponentType<any>) => withStoreLocator(component, config),
(component: React.ComponentType<any>) =>
withOptionalCommerceSdkReactProvider(component, config),
(component: React.ComponentType<any>) => withOptionalChakra(component)
]
return applyHOCs(App, HOCs)
}
extendRoutes(routes: RouteProps[]): RouteProps[] {
return [
{
exact: true,
path: this.getConfig().path,
component: StoreLocatorPage
},
...routes
]
}
}
export default StoreLocatorExtension