-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add access to applet for prolific respondent (#572)
* feat: add access to prolific respondent Few changes in this commit: - Looks for prolific URL parameters on the public link - Grant access to the applet if the prolific integration exists - Grant access to activity if the participant hasn't submitted answers for the study yet. Blocks them otherwise - New prolific account is created on submission - User redirected to prolific on submission acceptance.
- Loading branch information
Showing
26 changed files
with
359 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -185,4 +185,4 @@ export default [ | |
}, | ||
}, | ||
eslintConfigPrettier, | ||
]; | ||
]; |
20 changes: 20 additions & 0 deletions
20
src/entities/applet/api/integrations/useProlificCompletionCodeQuery.ts
This file contains 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 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.isProlificStudyValidated; | ||
type Options<TData> = QueryOptions<FetchFn, TData>; | ||
|
||
type PublicParams = { | ||
isPublic: true; | ||
publicAppletKey: string; | ||
}; | ||
|
||
type PrivateParams = { | ||
isPublic: false; | ||
appletId: string; | ||
}; | ||
|
||
export const useProlificStudyStateQuery = <TData = ReturnAwaited<FetchFn>>( | ||
params: (PublicParams | PrivateParams) & { prolificStudyId: null | string }, | ||
options?: Options<TData>, | ||
) => { | ||
return useBaseQuery( | ||
['prolificStudyValidated', params], | ||
() => { | ||
if (params.isPublic) { | ||
return ProlificService.isProlificStudyValidated( | ||
params.publicAppletKey, | ||
params.prolificStudyId ?? undefined, | ||
); | ||
} | ||
return ProlificService.isProlificStudyValidated(params.appletId); | ||
}, | ||
options, | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/entities/applet/api/integrations/useProlificUserExistsQuery.ts
This file contains 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.prolificUserExists; | ||
type Options<TData> = QueryOptions<FetchFn, TData>; | ||
|
||
type Params = { | ||
prolificPid: string; | ||
studyId: string; | ||
}; | ||
|
||
export const useProlificUserExistsQuery = <TData = ReturnAwaited<FetchFn>>( | ||
params: Params, | ||
options?: Options<TData>, | ||
) => { | ||
return useBaseQuery( | ||
['prolificUserExists', params], | ||
() => ProlificService.prolificUserExists(params.prolificPid, params.studyId), | ||
options, | ||
); | ||
}; |
This file contains 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 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 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 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 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 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 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 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 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 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.