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

+
+
+ +
+
+