From 6e18c2c7ef9a4fdef63deae085b55c98ddf69822 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Thu, 7 Apr 2022 10:18:09 -0400 Subject: [PATCH] init --- app/entry.server.tsx | 1 - app/routes/index.tsx | 3 +- app/routes/new.tsx | 50 +++++++++++++++++++ package-lock.json | 5 +- package.json | 1 - .../migration.sql | 3 +- prisma/schema.prisma | 1 + prisma/seed.ts | 2 +- 8 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 app/routes/new.tsx rename prisma/migrations/{20220407132919_init => 20220407141313_init}/migration.sql (80%) diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 09a11e4..aa0aa09 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -1,4 +1,3 @@ -import 'dotenv/config' import type { EntryContext } from "@remix-run/node"; import { RemixServer } from "@remix-run/react"; import { renderToString } from "react-dom/server"; diff --git a/app/routes/index.tsx b/app/routes/index.tsx index 84df05f..a893ee1 100644 --- a/app/routes/index.tsx +++ b/app/routes/index.tsx @@ -19,9 +19,10 @@ export default function Index() { return (

Welcome to Remix Heroku

+ Add a new note

Notes:

diff --git a/app/routes/new.tsx b/app/routes/new.tsx new file mode 100644 index 0000000..1b3990c --- /dev/null +++ b/app/routes/new.tsx @@ -0,0 +1,50 @@ +import type { ActionFunction } from "@remix-run/node"; +import { redirect } from "@remix-run/node"; + +import { db } from "~/utils/db.server"; + +export const action: ActionFunction = async ({ + request, +}) => { + const form = await request.formData(); + const name = form.get("name"); + const content = form.get("content"); + // we do this type check to be extra sure and to make TypeScript happy + if ( + typeof name !== "string" || + typeof content !== "string" + ) { + throw new Error(`Form not submitted correctly.`); + } + + const fields = { name, content }; + + await db.note.create({ data: fields }); + return redirect(`/`); +}; + + +export default function NewNote() { + return ( +
+

Add your own note

+
+
+ +
+
+