Skip to content

Commit 2b2ce19

Browse files
authored
Merge pull request #1 from SevanBadal/sevo/fix-create-user
Create User: Fix 500 Server Error and 400 Server Error
2 parents 6613036 + 88890c2 commit 2b2ce19

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

.env

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env*
3031

3132
# vercel
3233
.vercel

app/api/users/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { z } from "zod";
33
import prisma from "@/prisma/client";
44

55
const createUserSchema = z.object({
6-
firstname: z.string().min(1).max(25),
7-
lastname: z.string().min(1).max(25),
6+
firstName: z.string().min(1).max(25),
7+
lastName: z.string().min(1).max(25),
88
notes: z.string().min(1),
99
});
1010

@@ -14,10 +14,10 @@ export async function POST(request: NextRequest) {
1414
if (!validation.success)
1515
return NextResponse.json(validation.error.errors, { status: 400 });
1616

17-
const newUser = await prisma.user.create({
17+
const newUser = await prisma.users.create({
1818
data: {
19-
firstname: body.firstname,
20-
lastname: body.lastname,
19+
firstname: body.firstName,
20+
lastname: body.lastName,
2121
notes: body.notes,
2222
},
2323
});

app/users/new/page.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
"use client";
1+
'use client';
22
import Link from "next/link";
3-
import SimpleMDE from "react-simplemde-editor";
43
import "easymde/dist/easymde.min.css";
54
import { useForm, Controller } from "react-hook-form";
65
import { Button, TextField } from "@radix-ui/themes";
76
import axios from "axios";
87
import { useRouter } from "next/navigation";
8+
import dynamic from "next/dynamic";
9+
10+
const SimpleMdeEditor = dynamic(
11+
() => import("react-simplemde-editor"),
12+
{ ssr: false }
13+
);
914

1015
const NewUser = () => {
1116
const router = useRouter();
@@ -17,12 +22,13 @@ const NewUser = () => {
1722
const {
1823
register,
1924
control,
25+
reset,
2026
handleSubmit,
2127
formState: { errors },
2228
} = useForm<UserForm>();
2329
const onSubmit = handleSubmit(async (data) => {
2430
await axios.post("/api/users", data);
25-
router.push("/users/new");
31+
reset()
2632
});
2733
// firstName and lastName will have correct type
2834
return (
@@ -45,7 +51,7 @@ const NewUser = () => {
4551
name="notes"
4652
control={control}
4753
render={({ field }) => (
48-
<SimpleMDE placeholder="notes..." {...field} />
54+
<SimpleMdeEditor placeholder="notes..." {...field} />
4955
)}
5056
/>
5157

0 commit comments

Comments
 (0)