UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

40 lines (39 loc) 1.34 kB
import { useState as u, useMemo as i, useEffect as l } from "../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js"; import { useFetch as C } from "./useFetch.js"; import { useConfigContext as S } from "../core/ConfigContext/preact/context.js"; import { EMPTY_OBJECT as c } from "../utils/value/constants.js"; const T = (t, d = !0) => { const [s, a] = u(void 0), { getPayByLinkStores: n } = S().endpoints, { data: r, error: f, isFetching: m } = C( i( () => ({ fetchOptions: { enabled: !!n }, queryFn: async () => n?.(c, c) }), [n] ) ), o = i( () => r?.data?.filter((e) => e.storeId ? !t || (typeof t == "string" ? e.storeId === t : t?.includes(e.storeId)) : !1).map((e) => ({ id: e.storeId || "", name: e.storeCode || "", storeCode: e.storeCode || "", description: e.description || "" })), [r, t] ), p = i( () => r?.data?.map((e) => ({ id: e.storeId || "", name: e.storeCode || "", storeCode: e.storeCode || "", description: e.description || "" })), [r] ); return l(() => { !s && o && o?.length > 0 && d && a(o?.[0]?.id); }, [o, s, d]), { filteredStores: o, selectedStore: s, setSelectedStore: a, isFetching: m, error: f, allStores: p }; }; export { T as useStores };