Skip to content

Commit

Permalink
Merge pull request #34 from Sports-day/feature/#33-add-team-delete-bu…
Browse files Browse the repository at this point in the history
…tton

teamを削除する機能の実装
  • Loading branch information
Takkun0310 authored May 14, 2024
2 parents 909c064 + fa27b87 commit fabda3c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
71 changes: 71 additions & 0 deletions components/teams/teamDelete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use client'
import {
Button,
Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl
} from "@mui/material";
import React from "react";
import { teamFactory } from "@/src/models/TeamModel";
import { useRouter } from "next/navigation";
import {HiTrash} from "react-icons/hi2";

export type TeamDeleteProps = {
teamId: number;
}

export default function TeamDelete(props: TeamDeleteProps) {
const router = useRouter();
const [open, setOpen] = React.useState(false);

const handleOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

const handleDelete = async () => {
await teamFactory().delete(props.teamId);

router.push('/teams')
router.refresh()

handleClose();
};

return (
<FormControl>
<Button
variant="outlined"
color={"error"}
startIcon={<HiTrash/>}
onClick={handleOpen}
>
このチームを削除
</Button>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title" color='s-darkest.main' fontWeight='bold'>
{"チームを削除しますか?"}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description" color='black'>
この操作は元に戻せません。チームを削除してもよろしいですか?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="primary" autoFocus>
キャンセル
</Button>
<Button onClick={handleDelete} color="error" autoFocus>
削除
</Button>
</DialogActions>
</Dialog>
</FormControl>
);
}
7 changes: 3 additions & 4 deletions components/teams/teamEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField,
Typography
} from "@mui/material";
import {HiCheck, HiTrash} from "react-icons/hi2";
import { HiCheck } from "react-icons/hi2";
import React, {useState} from "react";
import {useRouter} from "next/navigation";
import {Team, teamFactory} from "@/src/models/TeamModel";
import {Class} from "@/src/models/ClassModel";
import {User} from "@/src/models/UserModel";
import TeamDelete from "@/components/teams/teamDelete";

type TeamEditorProps = {
class : Class;
Expand Down Expand Up @@ -142,9 +143,7 @@ export default function TeamEditor(props: TeamEditorProps) {
justifyContent={"space-between"}
alignItems="center"
>
<Button variant="outlined" color={"error"} startIcon={<HiTrash/>}>
このチームを削除
</Button>
<TeamDelete teamId={props.team.id}/>
<Button
variant={"contained"}
color={"info"}
Expand Down

0 comments on commit fabda3c

Please sign in to comment.