From 8f59db0f813e84497f80141d9ccb11502c41a632 Mon Sep 17 00:00:00 2001 From: Joshua Melville Date: Mon, 13 Nov 2023 17:52:40 +0200 Subject: [PATCH] linting --- .../_components/ActiveProtocolSwitch.tsx | 18 ++++---- .../_components/ImportProtocolModal.tsx | 41 ------------------- app/(interview)/interview/new/page.tsx | 2 +- .../OnboardSteps/UploadProtocol.tsx | 10 +---- components/ui/ErrorDialog.tsx | 1 - server/routers/protocol.ts | 32 +++++++-------- 6 files changed, 29 insertions(+), 75 deletions(-) delete mode 100644 app/(dashboard)/dashboard/protocols/_components/ImportProtocolModal.tsx 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 - - - - - ); -}; - -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 && ( - - )} +