@jotul/jotul-widgets 2.0.0 → 2.1.0
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/dist/JotulWidget.js +4 -7
- package/dist/types.d.ts +5 -4
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -0
- package/package.json +1 -1
package/dist/JotulWidget.js
CHANGED
|
@@ -7,7 +7,7 @@ import { FinderSearchRowSkeleton } from './components/FinderSearchRowSkeleton';
|
|
|
7
7
|
import { DealerCardSkeleton } from './components/DealerCardSkeleton';
|
|
8
8
|
import { DEFAULT_WIDGET_LOCALE_TAG, resolveWidgetUiLocale, WIDGET_STRINGS, } from './i18n/widgetStrings';
|
|
9
9
|
import { checkWidgetAuthorization, fetchDealerById, searchLocationSuggestions, searchDealersByCoordinates, searchDealersByPostalCode, submitInquiry, } from './api';
|
|
10
|
-
import { createInquiryFormValues, getDealerId, getDealerName, getSafeWidgetErrorMessage, isDealerInSearchResult, normalizeWidgetFilterList, validateInquiryFormValues, isWidgetType, renderReadyState, } from './utils';
|
|
10
|
+
import { createInquiryFormValues, getDealerId, getDealerName, getSafeWidgetErrorMessage, isDealerInSearchResult, normalizeWidgetFilterList, normalizeDealerMarkets, validateInquiryFormValues, isWidgetType, renderReadyState, } from './utils';
|
|
11
11
|
import { inquiryCategoryLabel } from './utils/inquiryCategories';
|
|
12
12
|
import { inquiryFormValuesToApiPayload } from './utils/inquirySubmit';
|
|
13
13
|
import { useTurnstileSiteKey } from './hooks/useTurnstileSiteKey';
|
|
@@ -62,16 +62,13 @@ const MARKET_FALLBACK_CENTER = {
|
|
|
62
62
|
DE: [52.52, 13.405],
|
|
63
63
|
};
|
|
64
64
|
export function JotulWidget({ type, endpoint = '/api/jotul/widget', className, productName, locale: localeProp, market: marketProp, markets: marketsProp, scope, brands, campaignSlug, styling, button, buttonLoading, widgetRef, pageType: pageTypeProp, productId, warrantyEndpoint, submissionEndpoint = '/api/jotul/submission', turnstileSiteKey: turnstileSiteKeyProp, turnstileConfigEndpoint, }) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
return /^[A-Z]{2}$/.test(upper) ? upper : '';
|
|
68
|
-
}), [marketsProp]);
|
|
65
|
+
const apiLocaleTag = useMemo(() => (localeProp?.trim() ? localeProp.trim() : DEFAULT_WIDGET_LOCALE_TAG), [localeProp]);
|
|
66
|
+
const apiMarkets = useMemo(() => normalizeDealerMarkets(marketsProp), [marketsProp]);
|
|
69
67
|
const apiBrands = useMemo(() => normalizeWidgetFilterList(brands), [brands]);
|
|
70
68
|
const firstMarket = apiMarkets?.[0];
|
|
71
|
-
const resolvedUiLocale = useMemo(() => resolveWidgetUiLocale(localeProp
|
|
69
|
+
const resolvedUiLocale = useMemo(() => resolveWidgetUiLocale(localeProp), [localeProp]);
|
|
72
70
|
const t = WIDGET_STRINGS[resolvedUiLocale];
|
|
73
71
|
const resolvedTurnstileSiteKey = useTurnstileSiteKey(turnstileSiteKeyProp, turnstileConfigEndpoint);
|
|
74
|
-
const apiLocaleTag = useMemo(() => (localeProp?.trim() ? localeProp.trim() : DEFAULT_WIDGET_LOCALE_TAG), [localeProp]);
|
|
75
72
|
const [auth, setAuth] = useState(null);
|
|
76
73
|
const [isLoading, setIsLoading] = useState(false);
|
|
77
74
|
const [searchResult, setSearchResult] = useState(null);
|
package/dist/types.d.ts
CHANGED
|
@@ -53,9 +53,9 @@ export type LocationAutocompleteResponse = {
|
|
|
53
53
|
export type CheckWidgetAuthorizationOptions = {
|
|
54
54
|
endpoint?: string;
|
|
55
55
|
fetcher?: typeof fetch;
|
|
56
|
-
/** BCP 47 language tag (e.g. `nb-NO`, `en-US`) sent to the API as `locale
|
|
56
|
+
/** BCP 47 language tag (e.g. `nb-NO`, `en-US`) sent to the API as `locale` (UI/geocoder language only). */
|
|
57
57
|
locale?: string;
|
|
58
|
-
/** ISO 3166-1 alpha-2 market(s)
|
|
58
|
+
/** ISO 3166-1 alpha-2 market(s) (e.g. `["NO", "SE"]`) sent as `market` query params for dealer filtering. */
|
|
59
59
|
markets?: string[];
|
|
60
60
|
scope?: JotulWidgetScope;
|
|
61
61
|
brands?: string[];
|
|
@@ -85,10 +85,11 @@ export type JotulWidgetProps = {
|
|
|
85
85
|
endpoint?: string;
|
|
86
86
|
className?: string;
|
|
87
87
|
productName?: string;
|
|
88
|
+
/** BCP 47 language tag for widget UI strings (not dealer filtering). */
|
|
88
89
|
locale?: string;
|
|
89
|
-
/** ISO 3166-1 alpha-2 market code for the warranty form
|
|
90
|
+
/** ISO 3166-1 alpha-2 market code for the warranty form only. */
|
|
90
91
|
market?: string;
|
|
91
|
-
/** ISO 3166-1 alpha-2 market(s) for dealer
|
|
92
|
+
/** ISO 3166-1 alpha-2 market(s) for dealer search filtering (product page, find dealer drawer). */
|
|
92
93
|
markets?: string[];
|
|
93
94
|
scope?: JotulWidgetScope;
|
|
94
95
|
brands?: string[];
|
package/dist/utils.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare function formatDistance(dealer: DealerRecord): string | null;
|
|
|
7
7
|
export declare function isExclusiveDealer(dealer: DealerRecord): boolean;
|
|
8
8
|
/** Normalize optional widget prop arrays: undefined or empty means no filter. */
|
|
9
9
|
export declare function normalizeWidgetFilterList(values: string[] | undefined, transform?: (value: string) => string): string[] | undefined;
|
|
10
|
+
export declare function normalizeDealerMarkets(markets?: string[]): string[] | undefined;
|
|
10
11
|
export declare function getDealerId(dealer: DealerRecord): string | undefined;
|
|
11
12
|
export declare function getDealerKey(dealer: DealerRecord, index: number): string;
|
|
12
13
|
export declare function getDealerName(dealer: DealerRecord, unknownLabel: string): string;
|
package/dist/utils.js
CHANGED
|
@@ -50,6 +50,12 @@ export function normalizeWidgetFilterList(values, transform) {
|
|
|
50
50
|
.filter((value) => value.length > 0);
|
|
51
51
|
return normalized.length > 0 ? normalized : undefined;
|
|
52
52
|
}
|
|
53
|
+
export function normalizeDealerMarkets(markets) {
|
|
54
|
+
return normalizeWidgetFilterList(markets, (value) => {
|
|
55
|
+
const upper = value.toUpperCase();
|
|
56
|
+
return /^[A-Z]{2}$/.test(upper) ? upper : '';
|
|
57
|
+
});
|
|
58
|
+
}
|
|
53
59
|
export function getDealerId(dealer) {
|
|
54
60
|
return asText(dealer.dealerId) ?? asText(dealer._id) ?? undefined;
|
|
55
61
|
}
|