Advertisement
SanderCokart

DeleteDialog.js

Jan 23rd, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Button from '@material-ui/core/Button';
  2. import Dialog from '@material-ui/core/Dialog';
  3. import DialogActions from '@material-ui/core/DialogActions';
  4. import DialogContent from '@material-ui/core/DialogContent';
  5. import DialogTitle from '@material-ui/core/DialogTitle';
  6. import PropTypes from 'prop-types';
  7. import React, {useContext} from 'react';
  8. import {TodoContext} from '../contexts/TodoContext';
  9.  
  10. function DeleteDialog(props) {
  11.     const context = useContext(TodoContext);
  12.  
  13.     const hide = () => {
  14.         props.setDeleteConfirmationIsShown(false);
  15.     };
  16.  
  17.     return (
  18.         <Dialog onClose={hide} fullWidth={true} maxWidth='sm' open={props.open}>
  19.             <DialogTitle>Are you sure you wish to delete this to-do?</DialogTitle>
  20.             <DialogContent>
  21.                 {props.todo.name}
  22.             </DialogContent>
  23.             <DialogActions>
  24.                 <Button onClick={hide}>Cancel</Button>
  25.                 <Button onClick={() => {
  26.                     context.deleteTodo({id: props.todo.id, name: props.todo.name});
  27.                     hide();
  28.                 }}>
  29.                     Delete
  30.                 </Button>
  31.             </DialogActions>
  32.         </Dialog>
  33.     );
  34. }
  35.  
  36. DeleteDialog.propTypes = {
  37.     open: PropTypes.bool.isRequired,
  38.     setDeleteConfirmationIsShown: PropTypes.func.isRequired,
  39.     todo: PropTypes.shape({
  40.         id: PropTypes.number.isRequired,
  41.         name: PropTypes.string.isRequired,
  42.     }),
  43. };
  44. export default DeleteDialog;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement