1- import React , { SyntheticEvent , useCallback , useMemo } from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import {
33 CaretRightFilled ,
44 DeleteOutlined ,
55 EnterOutlined ,
66 PauseOutlined ,
7+ QuestionCircleOutlined ,
78} from '@ant-design/icons' ;
9+ import { Popconfirm } from 'antd' ;
810import { observer } from 'mobx-react' ;
911import { createUseStyles } from 'react-jss' ;
1012
@@ -14,13 +16,19 @@ import * as TaskHooks from '../../../../hooks/TaskHooks';
1416import { Features } from '../../../../config' ;
1517import { last } from '../../../../helpers/ArrayHelper' ;
1618import { taskLastActiveDateFormat } from '../../../../helpers/DateTime' ;
19+ import {
20+ stopPropagation ,
21+ stopPropagationAndRun ,
22+ } from '../../../../helpers/StopPropagation' ;
1723
1824const { tasksStore } = rootStore ;
1925
2026interface TaskNodeProps {
2127 task : TaskModel ;
2228}
2329
30+ const QUESTION = < QuestionCircleOutlined style = { { color : 'red' } } /> ;
31+
2432export default observer ( function TaskNode ( { task } : TaskNodeProps ) {
2533 const classes = useStyle ( ) ;
2634
@@ -39,35 +47,38 @@ export default observer(function TaskNode({ task }: TaskNodeProps) {
3947 [ lastDateInProgress , duration ]
4048 ) ;
4149
42- const preventDefault = useCallback ( ( fn : ( ) => void ) => {
43- return ( e : SyntheticEvent ) => {
44- e . stopPropagation ( ) ;
45- fn ( ) ;
46- } ;
47- } , [ ] ) ;
48-
4950 return (
5051 < div className = { classes . taskNode } >
5152 < span className = { classes . taskTitle } > { task . title } </ span >
5253 < span > { timeData } </ span >
5354 < span className = { classes . taskNodeActions } >
5455 { Features . myDay && (
5556 < EnterOutlined
56- onClick = { preventDefault ( ( ) => tasksStore . addToMyDay ( task ) ) }
57+ onClick = { stopPropagationAndRun ( ( ) => tasksStore . addToMyDay ( task ) ) }
5758 />
5859 ) }
5960 { ! task . active ? (
6061 < CaretRightFilled
61- onClick = { preventDefault ( ( ) => tasksStore . startTimer ( task ) ) }
62+ onClick = { stopPropagationAndRun ( ( ) => tasksStore . startTimer ( task ) ) }
6263 />
6364 ) : (
6465 < PauseOutlined
65- onClick = { preventDefault ( ( ) => tasksStore . stopTimer ( ) ) }
66+ onClick = { stopPropagationAndRun ( ( ) => tasksStore . stopTimer ( ) ) }
6667 />
6768 ) }
68- < DeleteOutlined
69- onClick = { preventDefault ( ( ) => tasksStore . delete ( task ) ) }
70- />
69+ < Popconfirm
70+ title = "Are you sure to delete this task?"
71+ onConfirm = { stopPropagationAndRun ( ( ) => tasksStore . delete ( task ) ) }
72+ onCancel = { stopPropagation }
73+ okText = "Yes"
74+ cancelText = "No"
75+ placement = "topRight"
76+ icon = { QUESTION }
77+ >
78+ < span onClick = { stopPropagation } >
79+ < DeleteOutlined />
80+ </ span >
81+ </ Popconfirm >
7182 </ span >
7283 </ div >
7384 ) ;
0 commit comments