Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
cxjohn committed Aug 31, 2023
2 parents a6c4aa2 + 6a12a70 commit a04f1b6
Show file tree
Hide file tree
Showing 50 changed files with 163 additions and 1,039 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:staging": "CLIENT_BACKEND=staging npx playwright test",
"test:production": "CLIENT_BACKEND=production npx playwright test",
"test:ipfs": "CLIENT_BACKEND=ipfs npx playwright test",
"build": "DISABLE_ESLINT_PLUGIN=true CLIENT_BACKEND=staging next build",
"build": "next build",
"start": "next start",
"post-update": "yarn upgrade --latest",
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
Expand All @@ -24,7 +24,7 @@
"@json2csv/plainjs": "^6.1.2",
"@mui/material": "^5.11.3",
"@next/font": "^13.1.1",
"@prisma/client": "5.1.1",
"@prisma/client": "^5.1.1",
"@supabase/auth-helpers-nextjs": "^0.5.2",
"@supabase/auth-helpers-react": "^0.3.1",
"@supabase/auth-ui-react": "^0.2.6",
Expand Down Expand Up @@ -58,6 +58,7 @@
"react-datetime": "^3.2.0",
"react-dom": "^18.2.0",
"react-draft-wysiwyg": "^1.15.0",
"react-error-boundary": "^4.0.11",
"supabase": "^1.42.7",
"tailwindcss": "^3.2.4",
"trpc": "^0.11.3",
Expand All @@ -80,7 +81,7 @@
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"csv-parser": "^3.0.0",
"eslint": "^8.47.0",
"eslint": "^8.32.0",
"eslint-config-next": "^13.1.4",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
Expand Down
5 changes: 3 additions & 2 deletions prisma/migrations/0_init/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CREATE TABLE "evaluation" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"name" TEXT,
"status" TEXT NOT NULL DEFAULT 'draft',
"description" TEXT NOT NULL DEFAULT '',
"description" TEXT DEFAULT '',
"start_time" TIMESTAMPTZ(6),
"end_time" TIMESTAMPTZ(6),
"form_description" TEXT,
Expand All @@ -19,6 +19,7 @@ CREATE TABLE "evaluation_field" (
"subheading" TEXT,
"char_count" INTEGER,
"placeholder" TEXT,
"field_order" INTEGER,

CONSTRAINT "evaluation_field_pkey" PRIMARY KEY ("id")
);
Expand All @@ -42,7 +43,7 @@ CREATE TABLE "invitation" (
"evaluation_id" UUID NOT NULL,
"code" TEXT,
"voice_credits" INTEGER,
"remaining_uses" INTEGER NOT NULL DEFAULT 100,
"remaining_uses" INTEGER NOT NULL,
"is_sme" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "invitation_pkey" PRIMARY KEY ("id")
Expand Down
11 changes: 11 additions & 0 deletions prisma/migrations/1_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- Made the column `description` on table `evaluation` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "evaluation" ALTER COLUMN "description" SET NOT NULL;

-- AlterTable
ALTER TABLE "invitation" ALTER COLUMN "remaining_uses" SET DEFAULT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "evaluation" ADD COLUMN "is_upload" BOOLEAN;
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ model EvaluationField {
subheading String?
char_count Int?
placeholder String?
field_order Int?
evaluation Evaluation? @relation(fields: [evaluation_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
submission_field SubmissionField[]
Expand Down Expand Up @@ -103,6 +104,7 @@ model User {
github_user_id String? @db.Uuid
role String @default("user")
evaluator Evaluator[]
test String?
@@map("user")
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import LoadingSpinner from "src/components/shared/LoadingSpinner";
import SubTitle from "src/components/shared/SubTitle";
import DashboardHeader from "./DashboardHeader";
import { EvaluationCard } from "./EvaluationCard";
import { EvaluationEmptyCard } from "./EvaluationEmptyCard";
import { EvaluationItem } from "./EvaluationItem";
import { useDashboardStore } from "./DashboardStore";
import { trpc } from "src/lib/trpc";
import { ErrorBoundary } from "react-error-boundary";

export default function Dashboard() {
const store = useDashboardStore();
const [spinner, setSpinner] = useState(1);

const store = useDashboardStore(setSpinner)();
// const store = useDashboardStore();

console.log(spinner);

useEffect(() => {
store.load();
}, [store.fetching]);

if (store.fetching) return <LoadingSpinner />;
if (store.error) return <p>Oh no... {store.error.message}</p>;

return (
<>
<DashboardHeader store={store} />
Expand Down
105 changes: 73 additions & 32 deletions src/components/dashboard/DashboardStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { create } from "zustand";
import { Evaluation, rpc, DashboardEvaluation } from "src/lib";
import { Evaluation as evaluation } from "@prisma/client";
import { trpc } from "src/lib/trpc";
import { Dispatch, SetStateAction } from "react";

export interface DashboardStore {
fetching: boolean;
Expand All @@ -11,36 +12,76 @@ export interface DashboardStore {
createEvaluation: () => Promise<evaluation | Error>;
}

export const useDashboardStore = create<DashboardStore>()((set, get) => ({
fetching: true,
evaluations: [],

load: async () => {
trpc()
.user.getDashboardStore.query()
.then((data) => {
if (data instanceof Error) {
console.error(`ERROR -- rpc call getUserEvaluations failed`, data);
return;
}

set({
fetching: false,
evaluations: data,
export function useDashboardStore(setSpinner: Dispatch<SetStateAction<number>>) {
return create<DashboardStore>()((set, get) => ({
fetching: true,
evaluations: [],

load: async () => {
trpc()
.user.getDashboardStore.query()
.then((data) => {
if (data instanceof Error) {
console.error(`ERROR -- rpc call getUserEvaluations failed`, data);
return;
}

set({
fetching: false,
evaluations: data,
});

setSpinner((prev) => prev + 1);
});
});
},

createEvaluation: async (): Promise<evaluation | Error> => {
const newEvaluation: evaluation = {
...Evaluation.init(),
};

const res = await trpc().admin.createEvaluation.mutate(newEvaluation);

if (res instanceof Error) {
return res;
}
return newEvaluation;
},
}));
},

createEvaluation: async (): Promise<evaluation | Error> => {
const newEvaluation: evaluation = {
...Evaluation.init(),
};

const res = await trpc().admin.createEvaluation.mutate(newEvaluation);

if (res instanceof Error) {
return res;
}
return newEvaluation;
},
}));
}

// setSpinner: Dispatch<SetStateAction<number>>

// export const useDashboardStore = create<DashboardStore>()((set, get) => ({
// fetching: true,
// evaluations: [],

// load: async () => {
// trpc()
// .user.getDashboardStore.query()
// .then((data) => {
// if (data instanceof Error) {
// console.error(`ERROR -- rpc call getUserEvaluations failed`, data);
// return;
// }

// set({
// fetching: false,
// evaluations: data,
// });
// });
// },

// createEvaluation: async (): Promise<evaluation | Error> => {
// const newEvaluation: evaluation = {
// ...Evaluation.init(),
// };

// const res = await trpc().admin.createEvaluation.mutate(newEvaluation);

// if (res instanceof Error) {
// return res;
// }
// return newEvaluation;
// },
// }));
16 changes: 15 additions & 1 deletion src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { ErrorBoundary } from "react-error-boundary";

type LayoutProps = {
children?: React.ReactNode;
};

function fallbackRender({ error, resetErrorBoundary }: { error: Error; resetErrorBoundary: () => void }) {
// Call resetErrorBoundary() to reset the error boundary and retry the render.
console.log("caught error", error);

return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: "red" }}>{error.message}</pre>
</div>
);
}

export default function Layout({ children }: LayoutProps) {
return (
<div
className="w-full min-h-screen h-full bg-[#fafafa] text-offblack flex flex-col relative"
onDragOver={(evt) => evt.preventDefault()}
onDrop={(evt) => evt.preventDefault()}
>
{children}
<ErrorBoundary fallbackRender={fallbackRender}>{children}</ErrorBoundary>
</div>
);
}
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createBrowserSupabaseClient } from "@supabase/auth-helpers-nextjs";
import { SessionContextProvider } from "@supabase/auth-helpers-react";
import AuthWrapper from "src/components/layout/AuthWrapper";
import Head from "next/head";
import Script from "next/script";

const aileron = localFont({
src: [
Expand Down
4 changes: 4 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { user } from "./routes/user";
export const appRouter = router({
admin: admin,
user: user,

test1: publicProcedure.query(async () => {
throw new Error("test1");
}),
});

// Export type router type signature,
Expand Down
3 changes: 0 additions & 3 deletions supabase/.gitignore

This file was deleted.

72 changes: 0 additions & 72 deletions supabase/config.toml

This file was deleted.

11 changes: 0 additions & 11 deletions supabase/migrations/20230303165836_create_evaluation_table.sql

This file was deleted.

13 changes: 0 additions & 13 deletions supabase/migrations/20230303170406_create_user_table.sql

This file was deleted.

Loading

0 comments on commit a04f1b6

Please sign in to comment.