Skip to content

Commit 6908459

Browse files
committed
Organize the code to avoid future errors
1 parent 412e48c commit 6908459

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

manifest.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
},
2727
"mustUpdateAt": "2018-09-05",
2828
"categories": [],
29-
"registries": [
30-
"smartcheckout"
31-
],
29+
"registries": ["smartcheckout"],
3230
"settingsSchema": {},
3331
"scripts": {
3432
"postreleasy": "vtex publish -r vtex --verbose"

react/components/EditorContainer/Topbar/ContextSelectors/LocaleSelector.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,38 @@ const LocaleSelector: React.FC<Props> = ({
2626

2727
const handleChange = React.useCallback(
2828
(e: React.ChangeEvent<HTMLSelectElement>) => {
29-
setLocale(e.target.value)
30-
31-
emitter.emit('localesChanged', e.target.value, null, () => {
32-
if (editor.iframeWindow) {
33-
const searchParams = new URLSearchParams(
34-
editor.iframeWindow.location.search
35-
)
36-
37-
const bindingQueryString = searchParams.get('__bindingAddress')
29+
editor.setMode('disabled')
3830

39-
editor.iframeWindow.location.search = `__bindingAddress=${bindingQueryString}&__localeAddress=${e.target.value}&__siteEditor=true`
31+
setLocale(e?.target?.value)
32+
33+
emitter.emit(
34+
'localesChanged',
35+
e?.target?.value,
36+
null,
37+
(locale: string) => {
38+
let bindingQueryString
39+
40+
if (editor.iframeWindow) {
41+
const searchParams = new URLSearchParams(
42+
editor?.iframeWindow?.location.search
43+
)
44+
45+
const bindingAddress = searchParams.get('__bindingAddress')
46+
47+
if (bindingAddress) {
48+
bindingQueryString = `__bindingAddress=${decodeURIComponent(
49+
bindingAddress
50+
)}`
51+
}
52+
53+
if (e?.target?.value) {
54+
editor.iframeWindow.location.search = `${bindingQueryString}&__locale=${e.target.value}&__siteEditor=true`
55+
} else {
56+
editor.iframeWindow.location.search = `${bindingQueryString}&__locale=${locale}&__siteEditor=true`
57+
}
58+
}
4059
}
41-
})
42-
43-
editor.setMode('disabled')
60+
)
4461
},
4562
[emitter]
4663
)

react/components/EditorContainer/Topbar/UrlInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const UrlInput = () => {
1313
const SEARCH_QUERIES_TO_HIDE = [
1414
'__siteEditor',
1515
'__bindingAddress',
16-
'__localeAddress',
16+
'__locale',
1717
]
1818

1919
SEARCH_QUERIES_TO_HIDE.forEach(query => {
2020
searchParams.delete(query)
2121
})
2222

2323
if (searchParams.toString().length) {
24-
return pathname + `?${searchParams.toString()}`
24+
return pathname + decodeURIComponent(`?${searchParams.toString()}`)
2525
}
2626

2727
return pathname

0 commit comments

Comments
 (0)