guild_front/src/components/FileTracker/FileTracker.jsx

51 lines
1.1 KiB
React
Raw Normal View History

2023-08-31 01:58:48 +03:00
import React, { useState } from "react";
2023-08-31 01:58:35 +03:00
import { backendImg } from "@utils/helper";
2023-08-31 01:58:48 +03:00
import { apiRequest } from "@api/request";
import close from "assets/icons/closeProjectPersons.svg";
2023-08-31 01:58:35 +03:00
const FileTracker = ({ file, setDeletedTask, taskId }) => {
2023-08-31 01:58:48 +03:00
const [openImg, setOpenImg] = useState(false);
function deleteFile(file) {
apiRequest("/file/detach", {
method: "DELETE",
data: {
2024-02-01 23:46:58 +03:00
file_id: file.file_id,
2023-08-31 01:58:48 +03:00
entity_type: 2,
entity_id: taskId,
2023-12-19 17:36:30 +03:00
status: 0
}
2023-08-31 01:58:48 +03:00
}).then(() => {
setDeletedTask(file);
});
}
2023-08-31 01:58:35 +03:00
2023-08-31 01:58:48 +03:00
return (
<div
className={openImg ? "task-file img-opened" : "task-file"}
2023-08-31 01:58:48 +03:00
key={file.id}
onClick={() => {
if (openImg) setOpenImg(!openImg);
}}
>
<img
className="img-file"
2023-08-31 01:58:48 +03:00
src={backendImg(file.file?.url)}
alt="img"
onClick={() => {
if (!openImg) setOpenImg(!openImg);
}}
/>
{!openImg && (
<div className="delete-file" onClick={() => deleteFile(file)}>
2023-08-31 01:58:48 +03:00
<img src={close} alt="delete" />
2023-08-31 01:58:35 +03:00
</div>
2023-08-31 01:58:48 +03:00
)}
</div>
);
2023-08-31 01:58:35 +03:00
};
export default FileTracker;