FileItemActions.tsx
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { useState, Fragment } from "react";
import { Popconfirm, Popover, Button, message } from "antd";
import { FileItem } from "./useFileList";
import styles from "./FileItemActions.module.scss";
import { FileListPopover } from "./FileListPopover";
import { FileRenamePopover } from "./FileRenamePopover";
export type FileItemActionsProps = {
item: FileItem;
onRename: (id: number, name: string) => void;
onMove: (id: number, to: number) => void;
onCopy: (id: number, to: number) => void;
onDelete: (id: number) => void;
};
export function FileItemActions({
item,
onRename,
onMove,
onCopy,
onDelete,
}: FileItemActionsProps) {
const [rename, setRename] = useState<boolean>(false);
const [move, setMove] = useState<boolean>(false);
const [copy, setCopy] = useState<boolean>(false);
return (
<div className={styles.actions}>
<Popover
title="변경할 이름을 입력하세요"
content={
<FileRenamePopover
name={item.name}
onRename={(name: string) => {
if (name === item.name) {
return message.error("동일한 이름으로는 변경할 수 없습니다");
}
if (!name) {
return message.error("변경할 이름을 입력하세요");
}
onRename(item.id, name);
setRename(false);
}}
onCancel={() => setRename(false)}
/>
}
trigger="click"
visible={rename}
onVisibleChange={setRename}
>
<Button type="link" size="small">
이름 변경
</Button>
</Popover>
{!item.is_folder && (
<Button type="link" size="small">
공유
</Button>
)}
<Popover
title="이동할 폴더를 선택하세요"
content={
<FileListPopover
root={item.parent}
onSelect={(to: number) => {
if (to === item.parent) {
return message.error("같은 폴더로는 이동할 수 없습니다");
}
onMove(item.id, to);
setMove(false);
}}
onCancel={() => setMove(false)}
/>
}
trigger="click"
visible={move}
onVisibleChange={setMove}
>
<Button type="link" size="small">
이동
</Button>
</Popover>
{!item.is_folder && (
<Popover
title="복사할 폴더를 선택하세요"
content={
<FileListPopover
root={item.parent}
onSelect={(to: number) => {
onCopy(item.id, to);
setCopy(false);
}}
onCancel={() => setCopy(false)}
/>
}
trigger="click"
visible={copy}
onVisibleChange={setCopy}
>
<Button type="link" size="small">
복사
</Button>
</Popover>
)}
{!item.is_folder && (
<Popconfirm
title="정말로 삭제하시겠습니까?"
onConfirm={() => onDelete(item.id)}
okText="삭제"
cancelText="취소"
>
<Button type="link" size="small">
삭제
</Button>
</Popconfirm>
)}
</div>
);
}