@salifbiaye/create-boutique 0.3.3 → 0.3.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salifbiaye/create-boutique",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Usine à Boutiques : génère un projet complet (backend Medusa + une boutique Next.js par campagne) prêt pour docker compose",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/salifbiaye/create-boutique.git" },
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { forwardRef, useImperativeHandle, useMemo, useRef } from "react"
|
|
2
2
|
|
|
3
|
+
import { useLocale, useT } from "@lib/boutique/i18n-client"
|
|
3
4
|
import NativeSelect, {
|
|
4
5
|
NativeSelectProps,
|
|
5
6
|
} from "@modules/common/components/native-select"
|
|
6
7
|
import { HttpTypes } from "@medusajs/types"
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Liste des pays de la région : noms dans la langue du site (« Sénégal », « Côte d'Ivoire »), triés par ordre
|
|
11
|
+
* alphabétique, pays de la boutique en tête. (Le starter affichait les noms anglais de Medusa, non triés.)
|
|
12
|
+
*/
|
|
8
13
|
const CountrySelect = forwardRef<
|
|
9
14
|
HTMLSelectElement,
|
|
10
15
|
NativeSelectProps & {
|
|
11
16
|
region?: HttpTypes.StoreRegion
|
|
12
17
|
}
|
|
13
|
-
>(({ placeholder = "
|
|
18
|
+
>(({ placeholder = "form.country", region, defaultValue, ...props }, ref) => {
|
|
14
19
|
const innerRef = useRef<HTMLSelectElement>(null)
|
|
20
|
+
const t = useT()
|
|
21
|
+
const locale = useLocale()
|
|
15
22
|
|
|
16
23
|
useImperativeHandle<HTMLSelectElement | null, HTMLSelectElement | null>(
|
|
17
24
|
ref,
|
|
@@ -19,25 +26,36 @@ const CountrySelect = forwardRef<
|
|
|
19
26
|
)
|
|
20
27
|
|
|
21
28
|
const countryOptions = useMemo(() => {
|
|
22
|
-
if (!region) {
|
|
29
|
+
if (!region?.countries) {
|
|
23
30
|
return []
|
|
24
31
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
let names: Intl.DisplayNames | undefined
|
|
33
|
+
try {
|
|
34
|
+
names = new Intl.DisplayNames([locale], { type: "region" })
|
|
35
|
+
} catch {
|
|
36
|
+
names = undefined
|
|
37
|
+
}
|
|
38
|
+
const home = (locale.split("-")[1] ?? "").toLowerCase()
|
|
39
|
+
const options = region.countries
|
|
40
|
+
.filter((c) => c.iso_2)
|
|
41
|
+
.map((c) => ({
|
|
42
|
+
value: c.iso_2!,
|
|
43
|
+
label: names?.of(c.iso_2!.toUpperCase()) ?? c.display_name ?? c.iso_2!,
|
|
44
|
+
}))
|
|
45
|
+
.sort((a, b) => a.label.localeCompare(b.label, locale, { sensitivity: "base" }))
|
|
46
|
+
const first = options.find((o) => o.value === home)
|
|
47
|
+
return first ? [first, ...options.filter((o) => o !== first)] : options
|
|
48
|
+
}, [region, locale])
|
|
31
49
|
|
|
32
50
|
return (
|
|
33
51
|
<NativeSelect
|
|
34
52
|
ref={innerRef}
|
|
35
|
-
placeholder={placeholder}
|
|
53
|
+
placeholder={t(placeholder)}
|
|
36
54
|
defaultValue={defaultValue}
|
|
37
55
|
{...props}
|
|
38
56
|
>
|
|
39
|
-
{countryOptions
|
|
40
|
-
<option key={
|
|
57
|
+
{countryOptions.map(({ value, label }) => (
|
|
58
|
+
<option key={value} value={value}>
|
|
41
59
|
{label}
|
|
42
60
|
</option>
|
|
43
61
|
))}
|