@availity/hooks 5.2.0 → 6.0.0
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 +13 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.js +156 -0
- package/package.json +25 -15
- package/project.json +14 -3
- package/src/index.ts +20 -0
- package/src/useCurrentRegion.ts +23 -0
- package/src/useCurrentUser.ts +24 -0
- package/src/useEffectAsync.ts +9 -0
- package/src/useMount.ts +6 -0
- package/src/useOrganizations.ts +73 -0
- package/src/usePermissions.ts +23 -0
- package/src/useProviders.ts +48 -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.jsx +96 -0
- package/tests/useCurrentUser.test.jsx +94 -0
- package/tests/useEffectAsync.test.jsx +36 -0
- package/tests/useMount.test.jsx +24 -0
- package/tests/useOrganizations.test.jsx +112 -0
- package/tests/usePermissions.test.jsx +90 -0
- package/tests/useProviders.test.jsx +106 -0
- package/tests/useStash.test.jsx +89 -0
- package/tests/useTimeout.test.jsx +33 -0
- package/tests/useToggle.test.jsx +42 -0
- package/tests/useUpdateNav.test.jsx +46 -0
- package/tests/useWindowDimensions.test.jsx +38 -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/tsconfig.spec.json +0 -10
- 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/{types/aries.d.ts → src/types.ts} +0 -0
- /package/tests/{util.js → util.jsx} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [6.0.0](https://github.com/Availity/availity-react/compare/@availity/hooks@5.2.0...@availity/hooks@6.0.0) (2026-06-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
* feat(hooks)!: migrate to ESM exports, vitest, and @tanstack/react-query v5 ([bab37b2](https://github.com/Availity/availity-react/commit/bab37b24f60ec88f7ade5bb23510053dae03ca38))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### BREAKING CHANGES
|
|
12
|
+
|
|
13
|
+
* Package now uses ESM exports field and requires @tanstack/react-query ^5.
|
|
14
|
+
The useQuery API now uses object syntax. Status 'loading' is renamed to 'pending'.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
# [5.2.0](https://github.com/Availity/availity-react/compare/@availity/hooks@5.1.11...@availity/hooks@5.2.0) (2026-06-09)
|
|
6
19
|
|
|
7
20
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated useEffectAsync is an anti-pattern. Use useEffect with an IIFE or extract async logic into a separate function instead.
|
|
6
|
+
*/
|
|
7
|
+
declare function useEffectAsync(effect: () => void, inputs?: DependencyList): void;
|
|
8
|
+
|
|
9
|
+
declare function useMount(effect: EffectCallback): void;
|
|
10
|
+
|
|
11
|
+
declare function useTimeout(ms?: number): boolean;
|
|
12
|
+
|
|
13
|
+
declare function useToggle(initialState?: boolean): [boolean, (state?: boolean) => void];
|
|
14
|
+
|
|
15
|
+
interface CurrentRegion {
|
|
16
|
+
code: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
declare function useCurrentRegion(options?: Omit<UseQueryOptions<CurrentRegion, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<CurrentRegion, unknown>;
|
|
20
|
+
|
|
21
|
+
interface CurrentUser {
|
|
22
|
+
akaname: string;
|
|
23
|
+
createDate: string;
|
|
24
|
+
currentRegion: string;
|
|
25
|
+
email: string;
|
|
26
|
+
firstName: string;
|
|
27
|
+
lastName: string;
|
|
28
|
+
id: string;
|
|
29
|
+
jobTitle: string;
|
|
30
|
+
userHasSecurityException: boolean;
|
|
31
|
+
userId: string;
|
|
32
|
+
userValidated: boolean;
|
|
33
|
+
}
|
|
34
|
+
declare function useCurrentUser(options?: Omit<UseQueryOptions<CurrentUser, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<CurrentUser, unknown>;
|
|
35
|
+
|
|
36
|
+
interface AriesHookBase {
|
|
37
|
+
data: {
|
|
38
|
+
totalCount: number;
|
|
39
|
+
count: number;
|
|
40
|
+
offSet: number;
|
|
41
|
+
links: {
|
|
42
|
+
next: {
|
|
43
|
+
href: string;
|
|
44
|
+
};
|
|
45
|
+
last: {
|
|
46
|
+
href: string;
|
|
47
|
+
};
|
|
48
|
+
self: {
|
|
49
|
+
href: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ProvidersResponse extends AriesHookBase {
|
|
56
|
+
data: AriesHookBase['data'] & {
|
|
57
|
+
providers: {
|
|
58
|
+
id: string;
|
|
59
|
+
lastName: string;
|
|
60
|
+
firstName: string;
|
|
61
|
+
middleName: string;
|
|
62
|
+
uiDisplayName: string;
|
|
63
|
+
atypical: boolean;
|
|
64
|
+
npi: string;
|
|
65
|
+
customerIds: string[];
|
|
66
|
+
roles: {
|
|
67
|
+
code: string;
|
|
68
|
+
value: string;
|
|
69
|
+
}[];
|
|
70
|
+
primarySpecialty: {
|
|
71
|
+
code: string;
|
|
72
|
+
value: string;
|
|
73
|
+
};
|
|
74
|
+
primaryFax: {
|
|
75
|
+
internationalCellularCode: string;
|
|
76
|
+
areaCode: string;
|
|
77
|
+
phoneNumber: string;
|
|
78
|
+
};
|
|
79
|
+
primaryAddress: {
|
|
80
|
+
line1: string;
|
|
81
|
+
line2: string;
|
|
82
|
+
city: string;
|
|
83
|
+
state: string;
|
|
84
|
+
stateCode: string;
|
|
85
|
+
zip: {
|
|
86
|
+
code: string;
|
|
87
|
+
addon: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}[];
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
interface AvProvidersConfig {
|
|
94
|
+
customerId: string;
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
}
|
|
97
|
+
declare function useProviders(config: AvProvidersConfig, options?: Omit<UseQueryOptions<ProvidersResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<ProvidersResponse, unknown>;
|
|
98
|
+
|
|
99
|
+
interface PermissionsResponse extends AriesHookBase {
|
|
100
|
+
data: AriesHookBase['data'] & {
|
|
101
|
+
permissions: {
|
|
102
|
+
id: string;
|
|
103
|
+
description: string;
|
|
104
|
+
links: {
|
|
105
|
+
self: {
|
|
106
|
+
href: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}[];
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
declare function usePermissions(config: string | string[], options?: Omit<UseQueryOptions<PermissionsResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<PermissionsResponse, unknown>;
|
|
113
|
+
|
|
114
|
+
interface Organization {
|
|
115
|
+
links: {
|
|
116
|
+
permissions: {
|
|
117
|
+
href: string;
|
|
118
|
+
};
|
|
119
|
+
patients: {
|
|
120
|
+
href: string;
|
|
121
|
+
};
|
|
122
|
+
self: {
|
|
123
|
+
href: string;
|
|
124
|
+
};
|
|
125
|
+
admin: {
|
|
126
|
+
href: string;
|
|
127
|
+
};
|
|
128
|
+
businessArrangements: {
|
|
129
|
+
href: string;
|
|
130
|
+
};
|
|
131
|
+
users: {
|
|
132
|
+
href: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
id: string;
|
|
136
|
+
customerId: string;
|
|
137
|
+
name: string;
|
|
138
|
+
status: string;
|
|
139
|
+
statusCode: string;
|
|
140
|
+
types: {
|
|
141
|
+
code: string;
|
|
142
|
+
value: string;
|
|
143
|
+
}[];
|
|
144
|
+
primaryControllingAuthority: {
|
|
145
|
+
lastName: string;
|
|
146
|
+
firstName: string;
|
|
147
|
+
primaryPhone: string;
|
|
148
|
+
email: string;
|
|
149
|
+
};
|
|
150
|
+
physicalAddress: {
|
|
151
|
+
line1: string;
|
|
152
|
+
city: string;
|
|
153
|
+
state: string;
|
|
154
|
+
stateCode: string;
|
|
155
|
+
zipCode: string;
|
|
156
|
+
};
|
|
157
|
+
mailingAddress: {
|
|
158
|
+
line1: string;
|
|
159
|
+
city: string;
|
|
160
|
+
state: string;
|
|
161
|
+
stateCode: string;
|
|
162
|
+
zipCode: string;
|
|
163
|
+
};
|
|
164
|
+
billingAddress: {
|
|
165
|
+
line1: string;
|
|
166
|
+
city: string;
|
|
167
|
+
state: string;
|
|
168
|
+
stateCode: string;
|
|
169
|
+
zipCode: string;
|
|
170
|
+
};
|
|
171
|
+
regions: {
|
|
172
|
+
code: string;
|
|
173
|
+
value: string;
|
|
174
|
+
}[];
|
|
175
|
+
npis: {
|
|
176
|
+
number: string;
|
|
177
|
+
}[];
|
|
178
|
+
taxIds: {
|
|
179
|
+
number: string;
|
|
180
|
+
type: string;
|
|
181
|
+
}[];
|
|
182
|
+
phoneNumber: {
|
|
183
|
+
areaCode: string;
|
|
184
|
+
exchange: string;
|
|
185
|
+
phoneNumber: string;
|
|
186
|
+
};
|
|
187
|
+
numberOfLicensedPhysicians: string;
|
|
188
|
+
numberOfLicensedClinicians: string;
|
|
189
|
+
}
|
|
190
|
+
interface OrganizationsResponse extends AriesHookBase {
|
|
191
|
+
data: AriesHookBase['data'] & {
|
|
192
|
+
organizations: Organization[];
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
declare function useOrganizations(config: Record<string, unknown>, options?: Omit<UseQueryOptions<OrganizationsResponse, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<OrganizationsResponse, unknown>;
|
|
196
|
+
|
|
197
|
+
declare const useUpdateNav: () => void;
|
|
198
|
+
|
|
199
|
+
interface Dimensions {
|
|
200
|
+
width: number;
|
|
201
|
+
height: number;
|
|
202
|
+
}
|
|
203
|
+
declare function useWindowDimensions(): Dimensions;
|
|
204
|
+
|
|
205
|
+
type StashData = Record<string, unknown>;
|
|
206
|
+
declare function useStash(sessionId: string, options?: Omit<UseQueryOptions<StashData, unknown>, 'queryKey' | 'queryFn'>): UseQueryResult<StashData, unknown>;
|
|
207
|
+
|
|
208
|
+
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,156 @@
|
|
|
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 { avOrganizationsApi } from "@availity/api-axios";
|
|
90
|
+
var fetchOrganization = async (config) => avOrganizationsApi.getOrganizations(config);
|
|
91
|
+
function useOrganizations(config, options) {
|
|
92
|
+
return useQuery5({ queryKey: ["organizations", config], queryFn: () => fetchOrganization(config), ...options });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/useUpdateNav.ts
|
|
96
|
+
import { useEffect as useEffect4 } from "react";
|
|
97
|
+
import { useLocation } from "react-router-dom";
|
|
98
|
+
import avMessage from "@availity/message-core";
|
|
99
|
+
var useUpdateNav = () => {
|
|
100
|
+
const location = useLocation();
|
|
101
|
+
useEffect4(() => {
|
|
102
|
+
try {
|
|
103
|
+
avMessage.send({ event: "navChange", url: window.location.href });
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
}, [location]);
|
|
107
|
+
};
|
|
108
|
+
var useUpdateNav_default = useUpdateNav;
|
|
109
|
+
|
|
110
|
+
// src/useWindowDimensions.ts
|
|
111
|
+
import { useEffect as useEffect5, useState as useState3 } from "react";
|
|
112
|
+
var getWindowDimensions = () => {
|
|
113
|
+
const { innerWidth: width, innerHeight: height } = window;
|
|
114
|
+
return { width, height };
|
|
115
|
+
};
|
|
116
|
+
function useWindowDimensions() {
|
|
117
|
+
const [windowDimensions, setWindowDimensions] = useState3(getWindowDimensions());
|
|
118
|
+
useEffect5(() => {
|
|
119
|
+
const handleResize = () => {
|
|
120
|
+
setWindowDimensions(getWindowDimensions());
|
|
121
|
+
};
|
|
122
|
+
window.addEventListener("resize", handleResize);
|
|
123
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
124
|
+
}, []);
|
|
125
|
+
return windowDimensions;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/useStash.ts
|
|
129
|
+
import { avStashApi } from "@availity/api-axios";
|
|
130
|
+
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
131
|
+
var fetchStash = async (sessionId) => {
|
|
132
|
+
const response = await avStashApi.get(sessionId);
|
|
133
|
+
return response?.data;
|
|
134
|
+
};
|
|
135
|
+
function useStash(sessionId, options) {
|
|
136
|
+
return useQuery6({
|
|
137
|
+
queryKey: ["stash", sessionId],
|
|
138
|
+
queryFn: () => fetchStash(sessionId),
|
|
139
|
+
enabled: !!sessionId,
|
|
140
|
+
...options
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
useCurrentRegion,
|
|
145
|
+
useCurrentUser,
|
|
146
|
+
useEffectAsync,
|
|
147
|
+
useMount,
|
|
148
|
+
useOrganizations,
|
|
149
|
+
usePermissions,
|
|
150
|
+
useProviders,
|
|
151
|
+
useStash,
|
|
152
|
+
useTimeout,
|
|
153
|
+
useToggle,
|
|
154
|
+
useUpdateNav_default as useUpdateNav,
|
|
155
|
+
useWindowDimensions
|
|
156
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
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.0.2",
|
|
31
|
+
"@availity/message-core": "^9.0.2",
|
|
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
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"source": "./src/index.ts",
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"default": "./dist/index.js"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
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": {
|
|
@@ -33,6 +38,12 @@
|
|
|
33
38
|
"hasTypeAwareRules": true,
|
|
34
39
|
"cacheStrategy": "metadata"
|
|
35
40
|
}
|
|
41
|
+
},
|
|
42
|
+
"build": {
|
|
43
|
+
"command": "tsup src/index.ts --format esm --dts",
|
|
44
|
+
"options": {
|
|
45
|
+
"cwd": "packages/hooks"
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
}
|
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';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avRegionsApi } 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?: { id?: string; value?: string }[] };
|
|
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,24 @@
|
|
|
1
|
+
import { avUserApi } from '@availity/api-axios';
|
|
2
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
export interface CurrentUser {
|
|
5
|
+
akaname: string;
|
|
6
|
+
createDate: string;
|
|
7
|
+
currentRegion: string;
|
|
8
|
+
email: string;
|
|
9
|
+
firstName: string;
|
|
10
|
+
lastName: string;
|
|
11
|
+
id: string;
|
|
12
|
+
jobTitle: string;
|
|
13
|
+
userHasSecurityException: boolean;
|
|
14
|
+
userId: string;
|
|
15
|
+
userValidated: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const fetchUser = async () => avUserApi.me() as unknown as CurrentUser;
|
|
19
|
+
|
|
20
|
+
export default function useCurrentUser(
|
|
21
|
+
options?: Omit<UseQueryOptions<CurrentUser, unknown>, 'queryKey' | 'queryFn'>
|
|
22
|
+
): UseQueryResult<CurrentUser, unknown> {
|
|
23
|
+
return useQuery({ queryKey: ['user'], queryFn: fetchUser, ...options });
|
|
24
|
+
}
|
|
@@ -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,73 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avOrganizationsApi } from '@availity/api-axios';
|
|
3
|
+
import { AriesHookBase } from './types';
|
|
4
|
+
|
|
5
|
+
export interface Organization {
|
|
6
|
+
links: {
|
|
7
|
+
permissions: { href: string };
|
|
8
|
+
patients: { href: string };
|
|
9
|
+
self: { href: string };
|
|
10
|
+
admin: { href: string };
|
|
11
|
+
businessArrangements: { href: string };
|
|
12
|
+
users: { href: string };
|
|
13
|
+
};
|
|
14
|
+
id: string;
|
|
15
|
+
customerId: string;
|
|
16
|
+
name: string;
|
|
17
|
+
status: string;
|
|
18
|
+
statusCode: string;
|
|
19
|
+
types: { code: string; value: string }[];
|
|
20
|
+
primaryControllingAuthority: {
|
|
21
|
+
lastName: string;
|
|
22
|
+
firstName: string;
|
|
23
|
+
primaryPhone: string;
|
|
24
|
+
email: string;
|
|
25
|
+
};
|
|
26
|
+
physicalAddress: {
|
|
27
|
+
line1: string;
|
|
28
|
+
city: string;
|
|
29
|
+
state: string;
|
|
30
|
+
stateCode: string;
|
|
31
|
+
zipCode: string;
|
|
32
|
+
};
|
|
33
|
+
mailingAddress: {
|
|
34
|
+
line1: string;
|
|
35
|
+
city: string;
|
|
36
|
+
state: string;
|
|
37
|
+
stateCode: string;
|
|
38
|
+
zipCode: string;
|
|
39
|
+
};
|
|
40
|
+
billingAddress: {
|
|
41
|
+
line1: string;
|
|
42
|
+
city: string;
|
|
43
|
+
state: string;
|
|
44
|
+
stateCode: string;
|
|
45
|
+
zipCode: string;
|
|
46
|
+
};
|
|
47
|
+
regions: { code: string; value: string }[];
|
|
48
|
+
npis: { number: string }[];
|
|
49
|
+
taxIds: { number: string; type: string }[];
|
|
50
|
+
phoneNumber: {
|
|
51
|
+
areaCode: string;
|
|
52
|
+
exchange: string;
|
|
53
|
+
phoneNumber: string;
|
|
54
|
+
};
|
|
55
|
+
numberOfLicensedPhysicians: string;
|
|
56
|
+
numberOfLicensedClinicians: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface OrganizationsResponse extends AriesHookBase {
|
|
60
|
+
data: AriesHookBase['data'] & {
|
|
61
|
+
organizations: Organization[];
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fetchOrganization = async (config: Record<string, unknown>) =>
|
|
66
|
+
avOrganizationsApi.getOrganizations(config) as unknown as OrganizationsResponse;
|
|
67
|
+
|
|
68
|
+
export default function useOrganizations(
|
|
69
|
+
config: Record<string, unknown>,
|
|
70
|
+
options?: Omit<UseQueryOptions<OrganizationsResponse, unknown>, 'queryKey' | 'queryFn'>
|
|
71
|
+
): UseQueryResult<OrganizationsResponse, unknown> {
|
|
72
|
+
return useQuery({ queryKey: ['organizations', config], queryFn: () => fetchOrganization(config), ...options });
|
|
73
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { avPermissionsApi } from '@availity/api-axios';
|
|
3
|
+
import { AriesHookBase } from './types';
|
|
4
|
+
|
|
5
|
+
export interface PermissionsResponse extends AriesHookBase {
|
|
6
|
+
data: AriesHookBase['data'] & {
|
|
7
|
+
permissions: {
|
|
8
|
+
id: string;
|
|
9
|
+
description: string;
|
|
10
|
+
links: { self: { href: string } };
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const fetchPermissions = async (config: string | string[]) =>
|
|
16
|
+
avPermissionsApi.getPermissions(config) as unknown as PermissionsResponse;
|
|
17
|
+
|
|
18
|
+
export default function usePermissions(
|
|
19
|
+
config: string | string[],
|
|
20
|
+
options?: Omit<UseQueryOptions<PermissionsResponse, unknown>, 'queryKey' | 'queryFn'>
|
|
21
|
+
): UseQueryResult<PermissionsResponse, unknown> {
|
|
22
|
+
return useQuery({ queryKey: ['permissions', config], queryFn: () => fetchPermissions(config), ...options });
|
|
23
|
+
}
|