Skip to content

Commit

Permalink
Merge pull request #554 from lifeomic/wait-for-subject-id
Browse files Browse the repository at this point in the history
feat: Add option to wait for subjectId
  • Loading branch information
bruce-glazier authored May 17, 2024
2 parents 3d230e2 + 87841d6 commit 83be97d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/DeveloperConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export type DeveloperConfig = {
skipInviteParams?: boolean;
tileListMode?: 'list' | 'column';
showPreLoginWarning?: boolean;
/***
* Instead of showing the invite required screen when no patientId
* is found retry indefinitely. This is useful if createPatientMapping rule
* is present for a given account and we do not expect the usual invite to project flow.
***/
keepWaitingForPatientId?: boolean;
};

export type LogoHeaderConfig = { [key in Route]?: LogoHeaderOptions };
Expand Down
30 changes: 30 additions & 0 deletions src/hooks/useActiveProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { t } from 'i18next';
import { InviteRequiredScreen } from '../screens/InviteRequiredScreen';
import { useRestQuery } from './rest-api';
import { useActiveAccount } from './useActiveAccount';
import { useDeveloperConfig } from './useDeveloperConfig';
import { tID } from '../common/testID';

const selectedProjectIdKey = 'selectedProjectIdKey';

Expand Down Expand Up @@ -115,6 +117,7 @@ export type ActiveProjectContextProviderProps = {

export const ActiveProjectContextProvider: React.FC<ActiveProjectContextProviderProps> =
withAccountRequired(({ children }) => {
const { keepWaitingForPatientId } = useDeveloperConfig();
const query = combineQueries([useSubjectProjects(), useMe(), useUser()]);
const userId = query.data?.[2].id;
const [storedProjectIdResult, setStoredProjectId, isStorageLoaded] =
Expand Down Expand Up @@ -151,6 +154,16 @@ export const ActiveProjectContextProvider: React.FC<ActiveProjectContextProvider

const state = calculateState();

useEffect(() => {
if (
!query.isRefetching &&
state.status === 'not-a-patient' &&
keepWaitingForPatientId
) {
query.refetchAll();
}
}, [keepWaitingForPatientId, query, state.status]);

// This effect handles setting the initial value in async storage.
const activeProjectId =
state.status === 'success' ? state.activeProject.id : undefined;
Expand All @@ -169,6 +182,23 @@ export const ActiveProjectContextProvider: React.FC<ActiveProjectContextProvider
}
// TODO: handle error state.
if (state.status === 'not-a-patient') {
if (keepWaitingForPatientId) {
return (
<ActivityIndicatorView
testID={tID('waiting-for-patient-loader')}
style={{
text: {
alignSelf: 'center',
},
}}
message={t(
'expected-waiting-for-account-and-project',
'Please wait while we complete the initial setup for your first login.',
)}
/>
);
}

return <InviteRequiredScreen />;
}

Expand Down

0 comments on commit 83be97d

Please sign in to comment.