-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
173 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
export async function GET( | ||
_: Request, | ||
{ params }: { params: { name: string } }, | ||
) { | ||
const users = await prisma.user.findMany({ | ||
where: { | ||
name: { | ||
equals: params.name, | ||
mode: "insensitive", | ||
}, | ||
}, | ||
select: { | ||
name: true, | ||
kills: true, | ||
deaths: true, | ||
wins: true, | ||
}, | ||
}); | ||
|
||
if (users.length > 1) { | ||
return Response.json(`More than one user with name ${params.name} found`, { | ||
status: 500, | ||
}); | ||
} | ||
|
||
if (users.length === 0) { | ||
return Response.json(`Could not find user with name ${params.name}`, { | ||
status: 400, | ||
}); | ||
} | ||
|
||
return Response.json(users[0]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use client"; | ||
|
||
import { useContext } from "react"; | ||
import { Controller, SubmitHandler, useForm } from "react-hook-form"; | ||
import { useSWRConfig } from "swr"; | ||
import { ErrorContext } from "./App"; | ||
import { UserBody } from "@/lib/user"; | ||
|
||
export default function NameForm() { | ||
const { mutate } = useSWRConfig(); | ||
const { handleSubmit, control } = useForm<UserBody>(); | ||
const { setError } = useContext(ErrorContext); | ||
|
||
const onSubmit: SubmitHandler<UserBody> = async ({ name }) => { | ||
const res = await fetch("/api/user", { | ||
method: "POST", | ||
headers: { | ||
"Content-type": "application/json", | ||
}, | ||
body: JSON.stringify({ name }), | ||
}); | ||
|
||
if (!res.ok) { | ||
setError(await res.json()); | ||
return; | ||
} | ||
|
||
mutate("/api/user"); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<h1 className="text-3xl">Set Username</h1> | ||
<p className="text-center"> | ||
Please choose a username. You won't be able to change this in the | ||
future. | ||
</p> | ||
<Controller | ||
name="name" | ||
control={control} | ||
render={({ field }) => ( | ||
<input | ||
{...field} | ||
className="input input-bordered" | ||
placeholder="Username" | ||
required | ||
/> | ||
)} | ||
/> | ||
<button className="btn btn-primary">Save</button> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters