Skip to content

Commit 9be2931

Browse files
committed
[TaskNode] Popconfirm
1 parent f258ad5 commit 9be2931

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@
3232
"test/**/__snapshots__": true,
3333
"yarn.lock": true,
3434
"*.{css,sass,scss}.d.ts": true
35-
}
35+
},
36+
37+
"cSpell.words": ["Popconfirm"]
3638
}

src/helpers/StopPropagation.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
export const stopPropagation = (e: React.SyntheticEvent | undefined) => {
4+
e?.stopPropagation();
5+
};
6+
7+
export const stopPropagationAndRun = (fn: () => void) => {
8+
return (e: React.SyntheticEvent | undefined) => {
9+
e?.stopPropagation();
10+
fn();
11+
};
12+
};

src/screens/projects/components/TaskNode/TaskNode.tsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React, { SyntheticEvent, useCallback, useMemo } from 'react';
1+
import React, { useMemo } from 'react';
22
import {
33
CaretRightFilled,
44
DeleteOutlined,
55
EnterOutlined,
66
PauseOutlined,
7+
QuestionCircleOutlined,
78
} from '@ant-design/icons';
9+
import { Popconfirm } from 'antd';
810
import { observer } from 'mobx-react';
911
import { createUseStyles } from 'react-jss';
1012

@@ -14,13 +16,19 @@ import * as TaskHooks from '../../../../hooks/TaskHooks';
1416
import { Features } from '../../../../config';
1517
import { last } from '../../../../helpers/ArrayHelper';
1618
import { taskLastActiveDateFormat } from '../../../../helpers/DateTime';
19+
import {
20+
stopPropagation,
21+
stopPropagationAndRun,
22+
} from '../../../../helpers/StopPropagation';
1723

1824
const { tasksStore } = rootStore;
1925

2026
interface TaskNodeProps {
2127
task: TaskModel;
2228
}
2329

30+
const QUESTION = <QuestionCircleOutlined style={{ color: 'red' }} />;
31+
2432
export 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

Comments
 (0)