@envive-ai/react-hooks 0.1.4 → 0.1.5
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/adapters/amplitude/index.cjs +2 -2
- package/dist/adapters/amplitude/index.js +2 -2
- package/dist/application/config/index.cjs +3 -3
- package/dist/application/config/index.js +3 -3
- package/dist/application/models/graphql/index.cjs +2 -2
- package/dist/application/models/graphql/index.js +2 -2
- package/dist/application/models/index.cjs +2 -2
- package/dist/application/models/index.d.cts +1 -1
- package/dist/application/models/index.d.ts +1 -1
- package/dist/application/models/index.js +2 -2
- package/dist/application/service/index.cjs +3 -2
- package/dist/application/service/index.d.cts +18 -4
- package/dist/application/service/index.d.ts +18 -4
- package/dist/application/service/index.js +3 -3
- package/dist/application/utils/index.cjs +2 -2
- package/dist/application/utils/index.d.cts +5 -5
- package/dist/application/utils/index.d.ts +5 -5
- package/dist/application/utils/index.js +2 -2
- package/dist/atomStore-ONYy0XuA.d.cts +24 -0
- package/dist/atomStore-kOKiEcNl.d.ts +24 -0
- package/dist/atoms/app/index.cjs +2 -2
- package/dist/atoms/app/index.d.cts +2 -2
- package/dist/atoms/app/index.d.ts +3 -3
- package/dist/atoms/app/index.js +2 -2
- package/dist/atoms/atomStore/index.d.cts +2 -24
- package/dist/atoms/atomStore/index.d.ts +2 -24
- package/dist/atoms/chat/index.cjs +2 -2
- package/dist/atoms/chat/index.d.cts +27 -27
- package/dist/atoms/chat/index.d.ts +27 -27
- package/dist/atoms/chat/index.js +2 -2
- package/dist/atoms/globalSearch/index.d.cts +5 -5
- package/dist/atoms/globalSearch/index.d.ts +6 -6
- package/dist/atoms/org/index.cjs +3 -2
- package/dist/atoms/org/index.d.cts +29 -26
- package/dist/atoms/org/index.d.ts +29 -26
- package/dist/atoms/org/index.js +3 -3
- package/dist/atoms/search/index.cjs +2 -2
- package/dist/atoms/search/index.d.cts +2 -2
- package/dist/atoms/search/index.d.ts +2 -2
- package/dist/atoms/search/index.js +2 -2
- package/dist/{bandolier-B76-OE75.cjs → bandolier-Da4wt6sm.cjs} +10 -10
- package/dist/{bandolier-DRn_x1g1.js → bandolier-DzEmYWcz.js} +10 -10
- package/dist/{carpe-kHi4RLB5.cjs → carpe-AXipz0Xl.cjs} +10 -10
- package/dist/{carpe-qrSU99gq.js → carpe-CaUKwcEa.js} +10 -10
- package/dist/{chat-CLJ4NWcN.js → chat-CHmD79E1.js} +1 -1
- package/dist/{chat-BgONoYU7.cjs → chat-_NzpO_Hn.cjs} +1 -1
- package/dist/{components-BKZbet67.cjs → components-D0XDRcaN.cjs} +1 -1
- package/dist/{components-CV1fhAkj.js → components-Dl-TMD9k.js} +1 -1
- package/dist/config/locators/components/chat/index.cjs +1 -1
- package/dist/config/locators/components/chat/index.d.cts +1 -1
- package/dist/config/locators/components/chat/index.d.ts +1 -1
- package/dist/config/locators/components/chat/index.js +1 -1
- package/dist/config/locators/components/chat/variants/index.d.cts +1 -1
- package/dist/config/locators/components/index.cjs +1 -1
- package/dist/config/locators/components/index.d.cts +1 -1
- package/dist/config/locators/components/index.d.ts +1 -1
- package/dist/config/locators/components/index.js +1 -1
- package/dist/config/locators/components/search/index.d.ts +1 -1
- package/dist/config/locators/index.cjs +4 -4
- package/dist/config/locators/index.d.cts +2 -2
- package/dist/config/locators/index.d.ts +3 -3
- package/dist/config/locators/index.js +4 -4
- package/dist/contexts/index.cjs +2 -2
- package/dist/contexts/index.d.cts +4 -72
- package/dist/contexts/index.d.ts +4 -72
- package/dist/contexts/index.js +2 -2
- package/dist/contexts-CtRlNXaS.js +7674 -0
- package/dist/contexts-CtgmnYNn.cjs +9088 -0
- package/dist/{coterie-yQ-_JXSw.cjs → coterie--MGvWeVh.cjs} +10 -10
- package/dist/{coterie-mMirPcHP.js → coterie-oKHAT0lx.js} +10 -10
- package/dist/{custservice-types-C83itZmy.cjs → custservice-types-C8-9vKWb.cjs} +1 -1
- package/dist/{custservice-types-DPQ-4TI6.js → custservice-types-CamCiXjq.js} +1 -1
- package/dist/default-B4fINY5_.cjs +4 -0
- package/dist/default-BrTQxA0c.js +4 -0
- package/dist/{default-8Jfv8ehQ.cjs → default-C3LrcbZB.cjs} +2 -2
- package/dist/{default-C8PQf-38.js → default-CXkYrLEr.js} +2 -2
- package/dist/{divIds-CWkntTsx.js → divIds-0Vj9g-fM.js} +1 -1
- package/dist/{divIds-DEL_-qU0.cjs → divIds-CjceLRD9.cjs} +1 -1
- package/dist/{dreamlandBaby-cG0HM9bt.js → dreamlandBaby-BEqt0eKF.js} +10 -10
- package/dist/{dreamlandBaby-DHltv12Z.cjs → dreamlandBaby-DBDjEJCc.cjs} +10 -10
- package/dist/{embedded--2L0F4b5.cjs → embedded-B5Wi9g0T.cjs} +1 -1
- package/dist/{embedded-C5uJqmuD.js → embedded-_cLpd6FK.js} +1 -1
- package/dist/events/index.d.cts +1 -1
- package/dist/{fiveCbd-Cvnwh03g.cjs → fiveCbd-CdqNt16h.cjs} +10 -10
- package/dist/{fiveCbd-DhYMlsf9.js → fiveCbd-D6B-sgnX.js} +10 -10
- package/dist/{forLoveAndLemons-DR6a1zjJ.cjs → forLoveAndLemons-C7GsJG7f.cjs} +6 -6
- package/dist/{forLoveAndLemons-C8DuUexW.js → forLoveAndLemons-gNDlMtPR.js} +6 -6
- package/dist/{greenpan-B4Pu65kV.js → greenpan-B5AaW4M_.js} +10 -10
- package/dist/{greenpan-BL5p6j7f.cjs → greenpan-DrORpYms.cjs} +10 -10
- package/dist/{grooveLife-DjKWHoN3.cjs → grooveLife-BJqsfH2H.cjs} +10 -10
- package/dist/{grooveLife-JK0TyaPz.js → grooveLife-xIUmDM8s.js} +10 -10
- package/dist/{homegrownCannabis-ZnfCqW-m.cjs → homegrownCannabis-8TZ21u6L.cjs} +10 -10
- package/dist/{homegrownCannabis-DxqSDkmS.js → homegrownCannabis-BtMuEvbZ.js} +10 -10
- package/dist/hooks/index.cjs +3 -5
- package/dist/hooks/index.d.cts +19 -74
- package/dist/hooks/index.d.ts +15 -70
- package/dist/hooks/index.js +3 -3
- package/dist/index-BTK5uzs6.d.cts +1 -1
- package/dist/{index-jBATkcc_.d.cts → index-BdNKc2ix.d.cts} +1 -1
- package/dist/{index-C62lPpy4.d.cts → index-BrXuc_Ck.d.cts} +1 -1
- package/dist/index-BzgkfbNO.d.cts +1 -1
- package/dist/index-CKUpnyJQ.d.ts +72 -0
- package/dist/{index-DPx8s5YH.d.ts → index-CSIOQD-A.d.ts} +1 -1
- package/dist/{index-C_C0tLeD.d.ts → index-CbJZOEU4.d.ts} +31 -31
- package/dist/{index-CExtydIH.d.ts → index-Cr2y08f1.d.ts} +1 -1
- package/dist/{index-CNsGWfS6.d.cts → index-DXpgMVpp.d.ts} +7 -7
- package/dist/index-Dxpscrvz.d.ts +1 -1
- package/dist/{index-CYtsPztZ.d.cts → index-K2kNsOTw.d.cts} +31 -31
- package/dist/index-VHFMGkO-.d.cts +72 -0
- package/dist/index-aNW5V9fh.d.cts +749 -0
- package/dist/interceptors/index.cjs +2 -2
- package/dist/interceptors/index.d.cts +2 -2
- package/dist/interceptors/index.d.ts +1 -1
- package/dist/interceptors/index.js +2 -2
- package/dist/{jackArcher-mGkojXek.cjs → jackArcher-WtkbLBZj.cjs} +10 -10
- package/dist/{jackArcher-CXf_IAmC.js → jackArcher-sO9EbgrZ.js} +10 -10
- package/dist/{jordanCraig-Dv8pVCiS.cjs → jordanCraig-471FcgqF.cjs} +10 -10
- package/dist/{jordanCraig-BvCvPRoR.js → jordanCraig-DNOncplU.js} +10 -10
- package/dist/{kindredBravely-UQP7wiNu.cjs → kindredBravely-BlLyHGMX.cjs} +9 -9
- package/dist/{kindredBravely-X8F_LNph.js → kindredBravely-cqZ4OvXp.js} +9 -9
- package/dist/{kutFromTheKloth-BhYKk3CN.cjs → kutFromTheKloth-3mOIryvt.cjs} +10 -10
- package/dist/{kutFromTheKloth-D1xsTSJr.js → kutFromTheKloth-DtVNCMKa.js} +10 -10
- package/dist/{larryAndSerges-1411NuZa.cjs → larryAndSerges-88Bvq-Us.cjs} +7 -7
- package/dist/{larryAndSerges-DVIRLItu.js → larryAndSerges-cvak6May.js} +7 -7
- package/dist/{leapsAndRebounds-BJ8mwr33.js → leapsAndRebounds-Dmf8eUPq.js} +10 -10
- package/dist/{leapsAndRebounds-UcP9EJVO.cjs → leapsAndRebounds-iWKc923H.cjs} +10 -10
- package/dist/{longevityrx-Cp6wleWr.js → longevityrx-BTMI9vn-.js} +10 -10
- package/dist/{longevityrx-BFSv9GF5.cjs → longevityrx-CobPyigd.cjs} +10 -10
- package/dist/{lookOptic-KieSqskd.cjs → lookOptic-C4H_c0JZ.cjs} +10 -10
- package/dist/{lookOptic-BGhU4910.js → lookOptic-Jwf7EAU8.js} +10 -10
- package/dist/{mantraBrand-CHQw-0nw.cjs → mantraBrand-CySGqbn6.cjs} +10 -10
- package/dist/{mantraBrand-DrqG9uqO.js → mantraBrand-DoaVj837.js} +10 -10
- package/dist/{medterra-CLG6Co1C.cjs → medterra-BnZ5p27n.cjs} +10 -10
- package/dist/{medterra-D8ZX9NZC.js → medterra-DaICcPPp.js} +10 -10
- package/dist/{modells-CAfqOCW4.js → modells-CZ1L6dD_.js} +10 -10
- package/dist/{modells-BzyPwN2m.cjs → modells-DF0SndHr.cjs} +10 -10
- package/dist/{nodeSelector-BiCDowlK.d.ts → nodeSelector-DybpVr-i.d.ts} +1 -1
- package/dist/{nodeSelector-B3bPtEjX.d.cts → nodeSelector-vKB44CDB.d.cts} +1 -1
- package/dist/orgConfigResults-BL0XBA6x.d.cts +1 -1
- package/dist/{pressedFloral-DULBuQwR.cjs → pressedFloral-B3t2cYzs.cjs} +10 -10
- package/dist/{pressedFloral-Dp-7Fk3S.js → pressedFloral-Dsws2Kfb.js} +10 -10
- package/dist/{search-filter-types-BNTLVXqQ.d.cts → search-filter-types-9rTb3jMj.d.cts} +1 -1
- package/dist/{search-filter-types-DkmH1TxJ.d.ts → search-filter-types-C-zZSpGo.d.ts} +1 -1
- package/dist/{skinPerfection-Cd3XZ6By.cjs → skinPerfection-CILQM2bR.cjs} +10 -10
- package/dist/{skinPerfection-BxuYCeJX.js → skinPerfection-DmQCntRf.js} +10 -10
- package/dist/{snapSupplements-Bf6htPM0.js → snapSupplements--X_v0KRM.js} +10 -10
- package/dist/{snapSupplements-ZFnXyMuZ.cjs → snapSupplements-Djuzl0Ed.cjs} +10 -10
- package/dist/{spanx-Cyd4qDlK.cjs → spanx-Bo81yXSF.cjs} +11 -11
- package/dist/{spanx-CwDPQaGj.js → spanx-DauxB8KE.js} +11 -11
- package/dist/{spanxStaging-ijbYnHzr.cjs → spanxStaging-BucYQvR1.cjs} +11 -11
- package/dist/{spanxStaging-D43nyAGy.js → spanxStaging-CfXUukdP.js} +11 -11
- package/dist/{suggestionBarV2-types-Dc4-zJlV.cjs → suggestionBarV2-types-B3lwrENK.cjs} +1 -1
- package/dist/{suggestionBarV2-types-CwOXzIKq.js → suggestionBarV2-types-Penx3Y67.js} +1 -1
- package/dist/{supergoop-BnbFG7hm.cjs → supergoop-8qa_NV3F.cjs} +11 -11
- package/dist/{supergoop-CY043wIg.js → supergoop-DOaui-A6.js} +11 -11
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types-CGC6Oozp.cjs +231 -0
- package/dist/types-CnTCkyvK.js +177 -0
- package/dist/{uniqueVintage-Cui74mlJ.js → uniqueVintage-BWkDgt1z.js} +10 -10
- package/dist/{uniqueVintage-R2Jcu1y1.cjs → uniqueVintage-DAne8XcL.cjs} +10 -10
- package/dist/{variant-CKVRF2-W.d.ts → variant-CC1nrywd.d.ts} +3 -3
- package/dist/{variant-raYuOP4L.d.cts → variant-CQTuQQSq.d.cts} +3 -3
- package/dist/{venaCbd-r-IxEVc1.cjs → venaCbd-B1HO_Pkr.cjs} +10 -10
- package/dist/{venaCbd-o5_vOp4e.js → venaCbd-CnByO-5R.js} +10 -10
- package/dist/{westonJonBoucher-C95EuCl-.js → westonJonBoucher-BAGXegsX.js} +10 -10
- package/dist/{westonJonBoucher-DjGEW3ZB.cjs → westonJonBoucher-BRfHWMbs.cjs} +10 -10
- package/dist/{wineEnthusiast-DvfcV5B3.cjs → wineEnthusiast-DW8JVwV8.cjs} +10 -10
- package/dist/{wineEnthusiast-DeTFY8Gm.js → wineEnthusiast-EJbhMeKQ.js} +10 -10
- package/dist/{wolfMattress-BjGnGKjP.cjs → wolfMattress-B6INZNRJ.cjs} +10 -10
- package/dist/{wolfMattress-6xPfOJt3.js → wolfMattress-D9P7ErH_.js} +10 -10
- package/dist/{wolfTactical-C_F9-oPX.js → wolfTactical-C5Pupi3J.js} +10 -10
- package/dist/{wolfTactical-Bi3WZu0m.cjs → wolfTactical-TMthZM93.cjs} +10 -10
- package/package.json +2 -1
- package/src/application/models/supportedOrgs.ts +1 -1
- package/src/application/service/graphqlConfigService.ts +59 -0
- package/src/application/service/index.ts +1 -0
- package/src/atoms/org/graphqlConfig.ts +14 -3
- package/src/atoms/org/index.ts +7 -7
- package/src/atoms/org/merchantCss.ts +5 -2
- package/src/atoms/org/org.ts +2 -42
- package/src/atoms/search/searchAPI.ts +52 -42
- package/src/hooks/index.ts +1 -3
- package/src/hooks/useDynamicVariants.ts +48 -32
- package/src/hooks/useFileUpload.ts +1 -1
- package/src/hooks/useHideElements.ts +21 -18
- package/src/hooks/useImageResolver.ts +16 -8
- package/src/hooks/useNewOrgConfig.ts +80 -0
- package/dist/contexts-CQDwe3rK.cjs +0 -14333
- package/dist/contexts-e2sM-B9g.js +0 -12919
- package/dist/default-LukSiCz1.js +0 -4
- package/dist/default-rJSJ887P.cjs +0 -4
- package/dist/index-BfuO9b0Q.d.ts +0 -749
- package/dist/types-BF_CJeck.js +0 -177
- package/dist/types-CNH4sfF-.cjs +0 -231
- package/src/hooks/useHorizontalScrollAnimation.ts +0 -115
- package/src/hooks/useReducedMotionWithOverride.ts +0 -15
- package/src/hooks/useSnapControl.ts +0 -155
- /package/dist/{locators-lQMJj830.cjs → locators-CugndTUM.cjs} +0 -0
- /package/dist/{locators-Dc5ZT0aF.js → locators-DnKpajbY.js} +0 -0
package/src/atoms/org/org.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { ContextSourceEnum } from "@spiffy-ai/commerce-api-client";
|
|
|
4
4
|
import { atom } from "jotai";
|
|
5
5
|
import { atomWithStorage, createJSONStorage } from "jotai/utils";
|
|
6
6
|
import CommerceApiClient from "src/adapters/spiffy/commerce/api";
|
|
7
|
-
import { GraphQLClient } from "src/adapters/spiffy/commerce/graphql";
|
|
8
7
|
import { OrgConfig } from "src/application/models/api/orgConfigResults";
|
|
9
8
|
import { FeatureFlagService } from "src/application/service/featureFlagService";
|
|
10
9
|
import { UserIdentityService } from "src/application/service/userIdentityService";
|
|
@@ -12,7 +11,7 @@ import { AtomStore, getAtomStore } from "src/atoms/atomStore/atomStore";
|
|
|
12
11
|
import { PerfMetricsEvents, logPerfMetricAtom } from "src/atoms/chat";
|
|
13
12
|
import { orgAnalyticsConfigAtom } from "src/atoms/org/orgAnalyticsConfig";
|
|
14
13
|
import { colorsConfigAtom, frontendConfigAtom } from "./graphqlConfig";
|
|
15
|
-
import {
|
|
14
|
+
import { GraphQLConfigService } from "src/application/service/graphqlConfigService";
|
|
16
15
|
import {
|
|
17
16
|
orgLevelApiKeyAtom,
|
|
18
17
|
orgShortNameAtom as enviveOrgShortNameAtom,
|
|
@@ -146,45 +145,6 @@ export const resetStoredOrgConfigAtom = () => {
|
|
|
146
145
|
atomStore.set(storedOrgConfigAtom, {});
|
|
147
146
|
};
|
|
148
147
|
|
|
149
|
-
// eslint-disable-next-line
|
|
150
|
-
const getGraphQLConfig = async (atomStore: AtomStore) => {
|
|
151
|
-
try {
|
|
152
|
-
Logger.logDebug("getGraphQLConfig: Starting GraphQL client fetch");
|
|
153
|
-
const { colorsConfig, frontendConfig } =
|
|
154
|
-
(await GraphQLClient.getColorsAndFrontendConfig()) ?? {};
|
|
155
|
-
|
|
156
|
-
Logger.logDebug("getGraphQLConfig: GraphQL fetch completed", {
|
|
157
|
-
hasColorsConfig: !!colorsConfig,
|
|
158
|
-
hasFrontendConfig: !!frontendConfig,
|
|
159
|
-
frontendConfigKeys: frontendConfig ? Object.keys(frontendConfig) : [],
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const rawFrontendConfig = atomStore.get(frontendConfigAtom);
|
|
163
|
-
|
|
164
|
-
atomStore.set(colorsConfigAtom, colorsConfig);
|
|
165
|
-
|
|
166
|
-
atomStore.set(frontendConfigAtom, {
|
|
167
|
-
...rawFrontendConfig,
|
|
168
|
-
pageVariants: frontendConfig?.pageVariants,
|
|
169
|
-
mountingConfigs: frontendConfig?.mountingConfigs,
|
|
170
|
-
widgetConfigs: frontendConfig?.widgetConfigs,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
Logger.logDebug("getGraphQLConfig: Starting UI config fetch");
|
|
174
|
-
await getOrgUIConfig(
|
|
175
|
-
frontendConfig?.uiConfigs,
|
|
176
|
-
frontendConfig?.merchantOverrideCss
|
|
177
|
-
);
|
|
178
|
-
Logger.logDebug("getGraphQLConfig: UI config fetch completed");
|
|
179
|
-
} catch (error) {
|
|
180
|
-
Logger.logError(
|
|
181
|
-
"getGraphQLConfig: Error during GraphQL config fetch",
|
|
182
|
-
error
|
|
183
|
-
);
|
|
184
|
-
throw error; // Re-throw to be caught by the caller
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
148
|
/**
|
|
189
149
|
* This function is used to return an orgConfig corresponding to a given API key
|
|
190
150
|
*
|
|
@@ -256,7 +216,7 @@ export const getAsyncOrgConfig = async (
|
|
|
256
216
|
|
|
257
217
|
try {
|
|
258
218
|
Logger.logDebug("getAsyncOrgConfig: Starting GraphQL config fetch");
|
|
259
|
-
await
|
|
219
|
+
await GraphQLConfigService.fetchAndSetGraphQLConfig(atomStore);
|
|
260
220
|
Logger.logDebug(
|
|
261
221
|
"getAsyncOrgConfig: GraphQL config fetch completed successfully"
|
|
262
222
|
);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { atom } from
|
|
2
|
-
import { SearchResult, SearchParams } from
|
|
3
|
-
import SearchService from
|
|
4
|
-
import { ProductSorting } from
|
|
5
|
-
import { ProductFilters } from
|
|
6
|
-
import { ProductSorter } from
|
|
7
|
-
import { orgUIConfigAtom } from
|
|
1
|
+
import { atom } from "jotai";
|
|
2
|
+
import { SearchResult, SearchParams } from "src/application/models/api/search";
|
|
3
|
+
import SearchService from "src/application/service/searchService";
|
|
4
|
+
import { ProductSorting } from "./types";
|
|
5
|
+
import { ProductFilters } from "./productFilters";
|
|
6
|
+
import { ProductSorter } from "./productSorter";
|
|
7
|
+
import { orgUIConfigAtom } from "../org";
|
|
8
8
|
|
|
9
9
|
export type SelectedFilterOption = {
|
|
10
10
|
id: string; // "filterId:filterItemId" - maintains backward compatibility for comparisons
|
|
@@ -27,13 +27,15 @@ export const searchAtom = atom<SearchState>({
|
|
|
27
27
|
lastQuery: null,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
export const searchProductSortingAtom = atom<ProductSorting>(
|
|
30
|
+
export const searchProductSortingAtom = atom<ProductSorting>(
|
|
31
|
+
ProductSorting.FEATURED
|
|
32
|
+
);
|
|
31
33
|
export const searchSelectedFiltersAtom = atom<SelectedFilterOption[]>([]);
|
|
32
34
|
|
|
33
35
|
export const createFilterOption = (
|
|
34
36
|
filterId: string,
|
|
35
37
|
filterItemId: string,
|
|
36
|
-
displayName: string
|
|
38
|
+
displayName: string
|
|
37
39
|
): SelectedFilterOption => ({
|
|
38
40
|
id: `${filterId}:${filterItemId}`,
|
|
39
41
|
displayName,
|
|
@@ -53,7 +55,7 @@ export const searchParamsAtom = atom(
|
|
|
53
55
|
(get) => get(internalSearchParamsAtom),
|
|
54
56
|
(_, set, value: { id: string | null; query: string | null }) => {
|
|
55
57
|
set(internalSearchParamsAtom, value);
|
|
56
|
-
}
|
|
58
|
+
}
|
|
57
59
|
);
|
|
58
60
|
export const internalSearchSystemStateAtom = atom<boolean>(false);
|
|
59
61
|
|
|
@@ -65,9 +67,9 @@ export const searchSystemAtom = atom(
|
|
|
65
67
|
}
|
|
66
68
|
const stateChangeHandler = () => {
|
|
67
69
|
const params = new URLSearchParams(window.location.search);
|
|
68
|
-
if (params.get(
|
|
69
|
-
const id = params.get(
|
|
70
|
-
const query = params.get(
|
|
70
|
+
if (params.get("es") === "true") {
|
|
71
|
+
const id = params.get("esi");
|
|
72
|
+
const query = params.get("esq");
|
|
71
73
|
set(searchParamsAtom, { id, query });
|
|
72
74
|
} else {
|
|
73
75
|
set(searchParamsAtom, { id: null, query: null });
|
|
@@ -75,14 +77,14 @@ export const searchSystemAtom = atom(
|
|
|
75
77
|
};
|
|
76
78
|
if (value) {
|
|
77
79
|
set(internalSearchSystemStateAtom, true);
|
|
78
|
-
window.addEventListener(
|
|
80
|
+
window.addEventListener("popstate", stateChangeHandler);
|
|
79
81
|
// Also trigger the hash change handler to set the initial state
|
|
80
82
|
stateChangeHandler();
|
|
81
83
|
} else {
|
|
82
84
|
set(internalSearchSystemStateAtom, false);
|
|
83
|
-
window.removeEventListener(
|
|
85
|
+
window.removeEventListener("popstate", stateChangeHandler);
|
|
84
86
|
}
|
|
85
|
-
}
|
|
87
|
+
}
|
|
86
88
|
);
|
|
87
89
|
|
|
88
90
|
export const filteredSearchProductsAtom = atom((get) => {
|
|
@@ -91,13 +93,13 @@ export const filteredSearchProductsAtom = atom((get) => {
|
|
|
91
93
|
const selectedFilters = get(searchSelectedFiltersAtom);
|
|
92
94
|
const orgConfig = get(orgUIConfigAtom);
|
|
93
95
|
|
|
94
|
-
if (!searchData?.products) return [];
|
|
96
|
+
if (!searchData?.products || !orgConfig?.searchConfig) return [];
|
|
95
97
|
|
|
96
98
|
const filteredProducts = ProductFilters.filterProducts(
|
|
97
99
|
searchData.products,
|
|
98
100
|
orgConfig.searchConfig.searchFilterConfig,
|
|
99
101
|
selectedFilters,
|
|
100
|
-
orgConfig.searchConfig.additiveDynamicFilters
|
|
102
|
+
orgConfig.searchConfig.additiveDynamicFilters
|
|
101
103
|
);
|
|
102
104
|
|
|
103
105
|
return ProductSorter.sort(filteredProducts, sorting);
|
|
@@ -108,29 +110,35 @@ export const searchFiltersAtom = atom((get) => {
|
|
|
108
110
|
const selectedFilters = get(searchSelectedFiltersAtom);
|
|
109
111
|
const orgConfig = get(orgUIConfigAtom);
|
|
110
112
|
|
|
111
|
-
if (!searchData?.products) return [];
|
|
113
|
+
if (!searchData?.products || !orgConfig?.searchConfig) return [];
|
|
112
114
|
|
|
113
115
|
return ProductFilters.getFiltersForProducts(
|
|
114
116
|
searchData.products,
|
|
115
117
|
orgConfig.searchConfig.searchFilterConfig,
|
|
116
|
-
selectedFilters
|
|
118
|
+
selectedFilters
|
|
117
119
|
);
|
|
118
120
|
});
|
|
119
121
|
|
|
120
|
-
export const addSearchFilterAtom = atom(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
export const addSearchFilterAtom = atom(
|
|
123
|
+
null,
|
|
124
|
+
(get, set, filter: SelectedFilterOption) => {
|
|
125
|
+
const current = get(searchSelectedFiltersAtom);
|
|
126
|
+
if (!current.some((f) => f.id === filter.id)) {
|
|
127
|
+
set(searchSelectedFiltersAtom, [...current, filter]);
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
|
-
|
|
130
|
+
);
|
|
126
131
|
|
|
127
|
-
export const removeSearchFilterAtom = atom(
|
|
128
|
-
|
|
129
|
-
set
|
|
130
|
-
searchSelectedFiltersAtom
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
export const removeSearchFilterAtom = atom(
|
|
133
|
+
null,
|
|
134
|
+
(get, set, filterId: string) => {
|
|
135
|
+
const current = get(searchSelectedFiltersAtom);
|
|
136
|
+
set(
|
|
137
|
+
searchSelectedFiltersAtom,
|
|
138
|
+
current.filter((f) => f.id !== filterId)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
);
|
|
134
142
|
|
|
135
143
|
export const clearSearchFiltersAtom = atom(null, (_, set) => {
|
|
136
144
|
set(searchSelectedFiltersAtom, []);
|
|
@@ -141,28 +149,29 @@ export const performSearchAtom = atom(
|
|
|
141
149
|
async (get, set, params: SearchParams, allowRedirect = false) => {
|
|
142
150
|
const currentState = get(searchAtom);
|
|
143
151
|
const orgUIConfig = get(orgUIConfigAtom);
|
|
144
|
-
const redirectSearchResultsUrl =
|
|
152
|
+
const redirectSearchResultsUrl =
|
|
153
|
+
orgUIConfig?.searchConfig?.redirectSearchResultsUrl;
|
|
145
154
|
|
|
146
155
|
if (allowRedirect && redirectSearchResultsUrl) {
|
|
147
156
|
const redirectUrl = new URL(redirectSearchResultsUrl);
|
|
148
|
-
redirectUrl.searchParams.set(
|
|
149
|
-
redirectUrl.searchParams.set(
|
|
157
|
+
redirectUrl.searchParams.set("es", "true");
|
|
158
|
+
redirectUrl.searchParams.set("esq", params.query);
|
|
150
159
|
window.location.href = redirectUrl.toString();
|
|
151
160
|
} else {
|
|
152
161
|
// Update URL and manually trigger state change (since pushState doesn't trigger popstate)
|
|
153
162
|
const url = new URL(window.location.href);
|
|
154
|
-
url.searchParams.set(
|
|
155
|
-
url.searchParams.set(
|
|
156
|
-
window.history.pushState({},
|
|
163
|
+
url.searchParams.set("es", "true");
|
|
164
|
+
url.searchParams.set("esq", params.query);
|
|
165
|
+
window.history.pushState({}, "", url);
|
|
157
166
|
|
|
158
167
|
// Manually trigger page variant re-evaluation by dispatching a popstate event
|
|
159
168
|
// This ensures the page variant system detects the URL change and mounts search results
|
|
160
|
-
window.dispatchEvent(new PopStateEvent(
|
|
169
|
+
window.dispatchEvent(new PopStateEvent("popstate", { state: {} }));
|
|
161
170
|
}
|
|
162
171
|
|
|
163
172
|
// Manually trigger page variant re-evaluation by dispatching a popstate event
|
|
164
173
|
// This ensures the page variant system detects the URL change and mounts search results
|
|
165
|
-
window.dispatchEvent(new PopStateEvent(
|
|
174
|
+
window.dispatchEvent(new PopStateEvent("popstate", { state: {} }));
|
|
166
175
|
if (currentState.loading) {
|
|
167
176
|
return; // Prevent concurrent searches
|
|
168
177
|
}
|
|
@@ -182,7 +191,8 @@ export const performSearchAtom = atom(
|
|
|
182
191
|
lastQuery: params.query,
|
|
183
192
|
});
|
|
184
193
|
} catch (error: unknown) {
|
|
185
|
-
const errorMessage =
|
|
194
|
+
const errorMessage =
|
|
195
|
+
error instanceof Error ? error.message : "An unknown error occurred";
|
|
186
196
|
set(searchAtom, {
|
|
187
197
|
data: null,
|
|
188
198
|
loading: false,
|
|
@@ -190,5 +200,5 @@ export const performSearchAtom = atom(
|
|
|
190
200
|
lastQuery: params.query,
|
|
191
201
|
});
|
|
192
202
|
}
|
|
193
|
-
}
|
|
203
|
+
}
|
|
194
204
|
);
|
package/src/hooks/index.ts
CHANGED
|
@@ -7,17 +7,15 @@ export * from "./useElementObserver";
|
|
|
7
7
|
export * from "./useFileUpload";
|
|
8
8
|
export * from "./useGrabAndScroll";
|
|
9
9
|
export * from "./useHideElements";
|
|
10
|
-
export * from "./useHorizontalScrollAnimation";
|
|
11
10
|
export * from "./useImageResolver";
|
|
12
11
|
export * from "./useIntersection";
|
|
13
12
|
export * from "./useIsSmallScreen";
|
|
14
13
|
export * from "./useMessageFilter";
|
|
15
14
|
export * from "./useMessageScrollObserver";
|
|
16
|
-
export * from "./useReducedMotionWithOverride";
|
|
17
15
|
export * from "./useSearch";
|
|
18
16
|
export * from "./useSnapCalculator";
|
|
19
|
-
export * from "./useSnapControl";
|
|
20
17
|
export * from "./useSystemSettingsContext";
|
|
21
18
|
export * from "./useTrackComponentVisibleEvent";
|
|
22
19
|
export * from "./useUpdateAnalyticsProps";
|
|
20
|
+
export * from "./useNewOrgConfig";
|
|
23
21
|
export * from "./utils";
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import Logger from
|
|
2
|
-
import { useEffect, useRef, useCallback, useState } from
|
|
3
|
-
import { useAtom, useAtomValue, useSetAtom } from
|
|
4
|
-
import { variantInfoAtom } from
|
|
5
|
-
import { PageVariantService } from
|
|
6
|
-
import { orgPageConfigAtom } from
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import Logger from "src/application/logging/logger";
|
|
2
|
+
import { useEffect, useRef, useCallback, useState } from "react";
|
|
3
|
+
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
4
|
+
import { variantInfoAtom } from "src/atoms/app";
|
|
5
|
+
import { PageVariantService } from "src/application/service/pageVariantService";
|
|
6
|
+
import { orgPageConfigAtom } from "src/atoms/org/orgPageConfig";
|
|
7
|
+
import {
|
|
8
|
+
hasParsedVariantInfoAtom,
|
|
9
|
+
supportedEventAtom,
|
|
10
|
+
} from "src/atoms/app/variant";
|
|
11
|
+
import {
|
|
12
|
+
SpiffyMetricsEventName,
|
|
13
|
+
AmplitudeAdapter,
|
|
14
|
+
} from "src/adapters/amplitude";
|
|
15
|
+
import { orgUIConfigAtom } from "src/atoms/org/orgUIConfig";
|
|
16
|
+
import { createAppLoadedEvent, createVisitUserEvent } from "src/hooks/utils";
|
|
17
|
+
import { queueUserEventAtom } from "src/atoms/chat/messageQueue";
|
|
18
|
+
import { UserEvent } from "src/application/models";
|
|
19
|
+
import { UserEventCategory } from "@spiffy-ai/commerce-api-client";
|
|
14
20
|
|
|
15
21
|
// consider putting this in the org config
|
|
16
22
|
const DEBOUNCE_DELAY_MS = 300;
|
|
@@ -26,7 +32,10 @@ const debounce = (func: () => void, delay: number): (() => void) => {
|
|
|
26
32
|
};
|
|
27
33
|
};
|
|
28
34
|
|
|
29
|
-
const isUserEventEqual = (
|
|
35
|
+
const isUserEventEqual = (
|
|
36
|
+
event1: UserEvent | null,
|
|
37
|
+
event2: UserEvent | null
|
|
38
|
+
) => {
|
|
30
39
|
if (!event1 || !event2) {
|
|
31
40
|
return false;
|
|
32
41
|
}
|
|
@@ -48,8 +57,8 @@ const isUserEventEqual = (event1: UserEvent | null, event2: UserEvent | null) =>
|
|
|
48
57
|
if (
|
|
49
58
|
event1.category === UserEventCategory.PlpVisit &&
|
|
50
59
|
event2.category === UserEventCategory.PlpVisit &&
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
"id" in event1.attributes.attributes &&
|
|
61
|
+
"id" in event2.attributes.attributes
|
|
53
62
|
) {
|
|
54
63
|
return event1.attributes.attributes.id === event2.attributes.attributes.id;
|
|
55
64
|
}
|
|
@@ -68,14 +77,17 @@ export const useDynamicVariants = () => {
|
|
|
68
77
|
const setVariantInfo = useSetAtom(variantInfoAtom);
|
|
69
78
|
const setSupportedEvent = useSetAtom(supportedEventAtom);
|
|
70
79
|
const queueUserEvent = useSetAtom(queueUserEventAtom);
|
|
71
|
-
const [mostRecentUserEvent, setMostRecentUserEvent] =
|
|
80
|
+
const [mostRecentUserEvent, setMostRecentUserEvent] =
|
|
81
|
+
useState<UserEvent | null>(null);
|
|
72
82
|
|
|
73
83
|
const orgPageConfig = useAtomValue(orgPageConfigAtom);
|
|
74
84
|
const debouncedFunc = useRef<(() => void) | null>(null);
|
|
75
85
|
// we need to fetch org info before we can get the variant info. this prevents the rest of the application
|
|
76
86
|
// logic from running before that happens. More specifically, we want to have all org and variant states
|
|
77
87
|
// settled before mounting the ChatContextProvider which will start the session.
|
|
78
|
-
const [hasParsedVariantInfo, setHasParsedVariantInfo] = useAtom(
|
|
88
|
+
const [hasParsedVariantInfo, setHasParsedVariantInfo] = useAtom(
|
|
89
|
+
hasParsedVariantInfoAtom
|
|
90
|
+
);
|
|
79
91
|
const animationFrameRef = useRef<number | null>(null);
|
|
80
92
|
const isBeforeUnload = useRef(false);
|
|
81
93
|
|
|
@@ -98,16 +110,17 @@ export const useDynamicVariants = () => {
|
|
|
98
110
|
|
|
99
111
|
if (!orgPageConfig) {
|
|
100
112
|
Logger.logWarn(
|
|
101
|
-
|
|
102
|
-
undefined
|
|
113
|
+
"[spiffy-ai] orgPageConfig not found. skipping page change handling",
|
|
114
|
+
undefined
|
|
103
115
|
);
|
|
104
116
|
return;
|
|
105
117
|
}
|
|
106
118
|
|
|
107
|
-
const parsedVariantInfo =
|
|
119
|
+
const parsedVariantInfo =
|
|
120
|
+
await PageVariantService.getVariantInfoWithPageConfig(orgPageConfig);
|
|
108
121
|
|
|
109
122
|
if (parsedVariantInfo) {
|
|
110
|
-
Logger.logDebug(
|
|
123
|
+
Logger.logDebug("[spiffy-ai] variantInfo changed", parsedVariantInfo);
|
|
111
124
|
const [newVariantInfo, pageVariantConfig] = parsedVariantInfo;
|
|
112
125
|
|
|
113
126
|
setVariantInfo(newVariantInfo);
|
|
@@ -120,8 +133,10 @@ export const useDynamicVariants = () => {
|
|
|
120
133
|
queueUserEvent(visitEvent);
|
|
121
134
|
}
|
|
122
135
|
|
|
123
|
-
const supportedEvent = await PageVariantService.checkSupportedEvent(
|
|
124
|
-
|
|
136
|
+
const supportedEvent = await PageVariantService.checkSupportedEvent(
|
|
137
|
+
pageVariantConfig
|
|
138
|
+
);
|
|
139
|
+
console.log("useDynamicVariants - supportedEvent", supportedEvent);
|
|
125
140
|
setSupportedEvent(supportedEvent);
|
|
126
141
|
AmplitudeAdapter.trackEvent({
|
|
127
142
|
eventName: SpiffyMetricsEventName.SupportedEvent,
|
|
@@ -164,14 +179,14 @@ export const useDynamicVariants = () => {
|
|
|
164
179
|
isBeforeUnload.current = true;
|
|
165
180
|
};
|
|
166
181
|
|
|
167
|
-
window.addEventListener(
|
|
168
|
-
window.addEventListener(
|
|
169
|
-
window.addEventListener(
|
|
182
|
+
window.addEventListener("click", handleLocationChange);
|
|
183
|
+
window.addEventListener("popstate", handleLocationChange);
|
|
184
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
170
185
|
|
|
171
186
|
return () => {
|
|
172
|
-
window.removeEventListener(
|
|
173
|
-
window.removeEventListener(
|
|
174
|
-
window.removeEventListener(
|
|
187
|
+
window.removeEventListener("click", handleLocationChange);
|
|
188
|
+
window.removeEventListener("popstate", handleLocationChange);
|
|
189
|
+
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
175
190
|
// TODO: this is causing the supportedEvent to be undefined for Magento customers
|
|
176
191
|
// Why is unclear however...
|
|
177
192
|
// setSupportedEvent(undefined);
|
|
@@ -191,10 +206,11 @@ export const useDynamicVariants = () => {
|
|
|
191
206
|
|
|
192
207
|
useEffect(() => {
|
|
193
208
|
let windowInterval: number | null = null;
|
|
194
|
-
const
|
|
209
|
+
const merchantVariantSettings = orgUIConfig?.merchantVariantSettings;
|
|
195
210
|
|
|
196
211
|
if (merchantVariantSettings?.dynamicVariants?.enabled) {
|
|
197
|
-
const refreshInterval =
|
|
212
|
+
const refreshInterval =
|
|
213
|
+
merchantVariantSettings?.dynamicVariants?.refreshInterval;
|
|
198
214
|
windowInterval = window.setInterval(() => {
|
|
199
215
|
handleLocationChange();
|
|
200
216
|
}, refreshInterval);
|
|
@@ -13,7 +13,7 @@ export const useFileUpload = () => {
|
|
|
13
13
|
const [error, setError] = useState("");
|
|
14
14
|
|
|
15
15
|
const isValidFile = (file?: File) => {
|
|
16
|
-
const maxSize = customerServiceImpl
|
|
16
|
+
const maxSize = customerServiceImpl?.maxfileUploadSize;
|
|
17
17
|
if (maxSize && (file?.size || 0) > maxSize) {
|
|
18
18
|
const strFileSize = `${(maxSize / 1000000).toFixed(1)}MB`;
|
|
19
19
|
setError(`Exceeded file size of ${strFileSize}`);
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import Logger from
|
|
2
|
-
import { SelectorFactory } from
|
|
3
|
-
import { useEffect, useRef, useState } from
|
|
4
|
-
import { useAtomValue } from
|
|
5
|
-
import { SpiffyEventName } from
|
|
6
|
-
import { ElementObserver } from
|
|
7
|
-
import { DOMObserver } from
|
|
8
|
-
import { orgUIConfigAtom } from
|
|
1
|
+
import Logger from "src/application/logging/logger";
|
|
2
|
+
import { SelectorFactory } from "src/application/utils/nodeSelector";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useAtomValue } from "jotai";
|
|
5
|
+
import { SpiffyEventName } from "src/application/models/events";
|
|
6
|
+
import { ElementObserver } from "src/application/utils/elementObserver";
|
|
7
|
+
import { DOMObserver } from "src/application/utils/domObserver";
|
|
8
|
+
import { orgUIConfigAtom } from "src/atoms/org/orgUIConfig";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* This hook hides/shows elements that could overlap with the chat when the chat is opened/closed.
|
|
12
12
|
*/
|
|
13
13
|
export const useHideElements = () => {
|
|
14
14
|
const orgUIConfig = useAtomValue(orgUIConfigAtom);
|
|
15
|
-
const [hasRegisteredEventListeners, setHasRegisteredEventListeners] =
|
|
15
|
+
const [hasRegisteredEventListeners, setHasRegisteredEventListeners] =
|
|
16
|
+
useState(false);
|
|
16
17
|
const elementObservers = useRef<ElementObserver[]>([]);
|
|
17
18
|
|
|
18
19
|
const hideElements = (elements: ElementObserver[]) => {
|
|
@@ -29,8 +30,10 @@ export const useHideElements = () => {
|
|
|
29
30
|
|
|
30
31
|
useEffect(() => {
|
|
31
32
|
elementObservers.current = [];
|
|
32
|
-
orgUIConfig
|
|
33
|
-
elementObservers.current.push(
|
|
33
|
+
orgUIConfig?.hiddenElementSelectors?.forEach((selector) => {
|
|
34
|
+
elementObservers.current.push(
|
|
35
|
+
DOMObserver.add(SelectorFactory.query(selector))
|
|
36
|
+
);
|
|
34
37
|
});
|
|
35
38
|
// since we're not using useElementObserver, we need to manually start the observer
|
|
36
39
|
elementObservers.current.forEach((element) => {
|
|
@@ -44,22 +47,22 @@ export const useHideElements = () => {
|
|
|
44
47
|
});
|
|
45
48
|
elementObservers.current = [];
|
|
46
49
|
};
|
|
47
|
-
}, [orgUIConfig
|
|
50
|
+
}, [orgUIConfig?.hiddenElementSelectors]);
|
|
48
51
|
|
|
49
52
|
useEffect(() => {
|
|
50
53
|
if (elementObservers.current.length > 0 && !hasRegisteredEventListeners) {
|
|
51
54
|
Logger.logDebug(
|
|
52
|
-
`Registering ${SpiffyEventName.WidgetOpen} event for ${elementObservers.current.length} elements
|
|
55
|
+
`Registering ${SpiffyEventName.WidgetOpen} event for ${elementObservers.current.length} elements`
|
|
53
56
|
);
|
|
54
57
|
window.addEventListener(SpiffyEventName.WidgetOpen, () =>
|
|
55
|
-
hideElements(elementObservers.current)
|
|
58
|
+
hideElements(elementObservers.current)
|
|
56
59
|
);
|
|
57
60
|
|
|
58
61
|
Logger.logDebug(
|
|
59
|
-
`Registering ${SpiffyEventName.WidgetClose} event for ${elementObservers.current.length} elements
|
|
62
|
+
`Registering ${SpiffyEventName.WidgetClose} event for ${elementObservers.current.length} elements`
|
|
60
63
|
);
|
|
61
64
|
window.addEventListener(SpiffyEventName.WidgetClose, () =>
|
|
62
|
-
showElements(elementObservers.current)
|
|
65
|
+
showElements(elementObservers.current)
|
|
63
66
|
);
|
|
64
67
|
|
|
65
68
|
setHasRegisteredEventListeners(true);
|
|
@@ -68,11 +71,11 @@ export const useHideElements = () => {
|
|
|
68
71
|
return () => {
|
|
69
72
|
if (elementObservers.current.length > 0 && hasRegisteredEventListeners) {
|
|
70
73
|
window.removeEventListener(SpiffyEventName.WidgetOpen, () =>
|
|
71
|
-
hideElements(elementObservers.current)
|
|
74
|
+
hideElements(elementObservers.current)
|
|
72
75
|
);
|
|
73
76
|
|
|
74
77
|
window.removeEventListener(SpiffyEventName.WidgetClose, () =>
|
|
75
|
-
showElements(elementObservers.current)
|
|
78
|
+
showElements(elementObservers.current)
|
|
76
79
|
);
|
|
77
80
|
|
|
78
81
|
setHasRegisteredEventListeners(false);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useAtomValue } from
|
|
2
|
-
import { OrgShortName } from
|
|
3
|
-
import { orgUIConfigAtom } from
|
|
1
|
+
import { useAtomValue } from "jotai";
|
|
2
|
+
import { OrgShortName } from "src/application/models";
|
|
3
|
+
import { orgUIConfigAtom } from "src/atoms/org/orgUIConfig";
|
|
4
4
|
|
|
5
5
|
abstract class ImageResolver {
|
|
6
6
|
abstract resolve(url: string, size: number): string;
|
|
@@ -12,8 +12,14 @@ class MerchantImageResolver {
|
|
|
12
12
|
private static loadMapping() {
|
|
13
13
|
if (this.imageResolverMap.size === 0) {
|
|
14
14
|
this.imageResolverMap.set(OrgShortName.Spanx, new ShopifyImageResolver());
|
|
15
|
-
this.imageResolverMap.set(
|
|
16
|
-
|
|
15
|
+
this.imageResolverMap.set(
|
|
16
|
+
OrgShortName.SpanxStaging,
|
|
17
|
+
new ShopifyImageResolver()
|
|
18
|
+
);
|
|
19
|
+
this.imageResolverMap.set(
|
|
20
|
+
OrgShortName.UniqueVintage,
|
|
21
|
+
new ShopifyImageResolver()
|
|
22
|
+
);
|
|
17
23
|
}
|
|
18
24
|
return this.imageResolverMap;
|
|
19
25
|
}
|
|
@@ -31,15 +37,17 @@ class ShopifyImageResolver extends ImageResolver {
|
|
|
31
37
|
if (urlHasPrefix) {
|
|
32
38
|
return url.replace(pattern, newSizePrefix);
|
|
33
39
|
}
|
|
34
|
-
return url.replace(
|
|
40
|
+
return url.replace(".jpg", newSizePrefix);
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
export const useImageResolver = () => {
|
|
39
45
|
const orgUIConfig = useAtomValue(orgUIConfigAtom);
|
|
40
46
|
const resolve = (image?: string, size?: number) => {
|
|
41
|
-
if (image && size) {
|
|
42
|
-
const newImagePath = MerchantImageResolver.get(
|
|
47
|
+
if (image && size && orgUIConfig?.shortName) {
|
|
48
|
+
const newImagePath = MerchantImageResolver.get(
|
|
49
|
+
orgUIConfig.shortName
|
|
50
|
+
)?.resolve(image, size);
|
|
43
51
|
return newImagePath || image;
|
|
44
52
|
}
|
|
45
53
|
return image;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { GraphQLClient } from "src/adapters/spiffy/commerce/graphql";
|
|
2
|
+
import Logger from "src/application/logging/logger";
|
|
3
|
+
import { AtomStore, getAtomStore } from "../atoms/atomStore";
|
|
4
|
+
import { ColorMapping } from "src/contexts";
|
|
5
|
+
|
|
6
|
+
import { useAtomValue } from "jotai";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { orgShortNameAtom } from "../atoms/org/org";
|
|
9
|
+
import {
|
|
10
|
+
BasicOrgInfoType,
|
|
11
|
+
getOrgInfo,
|
|
12
|
+
} from "src/application/models/supportedOrgs";
|
|
13
|
+
import { FrontendConfig } from "src/application/models";
|
|
14
|
+
|
|
15
|
+
type newConfigResponse = {
|
|
16
|
+
colorsConfig: ColorMapping | undefined;
|
|
17
|
+
frontendConfig: FrontendConfig | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
async function fetchGraphQLConfig(
|
|
21
|
+
atomStore: AtomStore
|
|
22
|
+
): Promise<newConfigResponse> {
|
|
23
|
+
try {
|
|
24
|
+
Logger.logDebug("GraphQLConfigService: Starting GraphQL client fetch");
|
|
25
|
+
|
|
26
|
+
const { colorsConfig, frontendConfig } =
|
|
27
|
+
(await GraphQLClient.getColorsAndFrontendConfig()) ?? {};
|
|
28
|
+
|
|
29
|
+
Logger.logDebug("GraphQL config fetch completed", {
|
|
30
|
+
hasColorsConfig: !!colorsConfig,
|
|
31
|
+
hasFrontendConfig: !!frontendConfig,
|
|
32
|
+
frontendConfigKeys: frontendConfig ? Object.keys(frontendConfig) : [],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
colorsConfig,
|
|
37
|
+
frontendConfig,
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
Logger.logError(
|
|
41
|
+
"GraphQLConfigService: Error during GraphQL config fetch",
|
|
42
|
+
error
|
|
43
|
+
);
|
|
44
|
+
throw error; // Re-throw to be caught by the caller
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const useNewOrgConfig = () => {
|
|
49
|
+
const [oldConfig, setOldConfig] = useState<BasicOrgInfoType | undefined>();
|
|
50
|
+
|
|
51
|
+
const [newConfig, setNewConfig] = useState<newConfigResponse | undefined>();
|
|
52
|
+
|
|
53
|
+
const [combinedConfig, setCombinedConfig] = useState<
|
|
54
|
+
newConfigResponse & BasicOrgInfoType
|
|
55
|
+
>();
|
|
56
|
+
const orgShortName = useAtomValue(orgShortNameAtom);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (orgShortName) {
|
|
60
|
+
getOrgInfo(orgShortName).then((oldConfigData) => {
|
|
61
|
+
setOldConfig(oldConfigData);
|
|
62
|
+
});
|
|
63
|
+
fetchGraphQLConfig(getAtomStore()).then((newConfigData) => {
|
|
64
|
+
setNewConfig(newConfigData);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}, [orgShortName]);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (oldConfig && newConfig) {
|
|
71
|
+
setCombinedConfig;
|
|
72
|
+
}
|
|
73
|
+
}, [oldConfig, newConfig]);
|
|
74
|
+
|
|
75
|
+
if (!orgShortName || !combinedConfig) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return combinedConfig;
|
|
80
|
+
};
|