Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Nov 13, 2023
1 parent 317b360 commit 8f59db0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 75 deletions.
18 changes: 11 additions & 7 deletions app/(dashboard)/dashboard/_components/ActiveProtocolSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ const ActiveProtocolSwitch = ({

const { data: isActive } = api.protocol.active.is.useQuery(hash, {
initialData,
refetchOnMount: false,
onError: (err) => {
throw new Error(err.message);
},
});

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: () => {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion app/(interview)/interview/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ErrorMessage
Expand Down
10 changes: 2 additions & 8 deletions app/(onboard)/_components/OnboardSteps/UploadProtocol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { Button } from '~/components/ui/Button';
import { useOnboardingContext } from '../OnboardingProvider';

function ConfigureStudy() {
const [protocolUploaded, setProtocolUploaded] = useState(false);
const [protocolUploaded] = useState(false);
const { currentStep, setCurrentStep } = useOnboardingContext();

const handleProtocolUploaded = () => {
setProtocolUploaded(true);
};

const handleNextStep = () => {
setCurrentStep(currentStep + 1).catch(() => {});
};
Expand All @@ -32,9 +28,7 @@ function ConfigureStudy() {
<div className="flex justify-between">
{protocolUploaded && <Check />}
</div>
{!protocolUploaded && (
<ProtocolUploader onUploaded={handleProtocolUploaded} />
)}
<ProtocolUploader />
</div>
<div className="flex justify-start">
<Button onClick={handleNextStep}>
Expand Down
1 change: 0 additions & 1 deletion components/ui/ErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
AlertDialog,
AlertDialogContent,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
} from '~/components/ui/AlertDialog';

Expand Down
32 changes: 15 additions & 17 deletions server/routers/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);

Expand All @@ -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: {
Expand Down

0 comments on commit 8f59db0

Please sign in to comment.