@trackunit/react-core-hooks 0.2.189 → 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
  *
@@ -389,6 +428,44 @@ const useIrisAppName = () => {
389
428
  }, []);
390
429
  return { appName, loading, error };
391
430
  };
431
+ /**
432
+ * A hook to expose irisAppId using ParamsRuntime's getAppName and getOrgName for React components
433
+ *
434
+ * @requires ParamsRuntime
435
+ * @returns {UseIrisAppId} irisAppId, loading, error
436
+ * @example
437
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
438
+ * const { irisAppId } = useIrisAppName();
439
+ * useEffect(() => {
440
+ * (async () => {
441
+ * if (irisAppId) {
442
+ * // do something with irisAppId
443
+ * }
444
+ * })();
445
+ * }, [irisAppId]);
446
+ */
447
+ const useIrisAppId = () => {
448
+ const [irisAppId, setIrisAppId] = React.useState();
449
+ const [loading, setLoading] = React.useState(true);
450
+ const [error, setError] = React.useState();
451
+ React.useEffect(() => {
452
+ const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
453
+ setLoading(true);
454
+ try {
455
+ const updatedAppName = yield irisAppRuntimeCore.ParamsRuntime.getAppName();
456
+ const updatedOrgName = yield irisAppRuntimeCore.ParamsRuntime.getOrgName();
457
+ setLoading(false);
458
+ setIrisAppId(`${updatedOrgName}/${updatedAppName}`);
459
+ }
460
+ catch (e) {
461
+ setLoading(false);
462
+ setError(new Error("Failed to get iris app name"));
463
+ }
464
+ });
465
+ getAppName();
466
+ }, []);
467
+ return { irisAppId, loading, error };
468
+ };
392
469
 
393
470
  /**
394
471
  * A hook to expose site runtime for React components
@@ -661,10 +738,12 @@ exports.useCurrentUser = useCurrentUser;
661
738
  exports.useCurrentUserLanguage = useCurrentUserLanguage;
662
739
  exports.useCurrentUserSystemOfMeasurement = useCurrentUserSystemOfMeasurement;
663
740
  exports.useCurrentUserTimeZonePreference = useCurrentUserTimeZonePreference;
741
+ exports.useCustomerRuntime = useCustomerRuntime;
664
742
  exports.useEnvironment = useEnvironment;
665
743
  exports.useEventRuntime = useEventRuntime;
666
744
  exports.useFilterBarContext = useFilterBarContext;
667
745
  exports.useHasAccessTo = useHasAccessTo;
746
+ exports.useIrisAppId = useIrisAppId;
668
747
  exports.useIrisAppName = useIrisAppName;
669
748
  exports.useNavigateInHost = useNavigateInHost;
670
749
  exports.useOemBrandingContext = useOemBrandingContext;
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
  *
@@ -366,6 +405,44 @@ const useIrisAppName = () => {
366
405
  }, []);
367
406
  return { appName, loading, error };
368
407
  };
408
+ /**
409
+ * A hook to expose irisAppId using ParamsRuntime's getAppName and getOrgName for React components
410
+ *
411
+ * @requires ParamsRuntime
412
+ * @returns {UseIrisAppId} irisAppId, loading, error
413
+ * @example
414
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
415
+ * const { irisAppId } = useIrisAppName();
416
+ * useEffect(() => {
417
+ * (async () => {
418
+ * if (irisAppId) {
419
+ * // do something with irisAppId
420
+ * }
421
+ * })();
422
+ * }, [irisAppId]);
423
+ */
424
+ const useIrisAppId = () => {
425
+ const [irisAppId, setIrisAppId] = useState();
426
+ const [loading, setLoading] = useState(true);
427
+ const [error, setError] = useState();
428
+ useEffect(() => {
429
+ const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
430
+ setLoading(true);
431
+ try {
432
+ const updatedAppName = yield ParamsRuntime.getAppName();
433
+ const updatedOrgName = yield ParamsRuntime.getOrgName();
434
+ setLoading(false);
435
+ setIrisAppId(`${updatedOrgName}/${updatedAppName}`);
436
+ }
437
+ catch (e) {
438
+ setLoading(false);
439
+ setError(new Error("Failed to get iris app name"));
440
+ }
441
+ });
442
+ getAppName();
443
+ }, []);
444
+ return { irisAppId, loading, error };
445
+ };
369
446
 
370
447
  /**
371
448
  * A hook to expose site runtime for React components
@@ -617,4 +694,4 @@ const useCurrentUser = () => {
617
694
  return context;
618
695
  };
619
696
 
620
- 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, 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.189",
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;
@@ -20,3 +20,25 @@ export interface UseIrisAppName {
20
20
  * }, [appName]);
21
21
  */
22
22
  export declare const useIrisAppName: () => UseIrisAppName;
23
+ export interface UseIrisAppId {
24
+ irisAppId: string | undefined;
25
+ loading: boolean;
26
+ error: Error | undefined;
27
+ }
28
+ /**
29
+ * A hook to expose irisAppId using ParamsRuntime's getAppName and getOrgName for React components
30
+ *
31
+ * @requires ParamsRuntime
32
+ * @returns {UseIrisAppId} irisAppId, loading, error
33
+ * @example
34
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
35
+ * const { irisAppId } = useIrisAppName();
36
+ * useEffect(() => {
37
+ * (async () => {
38
+ * if (irisAppId) {
39
+ * // do something with irisAppId
40
+ * }
41
+ * })();
42
+ * }, [irisAppId]);
43
+ */
44
+ export declare const useIrisAppId: () => UseIrisAppId;