Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

エントリー機能の便利機能 #49

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/(authenticated)/sports/[id]/games/[gameId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {teamTagFactory} from "@/src/models/TeamTagModel";
import {teamFactory} from "@/src/models/TeamModel";
import {GameEntryList} from "@/components/league/legacy/GameEntryList";
import AddGameEntryDialog from "@/components/league/legacy/AddGameEntryDialog";
import AddGameEntryAutomation from "@/components/league/legacy/AddGameEntryAutomation";

export default async function GamePage({params}: { params: { gameId: string, id: string } }) {
const gameId = parseInt(params.gameId, 10)
Expand All @@ -24,7 +25,10 @@ export default async function GamePage({params}: { params: { gameId: string, id:
const teamTags = await teamTagFactory().index()
const linkedTeamTag = teamTags.find((teamTag) => teamTag.sportId === sport.id)
const teams = await teamFactory().index()
const filteredTeams = linkedTeamTag ? teams.filter((team) => team.teamTagId === linkedTeamTag.id) : []
const filteredTeams = linkedTeamTag ? teams
.filter((team) => team.teamTagId === linkedTeamTag.id)
.filter((team) => team.enteredGameIds.length === 0)
: []


return (
Expand All @@ -50,7 +54,9 @@ export default async function GamePage({params}: { params: { gameId: string, id:
/>
</CardBackground>
<CardBackground title={`${game.name}のエントリー`}>
<Stack>
<Stack
spacing={2}
>
<GameEntryList
game={game}
entries={gameEntryTeams}
Expand All @@ -60,6 +66,11 @@ export default async function GamePage({params}: { params: { gameId: string, id:
teams={filteredTeams}
entries={gameEntryTeams}
/>
<AddGameEntryAutomation
game={game}
teams={filteredTeams}
entries={gameEntryTeams}
/>
</Stack>
</CardBackground>
<CardBackground title={`${game.name}のリーグ表`} button={"試合を再生成"}
Expand Down
113 changes: 113 additions & 0 deletions components/league/legacy/AddGameEntryAutomation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use client'
import {Game, gameFactory} from "@/src/models/GameModel";
import {Team} from "@/src/models/TeamModel";
import {useRouter} from "next/navigation";
import React, {useRef, useState} from "react";
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle, Stack,
TextField,
TextFieldProps,
Typography
} from "@mui/material";

export type AddGameEntryAutomationProps = {
game: Game
teams: Team[]
entries: Team[]
}

export default function AddGameEntryAutomation(props: AddGameEntryAutomationProps) {
const router = useRouter()
const [isOpen, setIsOpen] = useState<boolean>(false)

const dataRef = useRef<TextFieldProps>(null)

const handleSubmit = async () => {
if (!dataRef.current) {
alert("エラーが発生しました")
return
}

// get data
const data = dataRef.current.value as string
const splitData = data.split("\t")

console.log(splitData)

// find teams
const selectedTeams = props.teams.filter((team) => splitData.includes(team.name))

if (selectedTeams.length === 0
) {
alert("チームを選択してください")
return
}

// add team user
await gameFactory().addGameEntries(props.game.id, selectedTeams.map((team) => team.id))

// refresh
router.refresh()
// close
setIsOpen(false)
}

return (
<>
<Button
variant={"contained"}
onClick={() => setIsOpen(true)}
>
エントリー追加(コピペ)
</Button>

<Dialog
open={isOpen}
onClose={() => setIsOpen(false)}
maxWidth={"md"}
fullWidth
>
<DialogTitle>
<Typography>
エントリーの追加
</Typography>
</DialogTitle>
<DialogContent>
<Stack spacing={2}>
<Typography>
データ
</Typography>
<TextField
type={"text"}
name={"data"}
id={"data"}
placeholder={"データ"}
inputRef={dataRef}
fullWidth
required
/>
</Stack>
</DialogContent>
<DialogActions>
<Button
variant={"outlined"}
onClick={() => setIsOpen(false)}
>
キャンセル
</Button>
<Button
type={"submit"}
variant={"contained"}
onClick={handleSubmit}
>
追加
</Button>
</DialogActions>
</Dialog>
</>
)
}
Loading