forked from ChildMindInstitute/mindlogger-web-refactor
-
Notifications
You must be signed in to change notification settings - Fork 0
Add applet prolific responder #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hamzace
wants to merge
1
commit into
dev
Choose a base branch
from
add-applet-prolific-responder
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,10 @@ module.exports = { | |
| pattern: '@(~app|~shared|~features|~pages|~entities)/**', | ||
| group: 'internal', | ||
| }, | ||
| { | ||
| pattern: '~/lib/**', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merger with rule above |
||
| group: 'internal', | ||
| }, | ||
| ], | ||
| pathGroupsExcludedImportTypes: ['internal', 'react'], | ||
| 'newlines-between': 'always', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/entities/applet/api/integrations/useProlificCompletionCodeQuery.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { ProlificService, QueryOptions, ReturnAwaited, useBaseQuery } from '~/shared/api'; | ||
|
|
||
| type FetchFn = typeof ProlificService.getStudyCompletionCodes; | ||
| type Options<TData> = QueryOptions<FetchFn, TData>; | ||
|
|
||
| type Params = { | ||
| appletId: string; | ||
| studyId: string; | ||
| }; | ||
|
|
||
| export const useProlificCompletionCodeQuery = <TData = ReturnAwaited<FetchFn>>( | ||
| params: Params, | ||
| options?: Options<TData>, | ||
| ) => { | ||
| return useBaseQuery( | ||
| ['prolificCompletionCode', params], | ||
| () => ProlificService.getStudyCompletionCodes(params.appletId, params.studyId), | ||
| options, | ||
| ); | ||
| }; |
33 changes: 33 additions & 0 deletions
33
src/entities/applet/api/integrations/useProlificIntegrationEnabledQuery.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { ProlificService, QueryOptions, ReturnAwaited, useBaseQuery } from '~/shared/api'; | ||
|
|
||
| type FetchFn = typeof ProlificService.isProlificIntergrationEnabled; | ||
| type Options<TData> = QueryOptions<FetchFn, TData>; | ||
|
|
||
| type PublicParams = { | ||
| isPublic: true; | ||
| publicAppletKey: string; | ||
| }; | ||
|
|
||
| type PrivateParams = { | ||
| isPublic: false; | ||
| appletId: string; | ||
| }; | ||
|
|
||
| export const useProlificIntegrationStateQuery = <TData = ReturnAwaited<FetchFn>>( | ||
| params: (PublicParams | PrivateParams) & { prolificStudyId: null | string }, | ||
| options?: Options<TData>, | ||
| ) => { | ||
| return useBaseQuery( | ||
| ['prolificIntegrationEnabled', params], | ||
| () => { | ||
|
elierotenberg marked this conversation as resolved.
|
||
| if (params.isPublic) { | ||
| return ProlificService.isProlificIntergrationEnabled( | ||
| params.publicAppletKey, | ||
| params.prolificStudyId ?? undefined, | ||
| ); | ||
| } | ||
| return ProlificService.isProlificIntergrationEnabled(params.appletId); | ||
| }, | ||
| options, | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| import { useCallback } from 'react'; | ||
|
|
||
| import { t } from 'i18next'; | ||
| import type { NavigateOptions } from 'react-router/dist/lib/context'; | ||
|
|
||
| import { useUpdateProlificParams } from './useSaveProlificParams'; | ||
|
|
||
| import { ActivityPipelineType } from '~/abstract/lib'; | ||
| import { appletModel } from '~/entities/applet'; | ||
| import { useProlificCompletionCodeQuery } from '~/entities/applet/api/integrations/useProlificCompletionCodeQuery'; | ||
| import { prolificParamsSelector } from '~/entities/applet/model/selectors'; | ||
| import { useBanners } from '~/entities/banner/model'; | ||
| import { ActivityFlowDTO } from '~/shared/api'; | ||
| import ROUTES from '~/shared/constants/routes'; | ||
| import { useCustomNavigation } from '~/shared/utils'; | ||
| import { useAppSelector, useCustomNavigation } from '~/shared/utils'; | ||
|
|
||
| type CompletionType = 'regular' | 'autoCompletion'; | ||
|
|
||
|
|
@@ -36,6 +42,22 @@ export const useEntityComplete = (props: Props) => { | |
| const { entityCompleted, flowUpdated, getGroupProgress } = | ||
| appletModel.hooks.useGroupProgressStateManager(); | ||
|
|
||
| const prolificParams = useAppSelector(prolificParamsSelector); | ||
| const { data: completionCodesReponse, isError: isCompletionCodesReponseError } = | ||
| useProlificCompletionCodeQuery( | ||
| { | ||
| appletId: props.appletId, | ||
| studyId: prolificParams?.studyId ?? '', | ||
| }, | ||
| { | ||
| enabled: !!prolificParams, | ||
| }, | ||
| ); | ||
|
|
||
| const { addErrorBanner } = useBanners(); | ||
|
|
||
| const { clearProlificParams } = useUpdateProlificParams(); | ||
|
|
||
| const completeEntityAndRedirect = useCallback( | ||
| (completionType: CompletionType) => { | ||
| entityCompleted({ | ||
|
|
@@ -50,6 +72,30 @@ export const useEntityComplete = (props: Props) => { | |
| return; | ||
| } | ||
|
|
||
| if (prolificParams && props.publicAppletKey) { | ||
| if (!isCompletionCodesReponseError && completionCodesReponse) { | ||
| clearProlificParams(); // Resetting redux state after completion | ||
|
|
||
| const { completionCodes } = completionCodesReponse.data; | ||
| for (const code of completionCodes) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move up for of |
||
| if (code.codeType === 'COMPLETED') { | ||
| window.location.replace( | ||
| `https://app.prolific.com/submissions/complete?cc=${code.code}`, | ||
| ); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| addErrorBanner({ children: t('prolific.nocode'), duration: null }); | ||
| return navigator.navigate( | ||
| ROUTES.publicJoin.navigateTo(props.publicAppletKey, prolificParams), | ||
| { | ||
| replace: true, | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (props.publicAppletKey) { | ||
| return navigator.navigate(ROUTES.publicJoin.navigateTo(props.publicAppletKey), { | ||
| replace: true, | ||
|
|
@@ -70,6 +116,11 @@ export const useEntityComplete = (props: Props) => { | |
| entityCompleted, | ||
| isInMultiInformantFlow, | ||
| navigator, | ||
| prolificParams, | ||
| completionCodesReponse, | ||
| isCompletionCodesReponseError, | ||
| clearProlificParams, | ||
| addErrorBanner, | ||
| props.activityId, | ||
| props.appletId, | ||
| props.eventId, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { useCallback } from 'react'; | ||
|
|
||
| import { actions } from '../slice'; | ||
| import type { ProlificUrlParamsPayload } from '../types'; | ||
|
|
||
| import { useAppDispatch } from '~/shared/utils'; | ||
|
|
||
| export const useUpdateProlificParams = () => { | ||
| const dispatch = useAppDispatch(); | ||
|
|
||
| const saveProlificParams = useCallback( | ||
| (payload: ProlificUrlParamsPayload) => { | ||
| dispatch(actions.saveProlificParams(payload)); | ||
| }, | ||
| [dispatch], | ||
| ); | ||
|
|
||
| const clearProlificParams = useCallback(() => { | ||
| dispatch(actions.clearProlificParams()); | ||
| }, [dispatch]); | ||
|
|
||
| return { saveProlificParams, clearProlificParams }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use absolute import aliases instead