-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work in progress for removing active protocol concept
- Loading branch information
Showing
32 changed files
with
244 additions
and
365 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
app/(dashboard)/dashboard/_components/AnonymousRecruitmentTest.tsx
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,81 @@ | ||
'use client'; | ||
|
||
import type { Protocol } from '@prisma/client'; | ||
import Link from 'next/link'; | ||
import { useEffect, useState } from 'react'; | ||
import RecruitmentSwitch from '~/components/RecruitmentSwitch'; | ||
import { Button } from '~/components/ui/Button'; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from '~/components/ui/select'; | ||
import { api } from '~/trpc/client'; | ||
|
||
const AnonymousRecruitmentTest = () => { | ||
const { data: appSettings, isLoading: isLoadingAppSettings } = | ||
api.appSettings.get.useQuery(); | ||
const { data: protocolData, isLoading: isLoadingProtocols } = | ||
api.protocol.get.all.useQuery(); | ||
const [protocols, setProtocols] = useState<Protocol[]>([]); | ||
const [selectedProtocol, setSelectedProtocol] = useState<Protocol>(); | ||
|
||
useEffect(() => { | ||
if (protocolData) { | ||
setProtocols(protocolData); | ||
} | ||
}, [protocolData]); | ||
|
||
if (isLoadingAppSettings) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-4 rounded-lg border border-muted p-6"> | ||
<h1 className="text-xl">Anonymous Recruitment Test Section</h1> | ||
<div className="flex justify-between"> | ||
<p>Allow anonymous recruitment?</p> | ||
<RecruitmentSwitch /> | ||
</div> | ||
<div></div> | ||
{appSettings?.allowAnonymousRecruitment && ( | ||
<div className="flex"> | ||
<Select | ||
onValueChange={(value) => { | ||
const protocol = protocols.find( | ||
(protocol) => protocol.id.toString() === value, | ||
); | ||
|
||
setSelectedProtocol(protocol); | ||
}} | ||
value={selectedProtocol?.id.toString()} | ||
disabled={isLoadingProtocols} | ||
> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select a Protocol..." /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{protocols?.map((protocol) => ( | ||
<SelectItem key={protocol.id} value={protocol.id}> | ||
{protocol.name} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
|
||
{selectedProtocol && ( | ||
<Link href={`/onboard/${selectedProtocol?.id}`}> | ||
<Button> | ||
Start anonymous interview using {selectedProtocol.name} | ||
</Button> | ||
</Link> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default AnonymousRecruitmentTest; |
74 changes: 0 additions & 74 deletions
74
app/(dashboard)/dashboard/_components/ProtocolsTable/ActiveButton.tsx
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/(interview)/interview/no-anonymous-recruitment/page.tsx
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,11 @@ | ||
import { ErrorMessage } from '../_components/ErrorMessage'; | ||
|
||
export default function Page() { | ||
return ( | ||
<ErrorMessage | ||
title="Anonymous Recruitment Disabled" | ||
message="Anonymous recruitment is disabled for this study. Researchers may | ||
optionally enable anonymous recruitment from the dashboard" | ||
/> | ||
); | ||
} |
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,73 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { NextResponse, type NextRequest } from 'next/server'; | ||
import { api } from '~/trpc/server'; | ||
|
||
export const dynamic = 'force-dynamic'; // defaults to auto | ||
|
||
const handler = async ( | ||
req: NextRequest, | ||
{ params }: { params: { protocolId: string } }, | ||
) => { | ||
const protocolId = params.protocolId; // From route segment | ||
let postData = undefined; | ||
|
||
// We need to check the request method to see if we should parse the body - it | ||
// fails on GET requests. | ||
if (req.method === 'POST') { | ||
postData = (await req.json()) as { participantId?: string } | undefined; | ||
} | ||
|
||
const searchParams = req.nextUrl.searchParams; | ||
|
||
let participantId = | ||
searchParams.get('participantId') ?? postData?.participantId; | ||
|
||
// If no participant ID is provided in searchParams or request body, check | ||
// if anonymous recruitment is enabled to see if we should generate one. | ||
if (!participantId) { | ||
const appSettings = await api.appSettings.get.query(); | ||
|
||
if (!appSettings || !appSettings.allowAnonymousRecruitment) { | ||
return NextResponse.redirect( | ||
new URL('/interview/no-anonymous-recruitment', req.nextUrl), | ||
); | ||
} | ||
|
||
// Generate a participantID - this will be used as a **identifier** rather | ||
// than an ID. | ||
participantId = faker.string.uuid(); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log( | ||
`🕵️🚫 No participantID provided. Generated a new identifier: ${participantId}.`, | ||
); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log(`🕵️✅ Using provided participantID: ${participantId}.`); | ||
} | ||
|
||
// Create a new interview given the protocolId and participantId | ||
const { createdInterviewId, error } = await api.interview.create.mutate({ | ||
participantId, | ||
protocolId, | ||
}); | ||
|
||
if (error) { | ||
return NextResponse.json( | ||
{ error: 'Failed to create interview', errorType: error }, | ||
{ status: 500 }, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log( | ||
`🚀 Starting interview with ID ${createdInterviewId} and protocol ${protocolId}...`, | ||
); | ||
|
||
// Redirect to the interview | ||
return NextResponse.redirect( | ||
new URL(`/interview/${createdInterviewId}`, req.nextUrl), | ||
); | ||
}; | ||
|
||
export { handler as GET, handler as POST }; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.