Skip to content

Commit

Permalink
Merge pull request #68 from Sports-day/feature/game-snackbar
Browse files Browse the repository at this point in the history
スナックバー追加しましたよ
  • Loading branch information
hakase61912 authored Oct 28, 2024
2 parents 24d831c + 3262653 commit 2897ddf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
87 changes: 54 additions & 33 deletions components/league/legacy/GameForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'
import {Game, gameFactory} from "@/src/models/GameModel";
import {FormEvent, useRef, useState} from "react";
import {Button, Stack, TextFieldProps} from "@mui/material";
import React, {FormEvent, useRef, useState} from "react";
import {Alert, Button, Snackbar, Stack, TextFieldProps} from "@mui/material";
import {Tag} from "@/src/models/TagModel";
import {useRouter} from "next/navigation";
import GameEditFields from "@/components/league/legacy/GameEditFields";
Expand All @@ -22,6 +22,7 @@ export default function GameForm(props: GameFormProps) {
const descriptionRef = useRef<TextFieldProps>(null)
const wightRef = useRef<TextFieldProps>(null)
// state
const [snackOpen, setSnackOpen] = React.useState<boolean>(false)
const [typeState, setTypeState] = useState<string>(props.game?.type ?? '')
const [calculationTypeState, setCalculationTypeState] = useState<string>(props.game?.calculationType ?? '')
const [tag, setTag] = useState<string>(props.game?.tagId?.toString() ?? '')
Expand Down Expand Up @@ -54,7 +55,6 @@ export default function GameForm(props: GameFormProps) {
}



if (props.formType === "create") {
const result = await gameFactory().create({
name: nameRef.current?.value as string,
Expand Down Expand Up @@ -87,40 +87,61 @@ export default function GameForm(props: GameFormProps) {

// refresh list
router.refresh()
setSnackOpen(true)
}

const handleSnackClose = () => {
setSnackOpen(false)
}

return (
<Stack
spacing={1}
direction={"column"}
>
<GameEditFields
nameRef={nameRef}
descriptionRef={descriptionRef}
wightRef={wightRef}
typeState={typeState}
setTypeState={setTypeState}
calculationTypeState={calculationTypeState}
setCalculationTypeState={setCalculationTypeState}
tags={props.tags}
tag={tag}
setTag={setTag}
game={props.game}
/>


<Button
type={"submit"}
variant={"contained"}
onClick={handleSubmit}
<>
<Stack
spacing={1}
direction={"column"}
>
{
props.formType == "create" ?
"作成" :
"編集"
}
</Button>
</Stack>
<GameEditFields
nameRef={nameRef}
descriptionRef={descriptionRef}
wightRef={wightRef}
typeState={typeState}
setTypeState={setTypeState}
calculationTypeState={calculationTypeState}
setCalculationTypeState={setCalculationTypeState}
tags={props.tags}
tag={tag}
setTag={setTag}
game={props.game}
/>


<Button
type={"submit"}
variant={"contained"}
onClick={handleSubmit}
>
{
props.formType == "create" ?
"作成" :
"編集"
}
</Button>
</Stack>
<Snackbar
open={snackOpen}
autoHideDuration={6000}
onClose={handleSnackClose}
anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}
>
<Alert
onClose={handleSnackClose}
severity="success"
variant="filled"
sx={{width: '100%'}}
>
変更が保存されました
</Alert>
</Snackbar>
</>
)
}
4 changes: 2 additions & 2 deletions components/match/matchEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export default function MatchEditor(props: MatchEditorProps) {
variant={"contained"}
color={"info"}
component={NextLink}
href={`/sports/${props.sport.id}/${props.game.id}`}
href={`/sports/${props.sport.id}/games/${props.game.id}`}
sx={{border: "1px solid #5f6dc2", py: 2}}
>
リーグに戻る
Expand Down Expand Up @@ -542,7 +542,7 @@ export default function MatchEditor(props: MatchEditorProps) {
variant={"contained"}
color={"info"}
component={NextLink}
href={`/sports/${props.sport.id}/${props.game.id}`}
href={`/sports/${props.sport.id}/games/${props.game.id}`}
sx={{border: "1px solid #5f6dc2", py: 2}}
>
リーグに戻る
Expand Down

0 comments on commit 2897ddf

Please sign in to comment.