forked from Saifullah-dev/react-file-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete.action.jsx
More file actions
42 lines (37 loc) · 1.33 KB
/
Delete.action.jsx
File metadata and controls
42 lines (37 loc) · 1.33 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
import React, { useEffect, useState } from "react";
import Button from "../../../components/Button/Button";
import { useSelection } from "../../../contexts/SelectionContext";
import "./Delete.action.scss";
import {injectIntl} from "react-intl";
const DeleteAction = ({ triggerAction, onDelete, intl }) => {
const [deleteMsg, setDeleteMsg] = useState("");
const { selectedFiles, setSelectedFiles } = useSelection();
useEffect(() => {
setDeleteMsg(() => {
if (selectedFiles.length === 1) {
return `Are you sure you want to delete "${selectedFiles[0].name}"?`;
} else if (selectedFiles.length > 1) {
return `Are you sure you want to delete these ${selectedFiles.length} items?`;
}
});
}, []);
const handleDeleting = () => {
onDelete(selectedFiles);
setSelectedFiles([]);
triggerAction.close();
};
return (
<div className="file-delete-confirm">
<p className="file-delete-confirm-text">{deleteMsg}</p>
<div className="file-delete-confirm-actions">
<Button type="secondary" onClick={() => triggerAction.close()}>
{intl.formatMessage({id: `cancel`})}
</Button>
<Button type="danger" onClick={handleDeleting}>
{intl.formatMessage({id: `delete`})}
</Button>
</div>
</div>
);
};
export default injectIntl(DeleteAction);