Skip to content

Commit

Permalink
Merge 54f3919 into 9c6c3a3
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolls1 committed Feb 16, 2024
2 parents 9c6c3a3 + 54f3919 commit 3879651
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"dependencies": {
"@lifeomic/chromicons-native": "^2.16.1",
"@lifeomic/one-query": "^3.3.0",
"@lifeomic/react-client": "^1.3.0",
"@types/fhir": "^0.0.36",
"color": "^4.2.3",
"d3-scale": "3.2.1",
Expand Down
36 changes: 33 additions & 3 deletions src/hooks/rest-api.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import { createAPIHooks } from '@lifeomic/one-query';
import {
createRestAPIHooks,
RestAPIEndpoints as ClientRestAPIEndpoints,
} from '@lifeomic/react-client';
import { useHttpClient } from './useHttpClient';
import { RestAPIEndpoints } from '../types/rest-types';
import { APIQueryHooks, RequestPayloadOf } from '@lifeomic/one-query';
import {
UseQueryOptions,
UseQueryResult,
} from '@tanstack/react-query/build/lib/types';
import { AxiosRequestConfig } from 'axios';

const hooks = createAPIHooks<RestAPIEndpoints>({
export type Endpoints = RestAPIEndpoints & ClientRestAPIEndpoints;

declare type RestrictedUseQueryOptions<
Response,
TError = unknown,
Data = Response,
> = Omit<UseQueryOptions<Response, TError, Data>, 'queryKey' | 'queryFn'> & {
axios?: AxiosRequestConfig;
};

const hooks: APIQueryHooks<Endpoints> = createRestAPIHooks<Endpoints>({
name: 'lifeomic-react-native-sdk',
client: () => {
// This function is explicitly documented as being hooks-compatible.
Expand All @@ -13,7 +32,18 @@ const hooks = createAPIHooks<RestAPIEndpoints>({
},
});

export const useRestQuery = hooks.useAPIQuery;
export const useRestQuery: <
Route extends keyof Endpoints & string,
Data = Endpoints[Route]['Response'],
>(
route: Route,
payload: RequestPayloadOf<Endpoints, Route>,
options?: RestrictedUseQueryOptions<
Endpoints[Route]['Response'],
unknown,
Data
>,
) => UseQueryResult<Data> = hooks.useAPIQuery;

export const useInfiniteRestQuery = hooks.useInfiniteAPIQuery;

Expand Down
43 changes: 41 additions & 2 deletions src/hooks/useConsent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { useActiveProject } from './useActiveProject';
import { Consent, Questionnaire } from 'fhir/r3';
import { useRestQuery, useRestMutation, useRestCache } from './rest-api';
import {
useRestQuery,
useRestMutation,
useRestCache,
Endpoints,
} from './rest-api';
import { RestAPIEndpoints } from '../types/rest-types';
import { RequestPayloadOf } from '@lifeomic/one-query';
import { useQueryClient } from '@tanstack/react-query';
import {
UseMutationResult,
UseQueryResult,
useQueryClient,
} from '@tanstack/react-query';
import { ACTIVITIES_QUERY_KEY } from './useActivities';
import cloneDeep from 'lodash/cloneDeep';

Expand Down Expand Up @@ -104,6 +113,36 @@ export const useConsent = () => {
useConsentDirectives,
useUpdateProjectConsentDirective,
useShouldRenderConsentScreen,
} as {
useConsentDirectives: () => UseQueryResult<{
items: ConsentAndForm[];
}>;
useUpdateProjectConsentDirective: (
options?:
| {
onSuccess?:
| ((
data: PatchConsentDirectives['Response'],
variables: PatchConsentDirectives['Request'] & {
directiveId: string;
},
) => Promise<void> | void)
| undefined;
}
| undefined,
) => UseMutationResult<
{},
unknown,
RequestPayloadOf<
Endpoints,
'PATCH /v1/consent/directives/me/:directiveId'
>
>;
useShouldRenderConsentScreen: () => {
isLoading: boolean;
consentDirectives: ConsentAndForm[] | undefined;
shouldRenderConsentScreen: boolean;
};
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useHttpClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import axios, {
} from 'axios';
import { useAuth } from './useAuth';
import { APIClient } from '@lifeomic/one-query';
import { RestAPIEndpoints } from '../types/rest-types';
import { useActiveAccount } from './useActiveAccount';
import { RestAPIEndpoints } from '@lifeomic/react-client';

export const defaultBaseURL = 'https://api.us.lifeomic.com';
export const defaultHeaders: RawAxiosRequestHeaders = {
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,14 @@
immer "^9.0.15"
lodash "^4.17.21"

"@lifeomic/react-client@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@lifeomic/react-client/-/react-client-1.3.0.tgz#67e08ec222e0f4d3393ff30f6121711ad822a16b"
integrity sha512-ZmHZVop8+GDsvqFNXCSYQgUntCq4tDlSjkkqN0JG+ncaV7YvnLiFj1peph+U2cvuZ6INgPX8WtntAM7cWsFjxA==
dependencies:
"@types/fhir" "^0.0.41"
immer "^10.0.3"

"@material/material-color-utilities@^0.2.5":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@material/material-color-utilities/-/material-color-utilities-0.2.5.tgz#1161e8bb134297ce0a4190e405acb9d1b3951747"
Expand Down Expand Up @@ -2870,6 +2878,11 @@
resolved "https://registry.yarnpkg.com/@types/fhir/-/fhir-0.0.36.tgz#a4e4af716169b0e129e876c5ae8cbb5efeac6162"
integrity sha512-Krjb/2zKlJFjVkEPvs5QFjoYynDF2NaflR8fl4KREgJsvvHG7jrSrLdlS4zTB8E+1MgI1g0fWsz0FzniYmJlMg==

"@types/fhir@^0.0.41":
version "0.0.41"
resolved "https://registry.yarnpkg.com/@types/fhir/-/fhir-0.0.41.tgz#c5215e2fda46d694111cdd36e12fd8124a3f12d6"
integrity sha512-MAQAFufNZBZ6V0F94Nhknmmh/E3iMXFK4n/L8RkSNjKtOJnvaAJERivNOj35VVx9VCQBJbE0BHSzikfBahoRhA==

"@types/graceful-fs@^4.1.2", "@types/graceful-fs@^4.1.3":
version "4.1.6"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae"
Expand Down Expand Up @@ -6191,6 +6204,11 @@ image-size@^0.6.0:
resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.6.3.tgz#e7e5c65bb534bd7cdcedd6cb5166272a85f75fb2"
integrity sha512-47xSUiQioGaB96nqtp5/q55m0aBQSQdyIloMOc/x+QVTDZLNmXE892IIDrJ0hM1A5vcNUDD5tDffkSP5lCaIIA==

immer@^10.0.3:
version "10.0.3"
resolved "https://registry.yarnpkg.com/immer/-/immer-10.0.3.tgz#a8de42065e964aa3edf6afc282dfc7f7f34ae3c9"
integrity sha512-pwupu3eWfouuaowscykeckFmVTpqbzW+rXFCX8rQLkZzM9ftBmU/++Ra+o+L27mz03zJTlyV4UUr+fdKNffo4A==

immer@^9.0.15:
version "9.0.21"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.21.tgz#1e025ea31a40f24fb064f1fef23e931496330176"
Expand Down

0 comments on commit 3879651

Please sign in to comment.