@graphcommerce/magento-store 9.1.0-canary.34 → 9.1.0-canary.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/components/CurrencySymbol/CurrencySymbol.tsx +2 -1
- package/components/Money/Money.tsx +3 -1
- package/components/StoreSwitcher/StoreSwitcherGroupSelector.tsx +1 -1
- package/components/StoreSwitcher/useStoreSwitcher.tsx +67 -63
- package/components/StoreSwitcherButton/StoreSwitcherButton.tsx +15 -25
- package/components/StoreSwitcherButton/StoreSwitcherFab.tsx +20 -0
- package/components/StoreSwitcherButton/StoreSwitcherMenuFabSecondaryItem.tsx +34 -0
- package/components/StoreSwitcherButton/StoreSwitcherText.tsx +50 -0
- package/components/StoreSwitcherButton/index.ts +5 -0
- package/components/StoreSwitcherButton/useStoreSwitcherButton.ts +25 -0
- package/graphql/fragments/StoreConfigFragment.graphql +3 -2
- package/graphql/fragments/StoreConfigQueryFragment.graphql +3 -0
- package/graphql/queries/StoreSwitcherList.graphql +1 -0
- package/index.ts +5 -5
- package/package.json +10 -10
- package/plugins/magentoCurrencyCode.ts +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4c92400`](https://github.com/graphcommerce-org/graphcommerce/commit/4c92400733bb3764494298122771d5bd9bacd5a2) - Render prices with a narrowSymbol so users just see $ instead of US$ ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
- [`f0d244e`](https://github.com/graphcommerce-org/graphcommerce/commit/f0d244ef8625e9cd2fc08d8518f8afa1edb3d688) - Solve issue where the currency switcher would result in an additional query ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
11
|
+
## 9.1.0-canary.35
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`5a41fff`](https://github.com/graphcommerce-org/graphcommerce/commit/5a41fff74c38ed1f9793e48ec42cba71d1d539d1) - Use the default display currency instead of the base currency in case they differ from one another. ([@paales](https://github.com/paales))
|
|
16
|
+
|
|
17
|
+
- [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`5a41fff`](https://github.com/graphcommerce-org/graphcommerce/commit/5a41fff74c38ed1f9793e48ec42cba71d1d539d1) - Store switcher now allows switching between currencies without navigating and just switches the @privateContext. ([@paales](https://github.com/paales))
|
|
18
|
+
|
|
19
|
+
- [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`5a41fff`](https://github.com/graphcommerce-org/graphcommerce/commit/5a41fff74c38ed1f9793e48ec42cba71d1d539d1) - Added store switcher to the header and mobile navigation ([@paales](https://github.com/paales))
|
|
20
|
+
|
|
3
21
|
## 9.1.0-canary.34
|
|
4
22
|
|
|
5
23
|
## 9.1.0-canary.33
|
|
@@ -7,7 +7,8 @@ import { StoreConfigDocument } from '../../graphql'
|
|
|
7
7
|
|
|
8
8
|
export function CurrencySymbol(props: CurrencySymbolProps) {
|
|
9
9
|
const { currency } = props
|
|
10
|
-
const baseCurrencyCode =
|
|
10
|
+
const baseCurrencyCode =
|
|
11
|
+
useQuery(StoreConfigDocument).data?.storeConfig?.default_display_currency_code ?? ''
|
|
11
12
|
|
|
12
13
|
return <CurrencySymbolBase {...props} currency={currency || baseCurrencyCode} />
|
|
13
14
|
}
|
|
@@ -15,7 +15,8 @@ export type MoneyProps = MoneyFragment & OverridableProps
|
|
|
15
15
|
|
|
16
16
|
export function Money(props: MoneyProps) {
|
|
17
17
|
const { currency, value, round = false, formatOptions, sx } = props
|
|
18
|
-
const baseCurrencyCode =
|
|
18
|
+
const baseCurrencyCode =
|
|
19
|
+
useQuery(StoreConfigDocument).data?.storeConfig?.default_display_currency_code
|
|
19
20
|
const digits = (value ?? 0) % 1 !== 0
|
|
20
21
|
const maximumFractionDigits = round && !digits ? 0 : 2
|
|
21
22
|
const currencyCode = currency ?? baseCurrencyCode ?? ''
|
|
@@ -26,6 +27,7 @@ export function Money(props: MoneyProps) {
|
|
|
26
27
|
<CurrencyFormat
|
|
27
28
|
currency={currencyCode}
|
|
28
29
|
maximumFractionDigits={maximumFractionDigits}
|
|
30
|
+
currencyDisplay='narrowSymbol'
|
|
29
31
|
{...formatOptions}
|
|
30
32
|
value={value}
|
|
31
33
|
sx={sx}
|
|
@@ -24,7 +24,7 @@ export function StoreSwitcherGroupSelector(props: StoreSwitcherGroupSelectorProp
|
|
|
24
24
|
const { header, showStores = 0, showCurrencies, ...actionCardList } = props
|
|
25
25
|
const { control, storeGroups } = useStoreSwitcherForm()
|
|
26
26
|
|
|
27
|
-
const hidden = storeGroups.length === 1
|
|
27
|
+
const hidden = storeGroups.length === 1
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
30
|
<>
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
useForm,
|
|
3
|
+
useWatch,
|
|
4
|
+
type SubmitHandler,
|
|
5
|
+
type UseFormReturn,
|
|
6
|
+
} from '@graphcommerce/ecommerce-ui'
|
|
3
7
|
import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
|
|
4
8
|
import {
|
|
5
9
|
cookie,
|
|
6
10
|
filterNonNullableKeys,
|
|
7
11
|
storefrontAll,
|
|
12
|
+
useCookie,
|
|
8
13
|
useStorefrontConfig,
|
|
9
14
|
type RequiredKeys,
|
|
10
15
|
} from '@graphcommerce/next-ui'
|
|
@@ -28,7 +33,7 @@ export type StoreSwitcherGroup = Pick<
|
|
|
28
33
|
disabled: boolean
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
export
|
|
36
|
+
export interface StoreSwitcherFormValues {
|
|
32
37
|
storeGroupCode: string
|
|
33
38
|
storeCode: string
|
|
34
39
|
currency: string
|
|
@@ -39,7 +44,7 @@ type StoreSwitcherFormContextType = {
|
|
|
39
44
|
storeGroups: StoreSwitcherGroup[]
|
|
40
45
|
} & UseFormReturn<StoreSwitcherFormValues>
|
|
41
46
|
|
|
42
|
-
const StoreSwitcherFormContext = createContext<StoreSwitcherFormContextType | null>(null)
|
|
47
|
+
export const StoreSwitcherFormContext = createContext<StoreSwitcherFormContextType | null>(null)
|
|
43
48
|
|
|
44
49
|
export function useStoreSwitcherForm(
|
|
45
50
|
context?: StoreSwitcherFormContextType,
|
|
@@ -87,29 +92,32 @@ export function useSelectedCurrency(context?: StoreSwitcherFormContextType): str
|
|
|
87
92
|
: null
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
export type StoreSwitcherFormProviderProps = {
|
|
96
|
+
children?: React.ReactNode
|
|
97
|
+
onSubmit?: SubmitHandler<StoreSwitcherFormValues>
|
|
98
|
+
} & StoreSwitcherListQuery
|
|
99
|
+
|
|
100
|
+
export function normalizeAvailableStores(
|
|
101
|
+
availableStores: StoreSwitcherListQuery['availableStores'],
|
|
102
|
+
): StoreSwitcherStore[] {
|
|
103
|
+
return filterNonNullableKeys(availableStores, [
|
|
104
|
+
'store_name',
|
|
105
|
+
'store_code',
|
|
106
|
+
'store_group_code',
|
|
107
|
+
'store_group_name',
|
|
108
|
+
'base_currency_code',
|
|
109
|
+
'locale',
|
|
110
|
+
])
|
|
111
|
+
.map((store) => ({
|
|
112
|
+
...store,
|
|
113
|
+
country: store.locale.split('_')[1]?.toLowerCase(),
|
|
114
|
+
disabled: !storefrontAll.find((l) => l.magentoStoreCode === store.store_code),
|
|
115
|
+
}))
|
|
116
|
+
.filter((store) => !store.disabled)
|
|
117
|
+
}
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
function normalizeStoreGroups(stores: StoreSwitcherStore[]): StoreSwitcherGroup[] {
|
|
120
|
+
return Object.values(
|
|
113
121
|
stores.reduce<{
|
|
114
122
|
[group: string]: StoreSwitcherGroup
|
|
115
123
|
}>((storesGrouped, store) => {
|
|
@@ -127,70 +135,66 @@ export function useStoreSwitcher({
|
|
|
127
135
|
if (storesGrouped[store.store_group_code].country !== store.country) {
|
|
128
136
|
storesGrouped[store.store_group_code].country = undefined
|
|
129
137
|
}
|
|
130
|
-
|
|
131
138
|
storesGrouped[store.store_group_code].stores.push(store)
|
|
132
139
|
return storesGrouped
|
|
133
140
|
}, {}),
|
|
134
141
|
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function useNormalizeMemo(availableStores: StoreSwitcherListQuery['availableStores']) {
|
|
145
|
+
return useMemo(() => {
|
|
146
|
+
const stores = normalizeAvailableStores(availableStores)
|
|
147
|
+
const storeGroups = normalizeStoreGroups(stores)
|
|
148
|
+
return { stores, storeGroups }
|
|
149
|
+
}, [availableStores])
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function StoreSwitcherFormProvider(props: StoreSwitcherFormProviderProps) {
|
|
153
|
+
const { children, onSubmit, availableStores } = props
|
|
154
|
+
|
|
155
|
+
const { stores, storeGroups } = useNormalizeMemo(availableStores)
|
|
135
156
|
|
|
136
157
|
const storeCode = useStorefrontConfig().magentoStoreCode
|
|
158
|
+
const store = stores.find((s) => s.store_code === storeCode)
|
|
137
159
|
|
|
138
160
|
const form = useForm<StoreSwitcherFormValues>({
|
|
139
161
|
defaultValues: {
|
|
140
162
|
storeCode,
|
|
141
|
-
storeGroupCode:
|
|
142
|
-
|
|
163
|
+
storeGroupCode: stores.find((s) => s.store_code === storeCode)?.store_group_code ?? '',
|
|
164
|
+
currency: cookie('Magento-Content-Currency') ?? store?.default_display_currency_code ?? '',
|
|
143
165
|
},
|
|
144
166
|
})
|
|
145
167
|
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
children?: React.ReactNode
|
|
152
|
-
onSubmit?: SubmitHandler<StoreSwitcherFormValues>
|
|
153
|
-
} & StoreSwitcherListQuery,
|
|
154
|
-
) {
|
|
155
|
-
const { children, onSubmit, availableStores } = props
|
|
156
|
-
const context = useStoreSwitcher({ availableStores })
|
|
157
|
-
const { setValue, storeGroups } = context
|
|
168
|
+
const context: StoreSwitcherFormContextType = useMemo(
|
|
169
|
+
() => ({ storeGroups, stores, ...form }),
|
|
170
|
+
[form, storeGroups, stores],
|
|
171
|
+
)
|
|
172
|
+
const { setValue } = context
|
|
158
173
|
|
|
159
174
|
const selectedStoreGroup = useSelectedStoreGroup(context) ?? storeGroups[0]
|
|
160
175
|
const selectedStore = useSelectedStore(context)
|
|
161
176
|
const selectedCurrency = useSelectedCurrency(context)
|
|
162
177
|
|
|
163
|
-
useIsomorphicLayoutEffect(() => {
|
|
164
|
-
const currency = cookie('Magento-Content-Currency')
|
|
165
|
-
if (currency) setValue('currency', currency)
|
|
166
|
-
}, [setValue])
|
|
167
|
-
|
|
168
178
|
useIsomorphicLayoutEffect(() => {
|
|
169
179
|
const defaultStore = selectedStoreGroup.stores[0]
|
|
170
|
-
if (!selectedStore)
|
|
171
|
-
setValue('storeCode', defaultStore.store_code)
|
|
172
|
-
}
|
|
180
|
+
if (!selectedStore) setValue('storeCode', defaultStore.store_code)
|
|
173
181
|
|
|
174
182
|
const currencyCode =
|
|
175
183
|
selectedStore?.currency?.default_display_currency_code ??
|
|
176
184
|
defaultStore.currency?.default_display_currency_code
|
|
177
185
|
|
|
178
|
-
if (!selectedCurrency && currencyCode)
|
|
179
|
-
setValue('currency', currencyCode)
|
|
180
|
-
}
|
|
186
|
+
if (!selectedCurrency && currencyCode) setValue('currency', currencyCode)
|
|
181
187
|
}, [selectedCurrency, selectedStore, selectedStoreGroup.stores, setValue])
|
|
182
188
|
|
|
183
|
-
const submit = context.handleSubmit(async (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
onSubmit?.(data, event)
|
|
189
|
+
const submit = context.handleSubmit(async (formValues, event) => {
|
|
190
|
+
const formStore = context.stores.find((s) => s.store_code === formValues.storeCode)
|
|
191
|
+
const isDefaultDisplayCurrency =
|
|
192
|
+
formValues.currency === formStore?.default_display_currency_code
|
|
193
|
+
|
|
194
|
+
if (isDefaultDisplayCurrency) cookie('Magento-Content-Currency', null)
|
|
195
|
+
else cookie('Magento-Content-Currency', formValues.currency)
|
|
196
|
+
|
|
197
|
+
await onSubmit?.(formValues, event)
|
|
194
198
|
})
|
|
195
199
|
|
|
196
200
|
return (
|
|
@@ -1,44 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { SxProps, Theme } from '@mui/material'
|
|
1
|
+
import { extendableComponent, iconLanguage, IconSvg, sxx } from '@graphcommerce/next-ui'
|
|
2
|
+
import type { ButtonProps } from '@mui/material'
|
|
4
3
|
import { Button } from '@mui/material'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { StoreConfigDocument } from '../../graphql'
|
|
4
|
+
import { StoreSwitcherText, type StoreSwitcherTextProps } from './StoreSwitcherText'
|
|
5
|
+
import { useShowStoreSwitcherButton } from './useStoreSwitcherButton'
|
|
8
6
|
|
|
9
|
-
export type StoreSwitcherButtonProps =
|
|
7
|
+
export type StoreSwitcherButtonProps = ButtonProps & {
|
|
8
|
+
textProps?: StoreSwitcherTextProps
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
const name = 'StoreSwitcherButton'
|
|
12
12
|
const parts = ['root', 'avatar'] as const
|
|
13
13
|
const { classes } = extendableComponent(name, parts)
|
|
14
14
|
|
|
15
15
|
export function StoreSwitcherButton(props: StoreSwitcherButtonProps) {
|
|
16
|
-
const { sx } = props
|
|
17
|
-
|
|
18
|
-
const config = useQuery(StoreConfigDocument)
|
|
19
|
-
const country = config.data?.storeConfig?.locale?.split('_')?.[1]?.toLowerCase() ?? ''
|
|
20
|
-
const router = useRouter()
|
|
16
|
+
const { sx, textProps, ...rest } = props
|
|
21
17
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
[config.data?.storeConfig?.base_currency_code],
|
|
25
|
-
)
|
|
18
|
+
const { show, onClick } = useShowStoreSwitcherButton()
|
|
19
|
+
if (!show) return null
|
|
26
20
|
|
|
27
21
|
return (
|
|
28
22
|
<Button
|
|
29
23
|
variant='text'
|
|
30
24
|
size='medium'
|
|
31
25
|
className={classes.root}
|
|
32
|
-
onClick={
|
|
33
|
-
|
|
26
|
+
onClick={onClick}
|
|
27
|
+
startIcon={<IconSvg src={iconLanguage} />}
|
|
28
|
+
sx={sxx({ width: 'max-content' }, sx)}
|
|
29
|
+
{...rest}
|
|
34
30
|
>
|
|
35
|
-
<
|
|
36
|
-
country={country}
|
|
37
|
-
className={classes.avatar}
|
|
38
|
-
size='20px'
|
|
39
|
-
sx={{ marginRight: '10px' }}
|
|
40
|
-
/>
|
|
41
|
-
{config.data?.storeConfig?.store_name} – {currency}
|
|
31
|
+
<StoreSwitcherText {...textProps} />
|
|
42
32
|
</Button>
|
|
43
33
|
)
|
|
44
34
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { iconLanguage, IconSvg, sxx } from '@graphcommerce/next-ui'
|
|
2
|
+
import { Fab, type FabProps } from '@mui/material'
|
|
3
|
+
import { StoreSwitcherText } from './StoreSwitcherText'
|
|
4
|
+
import { useShowStoreSwitcherButton } from './useStoreSwitcherButton'
|
|
5
|
+
|
|
6
|
+
export function StoreSwitcherFab(props: FabProps) {
|
|
7
|
+
const { show, onClick } = useShowStoreSwitcherButton()
|
|
8
|
+
if (!show) return null
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Fab
|
|
12
|
+
variant='extended'
|
|
13
|
+
onClick={onClick}
|
|
14
|
+
sx={sxx({ width: 'max-content', columnGap: '3px', typography: 'body1' })}
|
|
15
|
+
{...props}
|
|
16
|
+
>
|
|
17
|
+
<IconSvg src={iconLanguage} /> <StoreSwitcherText />
|
|
18
|
+
</Fab>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
iconLanguage,
|
|
3
|
+
IconSvg,
|
|
4
|
+
MenuFabSecondaryItem,
|
|
5
|
+
type FabMenuSecondaryItemProps,
|
|
6
|
+
} from '@graphcommerce/next-ui'
|
|
7
|
+
import { Trans } from '@lingui/macro'
|
|
8
|
+
import { StoreSwitcherText, type StoreSwitcherTextProps } from './StoreSwitcherText'
|
|
9
|
+
import { useShowStoreSwitcherButton } from './useStoreSwitcherButton'
|
|
10
|
+
|
|
11
|
+
export type StoreSwitcherMenuFabSecondaryItemProps = Omit<
|
|
12
|
+
FabMenuSecondaryItemProps,
|
|
13
|
+
'children' | 'href'
|
|
14
|
+
> & {
|
|
15
|
+
textProps?: StoreSwitcherTextProps
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function StoreSwitcherMenuFabSecondaryItem(props: StoreSwitcherMenuFabSecondaryItemProps) {
|
|
19
|
+
const { sx, textProps, ...rest } = props
|
|
20
|
+
|
|
21
|
+
const { show, onClick } = useShowStoreSwitcherButton()
|
|
22
|
+
if (!show) return null
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<MenuFabSecondaryItem
|
|
26
|
+
key='service'
|
|
27
|
+
icon={<IconSvg src={iconLanguage} size='medium' />}
|
|
28
|
+
href='/switch-stores'
|
|
29
|
+
{...rest}
|
|
30
|
+
>
|
|
31
|
+
<Trans>Store Settings</Trans> <StoreSwitcherText {...textProps} /> haja ajaj a ajaj a aj
|
|
32
|
+
</MenuFabSecondaryItem>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CurrencySymbol, extendableComponent, FlagAvatar, ListFormat } from '@graphcommerce/next-ui'
|
|
2
|
+
import { Box, type SxProps, type Theme } from '@mui/material'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { useShowStoreSwitcherButton } from './useStoreSwitcherButton'
|
|
5
|
+
|
|
6
|
+
export type StoreSwitcherTextProps = {
|
|
7
|
+
items?: React.ReactNode[]
|
|
8
|
+
showFlag?: boolean
|
|
9
|
+
sx?: SxProps<Theme>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const name = 'StoreSwitcherButton'
|
|
13
|
+
const parts = ['root', 'avatar'] as const
|
|
14
|
+
const { classes } = extendableComponent(name, parts)
|
|
15
|
+
|
|
16
|
+
export function StoreSwitcherText(props: StoreSwitcherTextProps) {
|
|
17
|
+
const { items = [], showFlag = false, sx = [] } = props
|
|
18
|
+
|
|
19
|
+
const { country, multiLocale, currency, multiCurrency } = useShowStoreSwitcherButton()
|
|
20
|
+
|
|
21
|
+
const renderItems = [
|
|
22
|
+
multiLocale && (
|
|
23
|
+
<React.Fragment key='locale'>
|
|
24
|
+
{showFlag && (
|
|
25
|
+
<FlagAvatar
|
|
26
|
+
country={country}
|
|
27
|
+
className={classes.avatar}
|
|
28
|
+
size='20px'
|
|
29
|
+
sx={{ marginRight: '10px' }}
|
|
30
|
+
/>
|
|
31
|
+
)}
|
|
32
|
+
{country.toUpperCase()}
|
|
33
|
+
</React.Fragment>
|
|
34
|
+
),
|
|
35
|
+
multiCurrency && currency && (
|
|
36
|
+
<CurrencySymbol key='currency' currency={currency} currencyDisplay='symbol' />
|
|
37
|
+
),
|
|
38
|
+
...items,
|
|
39
|
+
].filter(Boolean) as React.ReactNode[]
|
|
40
|
+
|
|
41
|
+
if (renderItems.length === 0) return null
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Box component='span' sx={sx}>
|
|
45
|
+
<ListFormat type='unit' listStyle='narrow'>
|
|
46
|
+
{renderItems}
|
|
47
|
+
</ListFormat>
|
|
48
|
+
</Box>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
+
import { useCookie } from '@graphcommerce/next-ui'
|
|
3
|
+
import { useRouter } from 'next/router'
|
|
4
|
+
import { StoreConfigDocument } from '../../graphql'
|
|
5
|
+
|
|
6
|
+
export function useShowStoreSwitcherButton(options?: Record<string, never>) {
|
|
7
|
+
const config = useQuery(StoreConfigDocument)
|
|
8
|
+
const country = config.data?.storeConfig?.locale?.split('_')?.[1]?.toLowerCase() ?? ''
|
|
9
|
+
const router = useRouter()
|
|
10
|
+
const multiLocale = (router.locales?.length ?? 0) > 1
|
|
11
|
+
const multiCurrency =
|
|
12
|
+
new Set(config.data?.storeConfig?.currency?.available_currency_codes ?? []).size > 1
|
|
13
|
+
|
|
14
|
+
const [currency] = useCookie('Magento-Content-Currency')
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
show: multiLocale || multiCurrency,
|
|
18
|
+
multiCurrency,
|
|
19
|
+
country,
|
|
20
|
+
multiLocale,
|
|
21
|
+
currency: currency ?? config.data?.storeConfig?.default_display_currency_code,
|
|
22
|
+
storeName: config.data?.storeConfig?.store_name,
|
|
23
|
+
onClick: () => router.push('/switch-stores'),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -2,7 +2,6 @@ fragment StoreConfigFragment on StoreConfig {
|
|
|
2
2
|
website_name
|
|
3
3
|
store_code
|
|
4
4
|
store_name
|
|
5
|
-
|
|
6
5
|
header_logo_src
|
|
7
6
|
logo_width
|
|
8
7
|
logo_height
|
|
@@ -12,8 +11,10 @@ fragment StoreConfigFragment on StoreConfig {
|
|
|
12
11
|
|
|
13
12
|
locale
|
|
14
13
|
base_currency_code
|
|
15
|
-
|
|
16
14
|
default_display_currency_code
|
|
15
|
+
currency {
|
|
16
|
+
available_currency_codes
|
|
17
|
+
}
|
|
17
18
|
|
|
18
19
|
head_shortcut_icon
|
|
19
20
|
head_includes
|
package/index.ts
CHANGED
|
@@ -2,12 +2,12 @@ export * from './components/AttributeForm'
|
|
|
2
2
|
export * from './components/CurrencySymbol/CurrencySymbol'
|
|
3
3
|
export * from './components/GlobalHead/GlobalHead'
|
|
4
4
|
export * from './components/Money/Money'
|
|
5
|
-
export * from './graphql'
|
|
6
5
|
export * from './components/PageMeta/PageMeta'
|
|
7
|
-
export * from './components/
|
|
6
|
+
export * from './components/PriceModifiers'
|
|
7
|
+
export * from './components/StoreSwitcher'
|
|
8
|
+
export * from './components/StoreSwitcherButton'
|
|
9
|
+
export * from './graphql'
|
|
8
10
|
export * from './hooks/useFindCountry'
|
|
9
11
|
export * from './hooks/useFindRegion'
|
|
10
|
-
export * from './utils/localeToStore'
|
|
11
12
|
export * from './utils/redirectOrNotFound'
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './components/PriceModifiers'
|
|
13
|
+
export * from './utils/localeToStore'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-store",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.1.0-canary.
|
|
5
|
+
"version": "9.1.0-canary.36",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^9.1.0-canary.
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.
|
|
17
|
-
"@graphcommerce/framer-utils": "^9.1.0-canary.
|
|
18
|
-
"@graphcommerce/graphql": "^9.1.0-canary.
|
|
19
|
-
"@graphcommerce/graphql-mesh": "^9.1.0-canary.
|
|
20
|
-
"@graphcommerce/image": "^9.1.0-canary.
|
|
21
|
-
"@graphcommerce/next-ui": "^9.1.0-canary.
|
|
22
|
-
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.
|
|
23
|
-
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^9.1.0-canary.36",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.36",
|
|
17
|
+
"@graphcommerce/framer-utils": "^9.1.0-canary.36",
|
|
18
|
+
"@graphcommerce/graphql": "^9.1.0-canary.36",
|
|
19
|
+
"@graphcommerce/graphql-mesh": "^9.1.0-canary.36",
|
|
20
|
+
"@graphcommerce/image": "^9.1.0-canary.36",
|
|
21
|
+
"@graphcommerce/next-ui": "^9.1.0-canary.36",
|
|
22
|
+
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.36",
|
|
23
|
+
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.36",
|
|
24
24
|
"@lingui/core": "^4.2.1",
|
|
25
25
|
"@lingui/macro": "^4.2.1",
|
|
26
26
|
"@lingui/react": "^4.2.1",
|
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
type usePrivateQueryContext as usePrivateQueryContextType,
|
|
4
4
|
} from '@graphcommerce/graphql'
|
|
5
5
|
import type { PrivateContext } from '@graphcommerce/graphql-mesh'
|
|
6
|
+
import { useCustomerSession } from '@graphcommerce/magento-customer/hooks/useCustomerSession'
|
|
6
7
|
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
7
|
-
import { cookie } from '@graphcommerce/next-ui'
|
|
8
|
+
import { cookie, useCookie } from '@graphcommerce/next-ui'
|
|
8
9
|
|
|
9
10
|
export const config: PluginConfig = {
|
|
10
11
|
type: 'function',
|
|
@@ -27,9 +28,9 @@ export const usePrivateQueryContext: FunctionPlugin<typeof usePrivateQueryContex
|
|
|
27
28
|
prev,
|
|
28
29
|
...args
|
|
29
30
|
) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
31
|
+
const awaiting = useCustomerSession().query.loading
|
|
32
|
+
const [currencyCode] = useCookie('Magento-Content-Currency')
|
|
32
33
|
const res = prev(...args)
|
|
33
|
-
if (!currencyCode) return res
|
|
34
|
+
if (!currencyCode || awaiting) return res
|
|
34
35
|
return { ...res, currencyCode }
|
|
35
36
|
}
|