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: {
|
|
|
|
file_id: file.id,
|
|
|
|
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 ? "taskFile ImgOpened" : "taskFile"}
|
|
|
|
key={file.id}
|
|
|
|
onClick={() => {
|
|
|
|
if (openImg) setOpenImg(!openImg);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="imgFile"
|
|
|
|
src={backendImg(file.file?.url)}
|
|
|
|
alt="img"
|
|
|
|
onClick={() => {
|
|
|
|
if (!openImg) setOpenImg(!openImg);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{!openImg && (
|
|
|
|
<div className="deleteFile" onClick={() => deleteFile(file)}>
|
|
|
|
<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;
|