-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DeleteItem): Add deletion of goals, microgoals, and tasks (#18)
- Refactor: Merge all deletion logic inside the hook are all merged into single function `deleteItem` - Feat: Add new component to enable delete goals, microgoals, and tasks by just single click on the delete icon (with mistake handling). - Feat: Add new common components `ConfirmationDialog`. --------- Co-authored-by: ZL Asica <[email protected]>
- Loading branch information
1 parent
f5f8525
commit 4e31a55
Showing
8 changed files
with
144 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import ConfirmationDialog from '@components/common/ConfirmationDialog'; | ||
import useGoalsUpdater from '@hooks/useGoalsUpdater'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import { IconButton, Tooltip } from '@mui/material'; | ||
import { useState } from 'react'; | ||
|
||
const DeleteItem = ({ goalIndex, microGoalIndex, taskIndex }) => { | ||
const { deleteItem } = useGoalsUpdater(); | ||
const [isDialogOpen, setIsDialogOpen] = useState(false); | ||
|
||
const handleDelete = async () => { | ||
await deleteItem({ goalIndex, microGoalIndex, taskIndex }); | ||
setIsDialogOpen(false); // Close the dialog after deletion | ||
}; | ||
|
||
return ( | ||
<> | ||
<Tooltip title="Delete"> | ||
<IconButton | ||
edge="end" | ||
aria-label="delete" | ||
onClick={() => setIsDialogOpen(true)} | ||
sx={{ color: 'error.main' }} // Set color to indicate delete action | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
|
||
{/* Delete Confirmation Dialog */} | ||
<ConfirmationDialog | ||
open={isDialogOpen} | ||
onClose={() => setIsDialogOpen(false)} | ||
onConfirm={handleDelete} | ||
title="Confirm Delete" | ||
description="Are you sure you want to delete this item?" | ||
confirmText="Delete" | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
import DeleteItem from '@components/Home/DeleteItem'; | ||
import { Checkbox, ListItem, ListItemText } from '@mui/material'; | ||
|
||
const Task = ({ task, onToggle }) => ( | ||
<ListItem | ||
dense | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
padding: 1, | ||
bgcolor: task.completed ? 'action.hover' : 'background.paper', | ||
borderRadius: 1, | ||
mb: 1, | ||
'&:hover': { bgcolor: 'action.hover' }, | ||
}} | ||
> | ||
<Checkbox | ||
edge="start" | ||
checked={task.completed} | ||
onChange={onToggle} | ||
size="medium" | ||
sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }} // Enlarge the checkbox icon | ||
/> | ||
<ListItemText | ||
primary={task.name} | ||
primaryTypographyProps={{ | ||
sx: { | ||
textDecoration: task.completed ? 'line-through' : 'none', | ||
color: task.completed ? 'text.disabled' : 'text.primary', | ||
}, | ||
const Task = ({ task, onToggle, macroGoalIndex, microGoalIndex, taskIndex }) => { | ||
return ( | ||
<ListItem | ||
dense | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
padding: 1, | ||
bgcolor: task.completed ? 'action.hover' : 'background.paper', | ||
borderRadius: 1, | ||
mb: 1, | ||
'&:hover': { bgcolor: 'action.hover' }, | ||
}} | ||
/> | ||
</ListItem> | ||
); | ||
> | ||
<Checkbox | ||
edge="start" | ||
checked={task.completed} | ||
onChange={onToggle} | ||
size="medium" | ||
sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }} // Enlarge the checkbox icon | ||
/> | ||
<ListItemText | ||
primary={task.name} | ||
primaryTypographyProps={{ | ||
sx: { | ||
textDecoration: task.completed ? 'line-through' : 'none', | ||
color: task.completed ? 'text.disabled' : 'text.primary', | ||
}, | ||
}} | ||
/> | ||
<DeleteItem | ||
goalIndex={macroGoalIndex} | ||
microGoalIndex={microGoalIndex} | ||
taskIndex={taskIndex} | ||
/> | ||
</ListItem> | ||
); | ||
}; | ||
|
||
export default Task; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
} from '@mui/material'; | ||
|
||
const ConfirmationDialog = ({ | ||
open, | ||
onClose, | ||
onConfirm, | ||
title, | ||
description = '', // If null, no description will be shown | ||
confirmText = 'Confirm', | ||
cancelText = 'Cancel', | ||
confirmColor = 'error', // 'primary' or 'error' | ||
}) => { | ||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={onClose} | ||
aria-describedby={description ? 'confirmation-dialog-description' : undefined} | ||
role="alertdialog" | ||
> | ||
<DialogTitle id="confirmation-dialog-title">{title}</DialogTitle> | ||
<DialogContent> | ||
{description && ( | ||
<DialogContentText id="confirmation-dialog-description">{description}</DialogContentText> | ||
)} | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose}>{cancelText}</Button> | ||
<Button onClick={onConfirm} color={confirmColor} autoFocus> | ||
{confirmText} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default ConfirmationDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters