-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathindex.tsx
More file actions
95 lines (89 loc) · 3.13 KB
/
index.tsx
File metadata and controls
95 lines (89 loc) · 3.13 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
/*
* Copyright (c) 2023, Salesforce, 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
*/
import React, {useState, ReactElement} from 'react'
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
import {withReactQuery} from '@salesforce/pwa-kit-react-sdk/ssr/universal/components/with-react-query'
import {useCorrelationId} from '@salesforce/pwa-kit-react-sdk/ssr/universal/hooks'
import {proxyBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
interface AppConfigProps {
children: React.ReactNode
}
const AppConfig = (props: AppConfigProps): ReactElement => {
const {correlationId} = useCorrelationId()
const headers = {
'correlation-id': correlationId
}
const defaultSiteId = 'RefArch'
const defaultLocale = 'en-US'
const [siteId, setSiteId] = useState(defaultSiteId)
const [locale, setLocale] = useState(defaultLocale)
const anotherSite = siteId === defaultSiteId ? 'RefArch' : defaultSiteId
const anotherLocale = locale === defaultLocale ? 'en-CA' : defaultLocale
return (
<CommerceApiProvider
siteId={siteId}
shortCode="kv7kzm78"
clientId="4afbc51f-6423-41c8-8b29-d7f2825b5bee"
organizationId="f_ecom_zzrf_006"
redirectURI="http://localhost:3000/callback"
proxy={`http://localhost:3000/${String(proxyBasePath)}/api`}
locale={locale}
currency="USD"
headers={headers}
>
{props.children}
<div
style={{
backgroundColor: '#ebebeb',
position: 'fixed',
right: 0,
bottom: 0,
margin: '8px'
}}
>
<h3>Site: {siteId}</h3>
<button
onClick={() => {
setSiteId(anotherSite)
}}
>
Switch to {anotherSite}
</button>
<button
onClick={() => {
setLocale(anotherLocale)
}}
>
Switch to {anotherLocale}
</button>
</div>
</CommerceApiProvider>
)
}
AppConfig.restore = () => {}
AppConfig.extraGetPropsArgs = () => {}
AppConfig.freeze = () => {}
const isServerSide = typeof window === 'undefined'
// Recommended settings for PWA-Kit usages.
// NOTE: they will be applied on both server and client side.
const options = {
queryClientConfig: {
defaultOptions: {
queries: {
retry: false,
staleTime: 2 * 1000,
...(isServerSide ? {retryOnMount: false} : {}),
// Option for debugging changes in cache with React Query Dev Tools
refetchOnWindowFocus: false
},
mutations: {
retry: false
}
}
}
}
export default withReactQuery(AppConfig, options)