@trackunit/react-core-hooks 0.2.190 → 0.2.191

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/index.cjs.js CHANGED
@@ -313,6 +313,45 @@ const useAssetRuntime = () => {
313
313
  return { assetInfo, loading, error };
314
314
  };
315
315
 
316
+ /**
317
+ * A hook to expose customer runtime for React components
318
+ *
319
+ * @requires CustomerRuntime
320
+ * @returns {UseCustomerRuntime} customerRuntime
321
+ * @example
322
+ * import { useCustomerRuntime } from "@trackunit/react-core-hooks";
323
+ * const { customerInfo } = useCustomerRuntime();
324
+ * // use customerInfo to get customer info for instance.
325
+ * useEffect(() => {
326
+ * (async () => {
327
+ * if (customerInfo?.customerId) {
328
+ * // use graphql to get data for the customerId
329
+ * }
330
+ * })();
331
+ * }, [customerInfo]);
332
+ */
333
+ const useCustomerRuntime = () => {
334
+ const [customerInfo, setCustomerInfo] = React.useState();
335
+ const [loading, setLoading] = React.useState(true);
336
+ const [error, setError] = React.useState();
337
+ React.useEffect(() => {
338
+ const getCustomerInfo = () => __awaiter(void 0, void 0, void 0, function* () {
339
+ setLoading(true);
340
+ try {
341
+ const updatedCustomerInfo = yield irisAppRuntimeCore.CustomerRuntime.getCustomerInfo();
342
+ setLoading(false);
343
+ setCustomerInfo(updatedCustomerInfo);
344
+ }
345
+ catch (e) {
346
+ setLoading(false);
347
+ setError(new Error("Failed to get customer info"));
348
+ }
349
+ });
350
+ getCustomerInfo();
351
+ }, []);
352
+ return { customerInfo, loading, error };
353
+ };
354
+
316
355
  /**
317
356
  * A hook to expose event runtime for React components
318
357
  *
@@ -699,6 +738,7 @@ exports.useCurrentUser = useCurrentUser;
699
738
  exports.useCurrentUserLanguage = useCurrentUserLanguage;
700
739
  exports.useCurrentUserSystemOfMeasurement = useCurrentUserSystemOfMeasurement;
701
740
  exports.useCurrentUserTimeZonePreference = useCurrentUserTimeZonePreference;
741
+ exports.useCustomerRuntime = useCustomerRuntime;
702
742
  exports.useEnvironment = useEnvironment;
703
743
  exports.useEventRuntime = useEventRuntime;
704
744
  exports.useFilterBarContext = useFilterBarContext;
package/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { createContext, useContext, useState, useEffect, useMemo } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
- import { AssetRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
4
+ import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
5
5
  import { filterByMultiple } from '@trackunit/shared-utils';
6
6
 
7
7
  const AnalyticsContext = createContext(null);
@@ -290,6 +290,45 @@ const useAssetRuntime = () => {
290
290
  return { assetInfo, loading, error };
291
291
  };
292
292
 
293
+ /**
294
+ * A hook to expose customer runtime for React components
295
+ *
296
+ * @requires CustomerRuntime
297
+ * @returns {UseCustomerRuntime} customerRuntime
298
+ * @example
299
+ * import { useCustomerRuntime } from "@trackunit/react-core-hooks";
300
+ * const { customerInfo } = useCustomerRuntime();
301
+ * // use customerInfo to get customer info for instance.
302
+ * useEffect(() => {
303
+ * (async () => {
304
+ * if (customerInfo?.customerId) {
305
+ * // use graphql to get data for the customerId
306
+ * }
307
+ * })();
308
+ * }, [customerInfo]);
309
+ */
310
+ const useCustomerRuntime = () => {
311
+ const [customerInfo, setCustomerInfo] = useState();
312
+ const [loading, setLoading] = useState(true);
313
+ const [error, setError] = useState();
314
+ useEffect(() => {
315
+ const getCustomerInfo = () => __awaiter(void 0, void 0, void 0, function* () {
316
+ setLoading(true);
317
+ try {
318
+ const updatedCustomerInfo = yield CustomerRuntime.getCustomerInfo();
319
+ setLoading(false);
320
+ setCustomerInfo(updatedCustomerInfo);
321
+ }
322
+ catch (e) {
323
+ setLoading(false);
324
+ setError(new Error("Failed to get customer info"));
325
+ }
326
+ });
327
+ getCustomerInfo();
328
+ }, []);
329
+ return { customerInfo, loading, error };
330
+ };
331
+
293
332
  /**
294
333
  * A hook to expose event runtime for React components
295
334
  *
@@ -655,4 +694,4 @@ const useCurrentUser = () => {
655
694
  return context;
656
695
  };
657
696
 
658
- export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useIrisAppId, useIrisAppName, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
697
+ export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useIrisAppId, useIrisAppName, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "0.2.190",
3
+ "version": "0.2.191",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./filter-bar/FilterBarProvider";
6
6
  export * from "./irisOemApp/IrisOemAppContextProvider";
7
7
  export * from "./navigation/NavigationContextProvider";
8
8
  export * from "./runtimes/useAssetRuntime";
9
+ export * from "./runtimes/useCustomerRuntime";
9
10
  export * from "./runtimes/useEventRuntime";
10
11
  export * from "./runtimes/useParamsRuntime";
11
12
  export * from "./runtimes/useSiteRuntime";
@@ -0,0 +1,24 @@
1
+ import { CustomerInfo } from "@trackunit/iris-app-runtime-core";
2
+ export interface UseCustomerRuntime {
3
+ customerInfo?: CustomerInfo;
4
+ loading: boolean;
5
+ error: Error | undefined;
6
+ }
7
+ /**
8
+ * A hook to expose customer runtime for React components
9
+ *
10
+ * @requires CustomerRuntime
11
+ * @returns {UseCustomerRuntime} customerRuntime
12
+ * @example
13
+ * import { useCustomerRuntime } from "@trackunit/react-core-hooks";
14
+ * const { customerInfo } = useCustomerRuntime();
15
+ * // use customerInfo to get customer info for instance.
16
+ * useEffect(() => {
17
+ * (async () => {
18
+ * if (customerInfo?.customerId) {
19
+ * // use graphql to get data for the customerId
20
+ * }
21
+ * })();
22
+ * }, [customerInfo]);
23
+ */
24
+ export declare const useCustomerRuntime: () => UseCustomerRuntime;