
+ + Indie Stack + +
++ Check the README.md file for instructions on how to get this + project deployed. +
++ Check the README.md file for instructions on how to get this + project deployed. +
+{user.email}
+ +No notes yet
+ ) : ( +{data.note.body}
++ No note selected. Select a note on the left, or{" "} + + create a new note. + +
+ ); +} diff --git a/packages/remix-dev/__tests__/fixtures/replace-remix-imports/app/routes/notes/new.tsx b/packages/remix-dev/__tests__/fixtures/replace-remix-imports/app/routes/notes/new.tsx new file mode 100644 index 00000000000..8b856d66a35 --- /dev/null +++ b/packages/remix-dev/__tests__/fixtures/replace-remix-imports/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+ + Create a New Post + +
+ ); +} diff --git a/packages/remix-dev/__tests__/fixtures/replace-remix-imports/app/routes/posts/admin/new.tsx b/packages/remix-dev/__tests__/fixtures/replace-remix-imports/app/routes/posts/admin/new.tsx new file mode 100644 index 00000000000..1b4d9f072a5 --- /dev/null +++ b/packages/remix-dev/__tests__/fixtures/replace-remix-imports/app/routes/posts/admin/new.tsx @@ -0,0 +1,89 @@ +import type { ActionFunction } from "remix"; +import { Form, redirect, json, useActionData, useTransition } from "remix"; +import invariant from "tiny-invariant"; +import { createPost } from "~/models/post.server"; + +type ActionData = + | { title: null | string; slug: null | string; markdown: null | string } + | undefined; +export const action: ActionFunction = async ({ request }) => { + const formData = await request.formData(); + + const title = formData.get("title"); + const slug = formData.get("slug"); + const markdown = formData.get("markdown"); + + const errors: ActionData = { + title: title ? null : "Title is required", + slug: slug ? null : "Slug is required", + markdown: markdown ? null : "Markdown is required", + }; + const hasErrors = Object.values(errors).some((errorMessage) => errorMessage); + if (hasErrors) { + return json