@availity/hooks 5.2.0 → 6.0.1
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/CHANGELOG.md +17 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +158 -0
- package/package.json +25 -15
- package/project.json +14 -6
- package/src/index.ts +20 -0
- package/src/types.ts +4 -0
- package/src/useCurrentRegion.ts +23 -0
- package/src/useCurrentUser.ts +13 -0
- package/src/useEffectAsync.ts +9 -0
- package/src/useMount.ts +6 -0
- package/src/useOrganizations.ts +22 -0
- package/src/usePermissions.ts +15 -0
- package/src/useProviders.ts +20 -0
- package/src/useStash.ts +21 -0
- package/src/{useTimeout.js → useTimeout.ts} +1 -1
- package/src/{useToggle.js → useToggle.ts} +2 -2
- package/src/{useUpdateNav.js → useUpdateNav.ts} +1 -1
- package/src/{useWindowDimensions.js → useWindowDimensions.ts} +9 -9
- package/stories/ResourceComponent.tsx +12 -10
- package/tests/useCurrentRegion.test.tsx +49 -0
- package/tests/useCurrentUser.test.tsx +52 -0
- package/tests/useEffectAsync.test.tsx +30 -0
- package/tests/useMount.test.tsx +23 -0
- package/tests/useOrganizations.test.tsx +49 -0
- package/tests/usePermissions.test.tsx +52 -0
- package/tests/useProviders.test.tsx +49 -0
- package/tests/useStash.test.tsx +58 -0
- package/tests/useTimeout.test.tsx +33 -0
- package/tests/useToggle.test.tsx +41 -0
- package/tests/useUpdateNav.test.tsx +46 -0
- package/tests/useWindowDimensions.test.tsx +37 -0
- package/tests/util.tsx +7 -0
- package/vitest.config.ts +17 -0
- package/index.d.ts +0 -12
- package/index.js +0 -12
- package/jest.config.js +0 -7
- package/src/useCurrentRegion.js +0 -15
- package/src/useCurrentUser.js +0 -8
- package/src/useEffectAsync.js +0 -8
- package/src/useMount.js +0 -6
- package/src/useOrganizations.js +0 -8
- package/src/usePermissions.js +0 -8
- package/src/useProviders.js +0 -8
- package/src/useStash.js +0 -14
- package/tests/util.js +0 -8
- package/tsconfig.spec.json +0 -10
- package/types/aries.d.ts +0 -12
- package/types/useCurrentRegion.d.ts +0 -12
- package/types/useCurrentUser.d.ts +0 -21
- package/types/useEffectAsync.d.ts +0 -3
- package/types/useMount.d.ts +0 -5
- package/types/useOrganizations.d.ts +0 -75
- package/types/usePermissions.d.ts +0 -22
- package/types/useProviders.d.ts +0 -50
- package/types/useStash.d.ts +0 -10
- package/types/useTimeout.d.ts +0 -3
- package/types/useToggle.d.ts +0 -3
- package/types/useUpdateNav.d.ts +0 -3
- package/types/useWindowDimensions.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [6.0.1](https://github.com/Availity/availity-react/compare/@availity/hooks@6.0.0...@availity/hooks@6.0.1) (2026-06-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# [6.0.0](https://github.com/Availity/availity-react/compare/@availity/hooks@5.2.0...@availity/hooks@6.0.0) (2026-06-12)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat(hooks)!: migrate to ESM exports, vitest, and @tanstack/react-query v5 ([bab37b2](https://github.com/Availity/availity-react/commit/bab37b24f60ec88f7ade5bb23510053dae03ca38))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* Package now uses ESM exports field and requires @tanstack/react-query ^5.
|
|
18
|
+
The useQuery API now uses object syntax. Status 'loading' is renamed to 'pending'.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
5
22
|
# [5.2.0](https://github.com/Availity/availity-react/compare/@availity/hooks@5.1.11...@availity/hooks@5.2.0) (2026-06-09)
|
|
6
23
|
|
|
7
24
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { User, ProvidersResponse as ProvidersResponse$1, PermissionsResponse as PermissionsResponse$1, Organization as Organization$1, OrganizationsResponse as OrganizationsResponse$1, AriesPaginatedResponse } from '@availity/api-axios';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated useEffectAsync is an anti-pattern. Use useEffect with an IIFE or extract async logic into a separate function instead.
|
|
7
|
+
*/
|
|
8
|
+
declare function useEffectAsync(effect: () => void, inputs?: DependencyList): void;
|
|
9
|
+
|
|
10
|
+
declare function useMount(effect: EffectCallback): void;
|
|
11
|
+
|
|
12
|
+
declare function useTimeout(ms?: number): boolean;
|
|
13
|
+
|
|
14
|
+
declare function useToggle(initialState?: boolean): [boolean, (state?: boolean) => void];
|
|
15
|
+
|
|
16
|
+
interface CurrentRegion {
|
|
17
|
+
code: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
declare function useCurrentRegion(options?: Omit<UseQueryOptions<CurrentRegion, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<CurrentRegion, unknown>;
|
|
21
|
+
|
|
22
|
+
/** @deprecated Use `User` from `@availity/api-axios` instead */
|
|
23
|
+
type CurrentUser = User;
|
|
24
|
+
declare function useCurrentUser(options?: Omit<UseQueryOptions<User, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<User, unknown>;
|
|
25
|
+
|
|
26
|
+
/** @deprecated Use `ProvidersResponse` from `@availity/api-axios` instead */
|
|
27
|
+
type ProvidersResponse = ProvidersResponse$1;
|
|
28
|
+
interface AvProvidersConfig {
|
|
29
|
+
customerId: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
declare function useProviders(config: AvProvidersConfig, options?: Omit<UseQueryOptions<ProvidersResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<ProvidersResponse, unknown>;
|
|
33
|
+
|
|
34
|
+
/** @deprecated Use `PermissionsResponse` from `@availity/api-axios` instead */
|
|
35
|
+
type PermissionsResponse = PermissionsResponse$1;
|
|
36
|
+
declare function usePermissions(config: string | string[], options?: Omit<UseQueryOptions<PermissionsResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<PermissionsResponse, unknown>;
|
|
37
|
+
|
|
38
|
+
/** @deprecated Use `Organization` from `@availity/api-axios` instead */
|
|
39
|
+
type Organization = Organization$1;
|
|
40
|
+
/** @deprecated Use `OrganizationsResponse` from `@availity/api-axios` instead */
|
|
41
|
+
type OrganizationsResponse = OrganizationsResponse$1;
|
|
42
|
+
declare function useOrganizations(config: Record<string, unknown>, options?: Omit<UseQueryOptions<OrganizationsResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<OrganizationsResponse, unknown>;
|
|
43
|
+
|
|
44
|
+
declare const useUpdateNav: () => void;
|
|
45
|
+
|
|
46
|
+
interface Dimensions {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
}
|
|
50
|
+
declare function useWindowDimensions(): Dimensions;
|
|
51
|
+
|
|
52
|
+
type StashData = Record<string, unknown>;
|
|
53
|
+
declare function useStash(sessionId: string, options?: Omit<UseQueryOptions<StashData, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<StashData, unknown>;
|
|
54
|
+
|
|
55
|
+
/** @deprecated Use `AriesPaginatedResponse` from `@availity/api-axios` instead */
|
|
56
|
+
type AriesHookBase = AriesPaginatedResponse;
|
|
57
|
+
|
|
58
|
+
export { type AriesHookBase, type AvProvidersConfig, type CurrentRegion, type CurrentUser, type Dimensions, type Organization, type OrganizationsResponse, type PermissionsResponse, type ProvidersResponse, useCurrentRegion, useCurrentUser, useEffectAsync, useMount, useOrganizations, usePermissions, useProviders, useStash, useTimeout, useToggle, useUpdateNav, useWindowDimensions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// src/useEffectAsync.ts
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
function useEffectAsync(effect, inputs) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
effect();
|
|
6
|
+
}, inputs);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/useMount.ts
|
|
10
|
+
import { useEffect as useEffect2 } from "react";
|
|
11
|
+
function useMount(effect) {
|
|
12
|
+
useEffect2(effect, []);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/useTimeout.ts
|
|
16
|
+
import { useEffect as useEffect3, useState } from "react";
|
|
17
|
+
function useTimeout(ms = 0) {
|
|
18
|
+
const [ready, setReady] = useState(false);
|
|
19
|
+
useEffect3(() => {
|
|
20
|
+
let unmounted = false;
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
if (!unmounted) {
|
|
23
|
+
setReady(true);
|
|
24
|
+
}
|
|
25
|
+
}, ms);
|
|
26
|
+
return () => {
|
|
27
|
+
unmounted = true;
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
};
|
|
30
|
+
}, [ms]);
|
|
31
|
+
return ready;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/useToggle.ts
|
|
35
|
+
import { useState as useState2 } from "react";
|
|
36
|
+
function useToggle(initialState = false) {
|
|
37
|
+
const [state, setState] = useState2(initialState);
|
|
38
|
+
const toggle = (newState) => {
|
|
39
|
+
if (newState !== void 0 && newState !== state) {
|
|
40
|
+
setState(newState);
|
|
41
|
+
} else if (newState === void 0) {
|
|
42
|
+
setState(!state);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return [state, toggle];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/useCurrentRegion.ts
|
|
49
|
+
import { useQuery } from "@tanstack/react-query";
|
|
50
|
+
import { avRegionsApi } from "@availity/api-axios";
|
|
51
|
+
async function fetchRegion() {
|
|
52
|
+
const response = await avRegionsApi.getCurrentRegion();
|
|
53
|
+
const data = response?.data;
|
|
54
|
+
return {
|
|
55
|
+
code: data?.regions?.[0]?.id || "",
|
|
56
|
+
value: data?.regions?.[0]?.value || ""
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function useCurrentRegion(options) {
|
|
60
|
+
return useQuery({ queryKey: ["region"], queryFn: fetchRegion, ...options });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/useCurrentUser.ts
|
|
64
|
+
import { avUserApi } from "@availity/api-axios";
|
|
65
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
66
|
+
var fetchUser = async () => avUserApi.me();
|
|
67
|
+
function useCurrentUser(options) {
|
|
68
|
+
return useQuery2({ queryKey: ["user"], queryFn: fetchUser, ...options });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/useProviders.ts
|
|
72
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
73
|
+
import { avProvidersApi } from "@availity/api-axios";
|
|
74
|
+
var fetchProviders = async (config) => avProvidersApi.getProviders(config.customerId, config);
|
|
75
|
+
function useProviders(config, options) {
|
|
76
|
+
return useQuery3({ queryKey: ["providers", config], queryFn: () => fetchProviders(config), ...options });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/usePermissions.ts
|
|
80
|
+
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
81
|
+
import { avPermissionsApi } from "@availity/api-axios";
|
|
82
|
+
var fetchPermissions = async (config) => avPermissionsApi.getPermissions(config);
|
|
83
|
+
function usePermissions(config, options) {
|
|
84
|
+
return useQuery4({ queryKey: ["permissions", config], queryFn: () => fetchPermissions(config), ...options });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/useOrganizations.ts
|
|
88
|
+
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
89
|
+
import {
|
|
90
|
+
avOrganizationsApi
|
|
91
|
+
} from "@availity/api-axios";
|
|
92
|
+
var fetchOrganization = async (config) => avOrganizationsApi.getOrganizations(config);
|
|
93
|
+
function useOrganizations(config, options) {
|
|
94
|
+
return useQuery5({ queryKey: ["organizations", config], queryFn: () => fetchOrganization(config), ...options });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/useUpdateNav.ts
|
|
98
|
+
import { useEffect as useEffect4 } from "react";
|
|
99
|
+
import { useLocation } from "react-router-dom";
|
|
100
|
+
import avMessage from "@availity/message-core";
|
|
101
|
+
var useUpdateNav = () => {
|
|
102
|
+
const location = useLocation();
|
|
103
|
+
useEffect4(() => {
|
|
104
|
+
try {
|
|
105
|
+
avMessage.send({ event: "navChange", url: window.location.href });
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}, [location]);
|
|
109
|
+
};
|
|
110
|
+
var useUpdateNav_default = useUpdateNav;
|
|
111
|
+
|
|
112
|
+
// src/useWindowDimensions.ts
|
|
113
|
+
import { useEffect as useEffect5, useState as useState3 } from "react";
|
|
114
|
+
var getWindowDimensions = () => {
|
|
115
|
+
const { innerWidth: width, innerHeight: height } = window;
|
|
116
|
+
return { width, height };
|
|
117
|
+
};
|
|
118
|
+
function useWindowDimensions() {
|
|
119
|
+
const [windowDimensions, setWindowDimensions] = useState3(getWindowDimensions());
|
|
120
|
+
useEffect5(() => {
|
|
121
|
+
const handleResize = () => {
|
|
122
|
+
setWindowDimensions(getWindowDimensions());
|
|
123
|
+
};
|
|
124
|
+
window.addEventListener("resize", handleResize);
|
|
125
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
126
|
+
}, []);
|
|
127
|
+
return windowDimensions;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/useStash.ts
|
|
131
|
+
import { avStashApi } from "@availity/api-axios";
|
|
132
|
+
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
133
|
+
var fetchStash = async (sessionId) => {
|
|
134
|
+
const response = await avStashApi.get(sessionId);
|
|
135
|
+
return response?.data;
|
|
136
|
+
};
|
|
137
|
+
function useStash(sessionId, options) {
|
|
138
|
+
return useQuery6({
|
|
139
|
+
queryKey: ["stash", sessionId],
|
|
140
|
+
queryFn: () => fetchStash(sessionId),
|
|
141
|
+
enabled: !!sessionId,
|
|
142
|
+
...options
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
useCurrentRegion,
|
|
147
|
+
useCurrentUser,
|
|
148
|
+
useEffectAsync,
|
|
149
|
+
useMount,
|
|
150
|
+
useOrganizations,
|
|
151
|
+
usePermissions,
|
|
152
|
+
useProviders,
|
|
153
|
+
useStash,
|
|
154
|
+
useTimeout,
|
|
155
|
+
useToggle,
|
|
156
|
+
useUpdateNav_default as useUpdateNav,
|
|
157
|
+
useWindowDimensions
|
|
158
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "A group of pre-built hooks that are common in most apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -17,33 +17,43 @@
|
|
|
17
17
|
"directory": "packages/hooks"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
20
21
|
"author": "Kyle Gray <kyle.gray@availity.com>",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"types": "index.d.ts",
|
|
23
22
|
"scripts": {
|
|
24
23
|
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
25
|
-
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"prop-types": "^15.8.1"
|
|
24
|
+
"publish:canary": "yarn npm publish --access public --tag canary",
|
|
25
|
+
"build": "tsup src/index.ts --format esm --clean --dts",
|
|
26
|
+
"dev": "tsup src/index.ts --format esm --watch --dts",
|
|
27
|
+
"clean": "rm -rf dist"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
|
-
"@availity/api-axios": "^
|
|
33
|
-
"@availity/message-core": "^
|
|
34
|
-
"
|
|
30
|
+
"@availity/api-axios": "^13.2.0",
|
|
31
|
+
"@availity/message-core": "^9.2.0",
|
|
32
|
+
"@tanstack/react-query": "^5.75.5",
|
|
33
|
+
"axios": "^1.17.0",
|
|
35
34
|
"react": "^18.3.1",
|
|
36
35
|
"react-dom": "^18.3.1",
|
|
37
|
-
"react-router-dom": "^6.30.
|
|
36
|
+
"react-router-dom": "^6.30.4",
|
|
37
|
+
"tsup": "^8.5.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@availity/api-axios": "^12.0.0",
|
|
41
|
-
"@availity/message-core": "^8.0.2",
|
|
40
|
+
"@availity/api-axios": "^12.0.0 || ^13.0.0",
|
|
41
|
+
"@availity/message-core": "^8.0.2 || ^9.0.2",
|
|
42
|
+
"@tanstack/react-query": "^5.75.5",
|
|
42
43
|
"axios": "^1.13.2",
|
|
43
|
-
"react": "^18.0.0",
|
|
44
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
44
45
|
"react-router-dom": "^6.26.0"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/index.js",
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"source": "./src/index.ts",
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"import": "./dist/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
48
58
|
}
|
|
49
59
|
}
|
package/project.json
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
"projectType": "library",
|
|
5
5
|
"targets": {
|
|
6
6
|
"test": {
|
|
7
|
-
"executor": "
|
|
8
|
-
"outputs": ["{workspaceRoot}/coverage/hooks"],
|
|
7
|
+
"executor": "nx:run-commands",
|
|
9
8
|
"options": {
|
|
10
|
-
"
|
|
9
|
+
"command": "vitest run --project=hooks",
|
|
10
|
+
"cwd": "."
|
|
11
|
+
},
|
|
12
|
+
"configurations": {
|
|
13
|
+
"ci": {
|
|
14
|
+
"command": "vitest run --project=hooks --coverage"
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
},
|
|
13
18
|
"version": {
|
|
@@ -22,17 +27,20 @@
|
|
|
22
27
|
"lint": {
|
|
23
28
|
"executor": "@nx/eslint:lint",
|
|
24
29
|
"options": {
|
|
25
|
-
"eslintConfig": ".eslintrc.yaml",
|
|
26
30
|
"silent": false,
|
|
27
31
|
"fix": false,
|
|
28
32
|
"cache": true,
|
|
29
33
|
"cacheLocation": "./node_modules/.cache/hooks/.eslintcache",
|
|
30
34
|
"maxWarnings": -1,
|
|
31
35
|
"quiet": false,
|
|
32
|
-
"noEslintrc": false,
|
|
33
|
-
"hasTypeAwareRules": true,
|
|
34
36
|
"cacheStrategy": "metadata"
|
|
35
37
|
}
|
|
38
|
+
},
|
|
39
|
+
"build": {
|
|
40
|
+
"command": "tsup src/index.ts --format esm --dts",
|
|
41
|
+
"options": {
|
|
42
|
+
"cwd": "packages/hooks"
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { default as useEffectAsync } from './useEffectAsync';
|
|
2
|
+
export { default as useMount } from './useMount';
|
|
3
|
+
export { default as useTimeout } from './useTimeout';
|
|
4
|
+
export { default as useToggle } from './useToggle';
|
|
5
|
+
export { default as useCurrentRegion } from './useCurrentRegion';
|
|
6
|
+
export { default as useCurrentUser } from './useCurrentUser';
|
|
7
|
+
export { default as useProviders } from './useProviders';
|
|
8
|
+
export { default as usePermissions } from './usePermissions';
|
|
9
|
+
export { default as useOrganizations } from './useOrganizations';
|
|
10
|
+
export { default as useUpdateNav } from './useUpdateNav';
|
|
11
|
+
export { default as useWindowDimensions } from './useWindowDimensions';
|
|
12
|
+
export { default as useStash } from './useStash';
|
|
13
|
+
|
|
14
|
+
export type { CurrentRegion } from './useCurrentRegion';
|
|
15
|
+
export type { CurrentUser } from './useCurrentUser';
|
|
16
|
+
export type { Dimensions } from './useWindowDimensions';
|
|
17
|
+
export type { OrganizationsResponse, Organization } from './useOrganizations';
|
|
18
|
+
export type { PermissionsResponse } from './usePermissions';
|
|
19
|
+
export type { ProvidersResponse, AvProvidersConfig } from './useProviders';
|
|
20
|
+
export type { AriesHookBase } from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avRegionsApi, Region } from '@availity/api-axios';
|
|
3
|
+
|
|
4
|
+
export interface CurrentRegion {
|
|
5
|
+
code: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function fetchRegion(): Promise<CurrentRegion> {
|
|
10
|
+
const response = await avRegionsApi.getCurrentRegion();
|
|
11
|
+
const data = response?.data as { regions?: Region[] };
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
code: data?.regions?.[0]?.id || '',
|
|
15
|
+
value: data?.regions?.[0]?.value || '',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function useCurrentRegion(
|
|
20
|
+
options?: Omit<UseQueryOptions<CurrentRegion, unknown>, 'queryKey' | 'queryFn'>
|
|
21
|
+
): UseQueryResult<CurrentRegion, unknown> {
|
|
22
|
+
return useQuery({ queryKey: ['region'], queryFn: fetchRegion, ...options });
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { avUserApi, User } from '@availity/api-axios';
|
|
2
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
/** @deprecated Use `User` from `@availity/api-axios` instead */
|
|
5
|
+
export type CurrentUser = User;
|
|
6
|
+
|
|
7
|
+
const fetchUser = async () => avUserApi.me() as unknown as User;
|
|
8
|
+
|
|
9
|
+
export default function useCurrentUser(
|
|
10
|
+
options?: Omit<UseQueryOptions<User, unknown>, 'queryKey' | 'queryFn'>
|
|
11
|
+
): UseQueryResult<User, unknown> {
|
|
12
|
+
return useQuery({ queryKey: ['user'], queryFn: fetchUser, ...options });
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated useEffectAsync is an anti-pattern. Use useEffect with an IIFE or extract async logic into a separate function instead.
|
|
5
|
+
*/
|
|
6
|
+
export default function useEffectAsync(effect: () => void, inputs?: DependencyList): void {
|
|
7
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8
|
+
useEffect(() => { effect(); }, inputs);
|
|
9
|
+
}
|
package/src/useMount.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import {
|
|
3
|
+
avOrganizationsApi,
|
|
4
|
+
Organization as ApiOrganization,
|
|
5
|
+
OrganizationsResponse as ApiOrganizationsResponse,
|
|
6
|
+
} from '@availity/api-axios';
|
|
7
|
+
|
|
8
|
+
/** @deprecated Use `Organization` from `@availity/api-axios` instead */
|
|
9
|
+
export type Organization = ApiOrganization;
|
|
10
|
+
|
|
11
|
+
/** @deprecated Use `OrganizationsResponse` from `@availity/api-axios` instead */
|
|
12
|
+
export type OrganizationsResponse = ApiOrganizationsResponse;
|
|
13
|
+
|
|
14
|
+
const fetchOrganization = async (config: Record<string, unknown>) =>
|
|
15
|
+
avOrganizationsApi.getOrganizations(config) as unknown as OrganizationsResponse;
|
|
16
|
+
|
|
17
|
+
export default function useOrganizations(
|
|
18
|
+
config: Record<string, unknown>,
|
|
19
|
+
options?: Omit<UseQueryOptions<OrganizationsResponse, unknown>, 'queryKey' | 'queryFn'>
|
|
20
|
+
): UseQueryResult<OrganizationsResponse, unknown> {
|
|
21
|
+
return useQuery({ queryKey: ['organizations', config], queryFn: () => fetchOrganization(config), ...options });
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avPermissionsApi, PermissionsResponse as ApiPermissionsResponse } from '@availity/api-axios';
|
|
3
|
+
|
|
4
|
+
/** @deprecated Use `PermissionsResponse` from `@availity/api-axios` instead */
|
|
5
|
+
export type PermissionsResponse = ApiPermissionsResponse;
|
|
6
|
+
|
|
7
|
+
const fetchPermissions = async (config: string | string[]) =>
|
|
8
|
+
avPermissionsApi.getPermissions(config) as unknown as PermissionsResponse;
|
|
9
|
+
|
|
10
|
+
export default function usePermissions(
|
|
11
|
+
config: string | string[],
|
|
12
|
+
options?: Omit<UseQueryOptions<PermissionsResponse, unknown>, 'queryKey' | 'queryFn'>
|
|
13
|
+
): UseQueryResult<PermissionsResponse, unknown> {
|
|
14
|
+
return useQuery({ queryKey: ['permissions', config], queryFn: () => fetchPermissions(config), ...options });
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avProvidersApi, ProvidersResponse as ApiProvidersResponse } from '@availity/api-axios';
|
|
3
|
+
|
|
4
|
+
/** @deprecated Use `ProvidersResponse` from `@availity/api-axios` instead */
|
|
5
|
+
export type ProvidersResponse = ApiProvidersResponse;
|
|
6
|
+
|
|
7
|
+
export interface AvProvidersConfig {
|
|
8
|
+
customerId: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const fetchProviders = async (config: AvProvidersConfig) =>
|
|
13
|
+
avProvidersApi.getProviders(config.customerId, config) as unknown as ProvidersResponse;
|
|
14
|
+
|
|
15
|
+
export default function useProviders(
|
|
16
|
+
config: AvProvidersConfig,
|
|
17
|
+
options?: Omit<UseQueryOptions<ProvidersResponse, unknown>, 'queryKey' | 'queryFn'>
|
|
18
|
+
): UseQueryResult<ProvidersResponse, unknown> {
|
|
19
|
+
return useQuery({ queryKey: ['providers', config], queryFn: () => fetchProviders(config), ...options });
|
|
20
|
+
}
|
package/src/useStash.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { avStashApi } from '@availity/api-axios';
|
|
2
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
export type StashData = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
const fetchStash = async (sessionId: string) => {
|
|
7
|
+
const response = await avStashApi.get(sessionId);
|
|
8
|
+
return response?.data;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default function useStash(
|
|
12
|
+
sessionId: string,
|
|
13
|
+
options?: Omit<UseQueryOptions<StashData, unknown>, 'queryKey' | 'queryFn'>
|
|
14
|
+
): UseQueryResult<StashData, unknown> {
|
|
15
|
+
return useQuery({
|
|
16
|
+
queryKey: ['stash', sessionId],
|
|
17
|
+
queryFn: () => fetchStash(sessionId),
|
|
18
|
+
enabled: !!sessionId,
|
|
19
|
+
...options,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
|
|
3
|
-
export default function useToggle(initialState = false) {
|
|
3
|
+
export default function useToggle(initialState = false): [boolean, (state?: boolean) => void] {
|
|
4
4
|
const [state, setState] = useState(initialState);
|
|
5
|
-
const toggle = (newState) => {
|
|
5
|
+
const toggle = (newState?: boolean) => {
|
|
6
6
|
if (newState !== undefined && newState !== state) {
|
|
7
7
|
setState(newState);
|
|
8
8
|
} else if (newState === undefined) {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface Dimensions {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const getWindowDimensions = (): Dimensions => {
|
|
4
9
|
const { innerWidth: width, innerHeight: height } = window;
|
|
5
|
-
return {
|
|
6
|
-
width,
|
|
7
|
-
height,
|
|
8
|
-
};
|
|
10
|
+
return { width, height };
|
|
9
11
|
};
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
export default function useWindowDimensions(): Dimensions {
|
|
12
14
|
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
|
|
13
15
|
|
|
14
16
|
useEffect(() => {
|
|
@@ -21,6 +23,4 @@ const useWindowDimensions = () => {
|
|
|
21
23
|
}, []);
|
|
22
24
|
|
|
23
25
|
return windowDimensions;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default useWindowDimensions;
|
|
26
|
+
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Card, CardBody, CardTitle } from 'reactstrap';
|
|
3
3
|
|
|
4
|
-
type Props = {
|
|
5
|
-
data:
|
|
4
|
+
type Props<TData> = {
|
|
5
|
+
data: TData;
|
|
6
6
|
loading: boolean;
|
|
7
7
|
title?: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
function ResourceComponent<TData>({ data, loading, title = '' }: Props<TData>) {
|
|
11
|
+
return (
|
|
12
|
+
<Card body>
|
|
13
|
+
<CardTitle className="text-center" tag="h4">
|
|
14
|
+
{title}
|
|
15
|
+
</CardTitle>
|
|
16
|
+
<CardBody>{loading ? 'Loading...' : <pre>{JSON.stringify(data, null, 2)}</pre>}</CardBody>
|
|
17
|
+
</Card>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
18
20
|
|
|
19
21
|
export default ResourceComponent;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { REGIONS } from '@availity/mock/src/routes';
|
|
7
|
+
import { useCurrentRegion } from '../src/index';
|
|
8
|
+
import renderWithClient from './util';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = () => {
|
|
18
|
+
const { data, error, status } = useCurrentRegion({ gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('useCurrentRegion', () => {
|
|
30
|
+
test('handle error', async () => {
|
|
31
|
+
server.use(http.get(REGIONS, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('handle success', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(`Data: ${JSON.stringify({ code: 'FL', value: 'Florida' })}`)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|