Skip to content

Commit aaa79ac

Browse files
Merge pull request #566 from lifeomic/add-require-consent-flag
feat: Add config option to require an active consent
2 parents 72da60e + 32dc615 commit aaa79ac

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/common/DeveloperConfig.ts

+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ export type DeveloperConfig = {
145145
* is present for a given account and we do not expect the usual invite to project flow.
146146
***/
147147
keepWaitingForPatientId?: boolean;
148+
/***
149+
* Instead of proceeding further into the LoggedInStack show a loading indicator if
150+
* there the user has no active consents and keep checking for either new consent assignment or active consent status.
151+
*/
152+
activeConsentRequired?: boolean;
148153
};
149154

150155
export type LogoHeaderConfig = { [key in Route]?: LogoHeaderOptions };

src/hooks/useConsent.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
} from '@tanstack/react-query';
1616
import { ACTIVITIES_QUERY_KEY } from './useActivities';
1717
import cloneDeep from 'lodash/cloneDeep';
18+
import { useDeveloperConfig } from './useDeveloperConfig';
19+
import { useEffect } from 'react';
1820

1921
type PatchConsentDirectives =
2022
RestAPIEndpoints['PATCH /v1/consent/directives/me/:directiveId'];
@@ -95,15 +97,36 @@ export const useConsent = () => {
9597
data: directivesData,
9698
isLoading: loadingDirectives,
9799
isFetched: fetchedDirectives,
100+
refetch: refetchDirectives,
101+
isRefetching: refetchingDirectives,
98102
} = useConsentDirectives();
99-
103+
const { activeConsentRequired } = useDeveloperConfig();
104+
const activeConsents = directivesData?.items?.filter(
105+
(c) => c.status === 'active',
106+
);
107+
const hasActiveConsent = !!activeConsents?.length;
100108
const consentDirectives = directivesData?.items?.filter(
101109
(c) => c.status === 'proposed' || c.status === 'rejected',
102110
);
103111
const shouldRenderConsentScreen = !!consentDirectives?.length;
112+
const consentCheckNotSatisfied =
113+
activeConsentRequired && !hasActiveConsent && !shouldRenderConsentScreen;
114+
115+
useEffect(() => {
116+
const intervalId = setInterval(() => {
117+
if (consentCheckNotSatisfied && !refetchingDirectives) {
118+
refetchDirectives();
119+
} else {
120+
clearInterval(intervalId);
121+
}
122+
}, 2000);
123+
124+
return () => clearInterval(intervalId);
125+
}, [consentCheckNotSatisfied, refetchDirectives, refetchingDirectives]);
104126

105127
return {
106-
isLoading: !fetchedDirectives || loadingDirectives,
128+
isLoading:
129+
!fetchedDirectives || loadingDirectives || consentCheckNotSatisfied,
107130
consentDirectives,
108131
shouldRenderConsentScreen,
109132
};
@@ -142,6 +165,8 @@ export const useConsent = () => {
142165
isLoading: boolean;
143166
consentDirectives: ConsentAndForm[] | undefined;
144167
shouldRenderConsentScreen: boolean;
168+
hasActiveConsent: boolean;
169+
refetchDirectives: () => void;
145170
};
146171
};
147172
};

0 commit comments

Comments
 (0)