From af0007bdb108bea848f9f6d51f40ce1c398e85cc Mon Sep 17 00:00:00 2001 From: h8570rg Date: Sun, 31 Dec 2023 17:39:31 +0900 Subject: [PATCH] fix: register --- app/(app)/matches/MatchCreateButton.tsx | 10 +- .../matches/[matchId]/GameInputModal.tsx | 21 +- app/(auth)/login/layout.tsx | 13 - app/(auth)/login/page.tsx | 9 +- app/(auth)/register/Form.tsx | 63 +++++ app/{(register) => (auth)}/register/page.tsx | 13 +- app/(auth)/sign-up/layout.tsx | 13 - app/(auth)/sign-up/page.tsx | 9 +- app/(register)/layout.tsx | 7 - app/(register)/register/ProfileForm.tsx | 222 ------------------ app/globals.css | 2 +- components/BottomNavigation/index.tsx | 8 +- components/FriendSearchModal/index.tsx | 4 +- components/ProfilesSearch/index.tsx | 4 +- lib/actions/updateProfile.ts | 72 ++++++ lib/utils/schemas.ts | 23 +- tailwind.config.js | 4 + 17 files changed, 205 insertions(+), 292 deletions(-) delete mode 100644 app/(auth)/login/layout.tsx create mode 100644 app/(auth)/register/Form.tsx rename app/{(register) => (auth)}/register/page.tsx (69%) delete mode 100644 app/(auth)/sign-up/layout.tsx delete mode 100644 app/(register)/layout.tsx delete mode 100644 app/(register)/register/ProfileForm.tsx create mode 100644 lib/actions/updateProfile.ts diff --git a/app/(app)/matches/MatchCreateButton.tsx b/app/(app)/matches/MatchCreateButton.tsx index d1385e3..1425883 100644 --- a/app/(app)/matches/MatchCreateButton.tsx +++ b/app/(app)/matches/MatchCreateButton.tsx @@ -228,7 +228,7 @@ export function MatchCreateButton({ className }: { className?: string }) { labelPlacement="outside-left" endContent={
- +
} {...register("chipRate")} @@ -240,7 +240,7 @@ export function MatchCreateButton({ className }: { className?: string }) { hideIndicator classNames={{ titleWrapper: "text-right", - title: "text-sm text-primary", + title: "text-small text-primary", }} >
@@ -254,7 +254,7 @@ export function MatchCreateButton({ className }: { className?: string }) { labelPlacement="outside-left" endContent={
- +
@@ -272,7 +272,7 @@ export function MatchCreateButton({ className }: { className?: string }) { labelPlacement="outside-left" endContent={
- +
@@ -290,7 +290,7 @@ export function MatchCreateButton({ className }: { className?: string }) { labelPlacement="outside-left" endContent={
- + 点返し
diff --git a/app/(app)/matches/[matchId]/GameInputModal.tsx b/app/(app)/matches/[matchId]/GameInputModal.tsx index 70e3a55..5194ece 100644 --- a/app/(app)/matches/[matchId]/GameInputModal.tsx +++ b/app/(app)/matches/[matchId]/GameInputModal.tsx @@ -196,18 +196,21 @@ export function GameInputModal({ endContent={
00 - +
diff --git a/app/(auth)/login/layout.tsx b/app/(auth)/login/layout.tsx deleted file mode 100644 index 965149a..0000000 --- a/app/(auth)/login/layout.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Metadata } from "next"; - -export const metadata: Metadata = { - title: "ログイン", -}; - -export default function LoginLayout({ - children, -}: { - children: React.ReactNode; -}) { - return children; -} diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 24053e6..def609a 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -1,12 +1,17 @@ +import { Metadata } from "next"; import Link from "next/link"; import { Divider } from "~/components/Divider"; import { Form } from "./Form"; import { SocialProviders } from "./SocialProviders"; +export const metadata: Metadata = { + title: "ログイン", +}; + export default function Login() { return ( <> -

ログイン

+

ログイン

@@ -14,7 +19,7 @@ export default function Login() {
-

+

アカウントをお持ちでない方は 新規登録 diff --git a/app/(auth)/register/Form.tsx b/app/(auth)/register/Form.tsx new file mode 100644 index 0000000..6d95a21 --- /dev/null +++ b/app/(auth)/register/Form.tsx @@ -0,0 +1,63 @@ +"use client"; + +import classNames from "classnames"; +import { useFormState } from "react-dom"; +import { Button } from "~/components/Button"; +import { Input } from "~/components/Input"; +import { updateProfile } from "~/lib/actions/updateProfile"; +import { + JANRECO_ID_MAX_LENGTH, + JANRECO_ID_MIN_LENGTH, + NAME_MAX_LENGTH, +} from "~/lib/utils/schemas"; + +export function Form({ + className, + userId, +}: { + className?: string; + userId: string; +}) { + const [state, formAction] = useFormState(updateProfile, {}); + + return ( + +

+ ユーザーIDと名前を決めてください。 +
+ ユーザーIDはユーザー検索に使用されます。名前は成績表に表示されます。 +

+
+ + + +
+ +
+
+
+ ); +} diff --git a/app/(register)/register/page.tsx b/app/(auth)/register/page.tsx similarity index 69% rename from app/(register)/register/page.tsx rename to app/(auth)/register/page.tsx index bb589c8..a04307b 100644 --- a/app/(register)/register/page.tsx +++ b/app/(auth)/register/page.tsx @@ -1,9 +1,8 @@ import { Metadata } from "next"; import { redirect } from "next/navigation"; -import Logo from "~/components/Logo"; import { services } from "~/lib/services"; import { createSupabaseServerComponentClient } from "~/lib/utils/supabase/serverComponentClient"; -import ProfileForm from "./ProfileForm"; +import { Form } from "./Form"; export const metadata: Metadata = { title: "ユーザー情報登録", @@ -19,9 +18,11 @@ export default async function Register() { } return ( -
- - -
+ <> +

+ ユーザー情報登録 +

+
+ ); } diff --git a/app/(auth)/sign-up/layout.tsx b/app/(auth)/sign-up/layout.tsx deleted file mode 100644 index c0acf05..0000000 --- a/app/(auth)/sign-up/layout.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Metadata } from "next"; - -export const metadata: Metadata = { - title: "新規登録", -}; - -export default function SignUpLayout({ - children, -}: { - children: React.ReactNode; -}) { - return children; -} diff --git a/app/(auth)/sign-up/page.tsx b/app/(auth)/sign-up/page.tsx index cbcc57e..5f7238a 100644 --- a/app/(auth)/sign-up/page.tsx +++ b/app/(auth)/sign-up/page.tsx @@ -1,12 +1,17 @@ +import { Metadata } from "next"; import Link from "next/link"; import { Form } from "./Form"; +export const metadata: Metadata = { + title: "新規登録", +}; + export default function Login() { return ( <> -

新規登録

+

新規登録

-

+

既にアカウントをお持ちの方は ログイン diff --git a/app/(register)/layout.tsx b/app/(register)/layout.tsx deleted file mode 100644 index c443549..0000000 --- a/app/(register)/layout.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function RegisterLayout({ - children, -}: { - children: React.ReactNode; -}) { - return

{children}
; -} diff --git a/app/(register)/register/ProfileForm.tsx b/app/(register)/register/ProfileForm.tsx deleted file mode 100644 index c493aba..0000000 --- a/app/(register)/register/ProfileForm.tsx +++ /dev/null @@ -1,222 +0,0 @@ -"use client"; - -import { zodResolver } from "@hookform/resolvers/zod"; -import classNames from "classnames"; -import { useRouter } from "next/navigation"; -import { useCallback, useState } from "react"; -import { SubmitHandler, useForm } from "react-hook-form"; -import { z } from "zod"; -import { Button } from "~/components/Button"; -import { Card, CardBody } from "~/components/Card"; -import { Icon } from "~/components/Icon"; -import { Input } from "~/components/Input"; -import { Popover, PopoverContent, PopoverTrigger } from "~/components/Popover"; -import { Progress } from "~/components/Progress"; -import { User } from "~/components/User"; -import { - ProfileUpdateSchema, - profileUpdateSchema, - useProfileUpdate, -} from "~/lib/hooks/api/profile"; -import { useProfileExists } from "~/lib/hooks/api/profiles"; - -const janrecoIdSchema = profileUpdateSchema.pick({ janrecoId: true }); -type JanrecoIdSchema = z.infer; -const nameSchema = profileUpdateSchema.pick({ name: true }); -type NameSchema = z.infer; - -export default function ProfileForm({ - className, - userId, -}: { - className?: string; - userId: string; -}) { - const router = useRouter(); - const [step, setStep] = useState(1); - const progress = (100 / 3) * step; - - const [janrecoId, setJanrecoId] = - useState(); - const [name, setName] = useState(); - - const { trigger: getProfileExists } = useProfileExists(); - - const { trigger: updateProfile, isMutating: isUpdatingProfile } = - useProfileUpdate({ profileId: userId }); - - const janrecoIdForm = useForm({ - resolver: zodResolver(janrecoIdSchema), - mode: "onChange", - }); - - const onJanrecoIdSubmit: SubmitHandler = async (data) => { - const exists = await getProfileExists({ janrecoId: data.janrecoId }); - if (exists) { - janrecoIdForm.setError("janrecoId", { - type: "manual", - message: "このIDは既に使用されています", - }); - return; - } - setJanrecoId(data.janrecoId); - setStep((prev) => prev + 1); - }; - - const nameForm = useForm({ - resolver: zodResolver(nameSchema), - mode: "onChange", - }); - - const onNameSubmit: SubmitHandler = async (data) => { - setName(data.name); - setStep((prev) => prev + 1); - }; - - const handleConfirmClick = useCallback(async () => { - if (!janrecoId || !name) { - return; - } - await updateProfile({ janrecoId, name }); - router.push("/"); - }, [janrecoId, name, router, updateProfile]); - - const handlePrevClick = useCallback(() => { - setStep((prev) => prev - 1); - }, []); - - return ( -
- -
-
- {/* janrecoIdForm */} - {step === 1 && ( - -
-

- ユーザーIDを決めてください -

- - - - - -
- ユーザーIDは、他のユーザーがあなたを検索するために使用されます。あとから変更することも可能です。 -
-
-
-
-
- - @ -
- } - description="半角英数字4~12文字で入力してください" - maxLength={12} - {...janrecoIdForm.register("janrecoId")} - errorMessage={ - janrecoIdForm.formState.errors.janrecoId?.message - } - autoFocus - /> -
- -
-
- - )} - {/* nameForm */} - {step === 2 && ( -
-
-

名前を決めてください

- - - - - -
- 名前は成績表に表示されます。あとから変更することも可能です。 -
-
-
-
-
- -
- - -
-
-
- )} - {/* confirm */} - {step === 3 && !!name && !!janrecoId && ( - <> -
-

- こちらでよろしいですか? -

-

- あとから変更できます -

-
-
- - -
- -
-
-
-
- - -
-
- - )} -
-
-
- ); -} diff --git a/app/globals.css b/app/globals.css index 1ccbecd..4979689 100644 --- a/app/globals.css +++ b/app/globals.css @@ -22,7 +22,7 @@ } .heading-1 { - @apply text-xl font-bold; + @apply text-[20px] font-bold; } } diff --git a/components/BottomNavigation/index.tsx b/components/BottomNavigation/index.tsx index 4742216..a2c4fee 100644 --- a/components/BottomNavigation/index.tsx +++ b/components/BottomNavigation/index.tsx @@ -6,7 +6,7 @@ export function BottomNavigation() {