Created delete dialog

This commit is contained in:
Kristoffer Juelsenn 2022-04-22 10:12:42 +02:00
parent af22c56aa4
commit 5431f9496c
1 changed files with 60 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import DeleteIcon from '@mui/icons-material/Delete';
import DateTimePicker from '@mui/lab/DateTimePicker'; import DateTimePicker from '@mui/lab/DateTimePicker';
import AdapterDateFns from '@mui/lab/AdapterDateFns'; import AdapterDateFns from '@mui/lab/AdapterDateFns';
import LocalizationProvider from '@mui/lab/LocalizationProvider'; import LocalizationProvider from '@mui/lab/LocalizationProvider';
import PropTypes from 'prop-types'
let submitChanges = curryTournamentId => event => { let submitChanges = curryTournamentId => event => {
event.preventDefault(); event.preventDefault();
@ -77,6 +78,7 @@ let submitChanges = curryTournamentId => event => {
.catch((error) => showError(error)); .catch((error) => showError(error));
} }
let deleteTournament = tournamentId => event => { let deleteTournament = tournamentId => event => {
console.log(tournamentId);
event.preventDefault(); event.preventDefault();
//TODO: https://mui.com/components/dialogs/ //TODO: https://mui.com/components/dialogs/
@ -172,13 +174,59 @@ function showError(error) {
console.error(error); console.error(error);
} }
function ConfirmationDialogRaw(props) {
const { tournamentId } = useParams();
const { onClose, value: valueProp, open, ...other } = props;
const [value, setValue] = React.useState(valueProp);
const radioGroupRef = React.useRef(null);
React.useEffect(() => {
if (!open) {
setValue(valueProp);
}
}, [valueProp, open]);
const handleCancel = () => {
onClose();
};
return (
<Dialog
sx={{ '& .MuiDialog-paper': { width: '80%', maxHeight: 435 } }}
maxWidth="xs"
open={open}
{...other}
>
<DialogTitle>Yes or No</DialogTitle>
<DialogContent>
Test
</DialogContent>
<DialogActions>
<Button autoFocus onClick={handleCancel}>
Cancel
</Button>
<Button onClick={deleteTournament(tournamentId)}>Ok</Button>
</DialogActions>
</Dialog>
);
}
ConfirmationDialogRaw.propTypes = {
onClose: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired,
value: PropTypes.string.isRequired,
};
export default function TournamentManager(props) { export default function TournamentManager(props) {
const { tournamentId } = useParams(); const { tournamentId } = useParams();
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const handleConfirm = () => { const [value, setValue] = React.useState("");
return true;
const handleClickListItem = () => {
setOpen(true);
}; };
const handleClose = () => { const handleClose = () => {
setOpen(false); setOpen(false);
}; };
@ -191,13 +239,20 @@ export default function TournamentManager(props) {
<ManageTournament tournamentId={tournamentId} /> <ManageTournament tournamentId={tournamentId} />
{/* <AnnounceButton /> */} {/* <AnnounceButton /> */}
<Box sx={{width: "100%"}}> <Box sx={{width: "100%"}}>
<Button variant="contained" color="error" onClick={deleteTournament(tournamentId)} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}> <Button variant="contained" color="error" onClick={handleClickListItem} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}>
Delete Tournament Delete Tournament
</Button> </Button>
<ConfirmationDialogRaw
id="ringtone-menu"
keepMounted
open={open}
onClose={handleClose}
value={value}
/>
</Box> </Box>
</Paper> </Paper>
<Dialog {/* <Dialog
open={open} open={open}
onClose={handleClose} onClose={handleClose}
aria-labelledby="alert-dialog-title" aria-labelledby="alert-dialog-title"
@ -217,7 +272,7 @@ export default function TournamentManager(props) {
Confirm Confirm
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog> */}
</> </>
); );