No notes yet
+ ) : ( +-
+ {data.noteListItems.map((note) => (
+
- + {note.title} + + ))} +
+ Create new note +
+ This app will get you started with Remix in no time.
+
+ {user ? (
+ <>
+ Hello {user.email} đ
+ >
+ ) : (
+ `Feel free to login!`
+ )}
+
+ Welcome to the Remix Fly Stack!
+
+ Please check the README.md file for instructions on how to get this
+ project deployed.
+
Learn more about Remix:
+No notes yet
+ ) : ( +{data.note.body}
+ ++ No note selected. Select a note on the left, or{" "} + create a new note. +
+ ); +} diff --git a/app/routes/notes/new.tsx b/app/routes/notes/new.tsx new file mode 100644 index 00000000..ae4319df --- /dev/null +++ b/app/routes/notes/new.tsx @@ -0,0 +1,116 @@ +import * as React from "react"; +import { Form, json, redirect, useActionData } from "remix"; +import type { ActionFunction } from "remix"; +import Alert from "@reach/alert"; + +import { createNote } from "~/models/note.server"; +import { requireUserId } from "~/session.server"; + +type ActionData = { + errors?: { + title?: string; + body?: string; + }; +}; + +export const action: ActionFunction = async ({ request }) => { + const userId = await requireUserId(request); + + const formData = await request.formData(); + const title = formData.get("title"); + const body = formData.get("body"); + + if (typeof title !== "string" || title.length === 0) { + return json