StudentDelete.js 2.04 KB
import React from 'react';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import { createMuiTheme } from '@material-ui/core/styles';
import {blue, pink} from '@material-ui/core/colors';

const theme = createMuiTheme({
  palette: {
    primary: {
      main: blue[100],
    },
    secondary: {
      main: pink[100],
    },
  },
});

class StudentDelete extends React.Component{

    constructor(props){
        super(props);
        this.state = {
            open: false
        }
    }

    handleClickOpen = () => {
        this.setState({
            open:true
        });
    }

    handleClose = () => {
        this.setState({
            open: false
        })
    }

    deleteStudent(st_Code){
        const url='/api/students/'+st_Code;
        fetch(url,{
            method:'DELETE'
        });
        this.props.stateRefresh();
    }
    
    render(){

        return(
            <div>
            <Button variant="contained" color="secondary" onClick={this.handleClickOpen}>삭제</Button>
            <Dialog open={this.state.open} onClose={this.handleClose}>
                <DialogTitle onClose={this.handleClose}>
                    삭제 경고
                </DialogTitle>
                <DialogContent>
                    <Typography gutterBottom>
                        선택한 학생의 정보가 삭제됩니다!
                    </Typography>
                </DialogContent>
                <DialogActions>
                <Button variant="contained" color="secondary" onClick={(e)=>{this.deleteStudent(this.props.st_Code)}}>삭제</Button>
                <Button variant="outlined" color="secondary" onClick={this.handleClose}>닫기</Button>
                </DialogActions>
            </Dialog>   
            </div>

        )
    }
}

export default StudentDelete;