generated from namidapoo/next15-shadcn-use-bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from namidapoo/feat/username-input
feat: ユーザー名を検索可能にする
- Loading branch information
Showing
22 changed files
with
516 additions
and
92 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 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,64 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useRouter } from "next/navigation"; | ||
import type { FC } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { z } from "zod"; | ||
|
||
const formSchema = z.object({ | ||
username: z.string().min(1, "ユーザー名は必須です。"), | ||
}); | ||
|
||
export const ProfileForm: FC = () => { | ||
const { push } = useRouter(); | ||
|
||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
username: "", | ||
}, | ||
mode: "onBlur", | ||
}); | ||
|
||
function onSubmit(values: z.infer<typeof formSchema>) { | ||
push(`/recap/${values.username}`); | ||
} | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="space-y-4 w-full max-w-xs mx-auto pt-4" | ||
> | ||
<FormField | ||
control={form.control} | ||
name="username" | ||
render={({ field }) => ( | ||
<FormItem className="text-left text-lg"> | ||
<FormControl className="h-12"> | ||
<Input | ||
placeholder="ユーザー名を入力してください。" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button className="mx-auto w-full max-w-xs py-6 text-md"> | ||
振り返りを見る | ||
</Button> | ||
</form> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Separator } from "@/components/ui/separator"; | ||
import Link from "next/link"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export default function ErrorPage() { | ||
return ( | ||
<div className="flex h-full flex-col items-center justify-center bg-background text-foreground"> | ||
<div className="space-y-4 text-center"> | ||
<p className="text-lg">ユーザーの情報を取得できませんでした。</p> | ||
<Separator className="mx-auto w-40" /> | ||
<Button asChild size="lg"> | ||
<Link href="/">ホームに戻る</Link> | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
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,25 @@ | ||
import { auth } from "@/lib/auth"; | ||
import { OverView } from "../components/overview"; | ||
import { fetchGitHubStats } from "../fetchGitHubStats"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: Promise<{ user: string }>; | ||
}) { | ||
const { user } = await params; | ||
const session = await auth(); | ||
// ログインしてない場合は環境変数からトークンを取得 | ||
if (!process.env.GITHUB_TOKEN) { | ||
throw new Error("GITHUB_TOKEN is not defined"); | ||
} | ||
const token = session?.accessToken ?? process.env.GITHUB_TOKEN; | ||
const data = await fetchGitHubStats({ | ||
token, | ||
login: user, | ||
}); | ||
|
||
return <OverView user={user} data={data} />; | ||
} |
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,11 @@ | ||
"use server"; | ||
|
||
import { signIn, signOut } from "@/lib/auth"; | ||
|
||
export async function handleSignIn(provider?: string) { | ||
await signIn(provider); | ||
} | ||
|
||
export async function handleSignOut(provider?: string) { | ||
await signOut({ redirectTo: "/" }); | ||
} |
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,23 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import type { ComponentPropsWithRef, FC } from "react"; | ||
import { handleSignIn, handleSignOut } from "./action"; | ||
|
||
type Props = { provider?: string } & ComponentPropsWithRef<typeof Button>; | ||
|
||
export const SignIn: FC<Props> = ({ provider, ...props }) => { | ||
return ( | ||
<form action={() => handleSignIn(provider)}> | ||
<Button {...props}>サインイン</Button> | ||
</form> | ||
); | ||
}; | ||
|
||
export const SignOut: FC<Props> = ({ provider, ...props }) => { | ||
return ( | ||
<form className="w-full" action={() => handleSignOut(provider)}> | ||
<Button variant="ghost" className="w-full p-0" {...props}> | ||
ログアウト | ||
</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
Oops, something went wrong.