-
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 #136 from h8570rg/fix/match_add
Fix/match add
- Loading branch information
Showing
22 changed files
with
536 additions
and
324 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 was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/(app)/matches/[matchId]/MatchPlayerInputModal/AnonymousPlayerSelect.tsx
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,50 @@ | ||
"use client"; | ||
|
||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import { useFormState } from "react-dom"; | ||
import { Avatar } from "~/components/Avatar"; | ||
import { Button } from "~/components/Button"; | ||
import { Input } from "~/components/Input"; | ||
import { NAME_MAX_LENGTH } from "~/lib/utils/schemas"; | ||
import { addAnonymousPlayer } from "./actions"; | ||
|
||
export function AnonymousPlayerSelect({ matchId }: { matchId: string }) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
|
||
const [{ errors, success }, formAction] = useFormState( | ||
addAnonymousPlayer.bind(null, matchId), | ||
{ | ||
success: false, | ||
}, | ||
); | ||
|
||
// TODO: 見直し。サーバー側でできないか | ||
useEffect(() => { | ||
if (success) { | ||
const params = new URLSearchParams(searchParams); | ||
params.delete("mode"); | ||
router.replace(`${pathname}?${params.toString()}`); | ||
} | ||
}, [pathname, router, searchParams, success]); | ||
|
||
return ( | ||
<form className="pt-1" action={formAction} noValidate> | ||
<div className="flex gap-3"> | ||
<Avatar className="mt-2 shrink-0" /> | ||
<Input | ||
name="name" | ||
type="text" | ||
placeholder="プレイヤー名を入力してください" | ||
maxLength={NAME_MAX_LENGTH} | ||
errorMessage={errors?.name} | ||
/> | ||
</div> | ||
<Button className="mt-4" fullWidth type="submit" color="primary"> | ||
決定 | ||
</Button> | ||
</form> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
app/(app)/matches/[matchId]/MatchPlayerInputModal/ModalController.tsx
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 @@ | ||
"use client"; | ||
|
||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useCallback } from "react"; | ||
import { Modal, ModalContent } from "~/components/Modal"; | ||
|
||
export function ModalController({ children }: { children: React.ReactNode }) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
const mode = searchParams.get("mode"); | ||
const isOpen = mode === "player-add"; | ||
|
||
const handleClose = useCallback(() => { | ||
const params = new URLSearchParams(searchParams); | ||
params.delete("mode"); | ||
router.replace(`${pathname}?${params.toString()}`); | ||
}, [pathname, router, searchParams]); | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={handleClose} hideCloseButton> | ||
<ModalContent>{children}</ModalContent> | ||
</Modal> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
app/(app)/matches/[matchId]/MatchPlayerInputModal/Tabs.tsx
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,29 @@ | ||
"use client"; | ||
|
||
import { Tab, Tabs } from "~/components/Tabs"; | ||
|
||
export function PlayerTypeTabs({ | ||
userTab, | ||
anonymousTab, | ||
}: { | ||
userTab: React.ReactNode; | ||
anonymousTab: React.ReactNode; | ||
}) { | ||
return ( | ||
<Tabs | ||
classNames={{ | ||
panel: "min-h-0", | ||
}} | ||
fullWidth | ||
radius="lg" | ||
aria-label="プレイヤー選択の選択肢" | ||
> | ||
<Tab key="friends" title="ユーザー"> | ||
{userTab} | ||
</Tab> | ||
<Tab key="anonymous" title="一般"> | ||
{anonymousTab} | ||
</Tab> | ||
</Tabs> | ||
); | ||
} |
Oops, something went wrong.