diff --git a/app/(dashboard)/dashboard/_components/ActiveProtocolSwitch.tsx b/app/(dashboard)/dashboard/_components/ActiveProtocolSwitch.tsx index 03d05889..432b7168 100644 --- a/app/(dashboard)/dashboard/_components/ActiveProtocolSwitch.tsx +++ b/app/(dashboard)/dashboard/_components/ActiveProtocolSwitch.tsx @@ -16,6 +16,7 @@ const ActiveProtocolSwitch = ({ const { data: isActive } = api.protocol.active.is.useQuery(hash, { initialData, + refetchOnMount: false, onError: (err) => { throw new Error(err.message); }, @@ -23,19 +24,22 @@ const ActiveProtocolSwitch = ({ const { mutateAsync: setActive } = api.protocol.active.set.useMutation({ async onMutate(variables) { - const { input: newState, hash } = variables; + const { input: newState } = variables; + await utils.protocol.active.get.cancel(); + const previous = utils.protocol.active.get.getData(); - const previousState = utils.protocol.active.get.getData(); + if (previous) { + utils.protocol.active.get.setData(undefined, { + ...previous, + active: newState, + }); - if (hash) { - utils.protocol.active.get.setData(hash, newState); + return previous; } - - return previousState; }, onError: (err, _newState, previousState) => { - utils.protocol.active.get.setData(hash, previousState); + utils.protocol.active.get.setData(undefined, previousState); throw new Error(err.message); }, onSuccess: () => { diff --git a/app/(dashboard)/dashboard/protocols/_components/ImportProtocolModal.tsx b/app/(dashboard)/dashboard/protocols/_components/ImportProtocolModal.tsx deleted file mode 100644 index 8d822150..00000000 --- a/app/(dashboard)/dashboard/protocols/_components/ImportProtocolModal.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { Button } from '~/components/ui/Button'; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, - DialogTrigger, -} from '~/components/ui/dialog'; -import ProtocolUploader from '~/app/(dashboard)/dashboard/_components/ProtocolUploader'; -import { useState } from 'react'; - -interface ImportProtocolModalProps { - onProtocolUploaded: () => void; -} - -const ImportProtocolModal = ({ - onProtocolUploaded, -}: ImportProtocolModalProps) => { - const [openModal, setOpenModal] = useState(false); - - const handleUploaded = () => { - onProtocolUploaded(); - setOpenModal(false); - }; - - return ( - - - Import protocol - - - - Import Protocol - - - - - ); -}; - -export default ImportProtocolModal; diff --git a/app/(interview)/interview/new/page.tsx b/app/(interview)/interview/new/page.tsx index 3b341b7f..6d79d43b 100644 --- a/app/(interview)/interview/new/page.tsx +++ b/app/(interview)/interview/new/page.tsx @@ -18,7 +18,7 @@ export default async function Page({ }; }) { // check if active protocol exists - const activeProtocol = await api.protocol.getCurrentlyActive.query(); + const activeProtocol = await api.protocol.active.get.query(); if (!activeProtocol) { return ( { - setProtocolUploaded(true); - }; - const handleNextStep = () => { setCurrentStep(currentStep + 1).catch(() => {}); }; @@ -32,9 +28,7 @@ function ConfigureStudy() { {protocolUploaded && } - {!protocolUploaded && ( - - )} + diff --git a/components/ui/ErrorDialog.tsx b/components/ui/ErrorDialog.tsx index ea952663..879dbbe8 100644 --- a/components/ui/ErrorDialog.tsx +++ b/components/ui/ErrorDialog.tsx @@ -8,7 +8,6 @@ import { AlertDialog, AlertDialogContent, AlertDialogTitle, - AlertDialogDescription, AlertDialogAction, } from '~/components/ui/AlertDialog'; diff --git a/server/routers/protocol.ts b/server/routers/protocol.ts index 953f09e0..f7cba90c 100644 --- a/server/routers/protocol.ts +++ b/server/routers/protocol.ts @@ -5,6 +5,7 @@ import { z } from 'zod'; import { hash } from 'ohash'; import { Prisma } from '@prisma/client'; import { utapi } from '~/app/api/uploadthing/core'; +import type { Protocol } from '@codaco/shared-consts'; const updateActiveProtocolSchema = z.object({ input: z.boolean(), @@ -194,23 +195,20 @@ export const protocolRouter = router({ }), }), insert: protectedProcedure - .input( - z.object({ - protocol: z - .object({ - lastModified: z.string(), - schemaVersion: z.number(), - stages: z.array(z.any()), - codebook: z.record(z.any()), - description: z.string().optional(), - }) - .passthrough(), // Don't strip keys not defined here so that hashing can use all properties - protocolName: z.string(), - assets: assetInsertSchema, - }), - ) + .input((value) => { + return z + .object({ + protocol: z.unknown(), + protocolName: z.string(), + assets: assetInsertSchema, + }) + .passthrough() + .parse(value); + }) .mutation(async ({ input }) => { - const { protocol, protocolName, assets } = input; + const { protocol: inputProtocol, protocolName, assets } = input; + + const protocol = inputProtocol as Protocol; try { const protocolHash = hash(protocol); @@ -221,7 +219,7 @@ export const protocolRouter = router({ lastModified: protocol.lastModified, name: protocolName, schemaVersion: protocol.schemaVersion, - stages: protocol.stages, + stages: JSON.stringify(protocol.stages), codebook: protocol.codebook, description: protocol.description, assets: {