2023-04-06 09:37:11 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// ui
|
|
|
|
import { Tooltip } from "components/ui";
|
|
|
|
import { DeleteAttachmentModal } from "./delete-attachment-modal";
|
|
|
|
// icons
|
|
|
|
import { XMarkIcon } from "@heroicons/react/24/outline";
|
|
|
|
import { ExclamationIcon, getFileIcon } from "components/icons";
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
import projectService from "services/project.service";
|
|
|
|
// fetch-key
|
|
|
|
import { ISSUE_ATTACHMENTS, PROJECT_MEMBERS } from "constants/fetch-keys";
|
|
|
|
// helper
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
|
|
|
import { renderLongDateFormat } from "helpers/date-time.helper";
|
|
|
|
import { convertBytesToSize, getFileExtension, getFileName } from "helpers/attachment.helper";
|
|
|
|
// type
|
|
|
|
import { IIssueAttachment } from "types";
|
|
|
|
|
|
|
|
export const IssueAttachments = () => {
|
|
|
|
const [deleteAttachment, setDeleteAttachment] = useState<IIssueAttachment | null>(null);
|
|
|
|
const [attachmentDeleteModal, setAttachmentDeleteModal] = useState<boolean>(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
|
|
|
|
|
|
const { data: attachments } = useSWR<IIssueAttachment[]>(
|
|
|
|
workspaceSlug && projectId && issueId ? ISSUE_ATTACHMENTS(issueId as string) : null,
|
|
|
|
workspaceSlug && projectId && issueId
|
|
|
|
? () =>
|
2023-05-02 14:30:33 +00:00
|
|
|
issuesService.getIssueAttachment(
|
2023-04-06 09:37:11 +00:00
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
issueId as string
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data: people } = useSWR(
|
|
|
|
workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMembers(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DeleteAttachmentModal
|
|
|
|
isOpen={attachmentDeleteModal}
|
|
|
|
setIsOpen={setAttachmentDeleteModal}
|
|
|
|
data={deleteAttachment}
|
|
|
|
/>
|
|
|
|
{attachments &&
|
|
|
|
attachments.length > 0 &&
|
|
|
|
attachments.map((file) => (
|
|
|
|
<div
|
|
|
|
key={file.id}
|
2023-07-17 10:58:23 +00:00
|
|
|
className="flex h-[60px] items-center justify-between gap-1 rounded-md border-[2px] border-custom-border-200 bg-custom-background-100 px-4 py-2 text-sm"
|
2023-04-06 09:37:11 +00:00
|
|
|
>
|
|
|
|
<Link href={file.asset}>
|
|
|
|
<a target="_blank">
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
<div className="h-7 w-7">{getFileIcon(getFileExtension(file.asset))}</div>
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<div className="flex items-center gap-2">
|
2023-07-14 09:38:07 +00:00
|
|
|
<Tooltip tooltipContent={getFileName(file.attributes.name)}>
|
2023-04-06 09:37:11 +00:00
|
|
|
<span className="text-sm">
|
|
|
|
{truncateText(`${getFileName(file.attributes.name)}`, 10)}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`${
|
|
|
|
people?.find((person) => person.member.id === file.updated_by)?.member
|
|
|
|
.first_name ?? ""
|
|
|
|
} uploaded on ${renderLongDateFormat(file.updated_at)}`}
|
|
|
|
>
|
|
|
|
<span>
|
2023-07-10 07:17:00 +00:00
|
|
|
<ExclamationIcon className="h-3 w-3 fill-current text-custom-text-100" />
|
2023-04-06 09:37:11 +00:00
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
|
2023-05-02 14:30:33 +00:00
|
|
|
<div className="flex items-center gap-3 text-xs text-gray-500">
|
2023-04-06 09:37:11 +00:00
|
|
|
<span>{getFileExtension(file.asset).toUpperCase()}</span>
|
|
|
|
<span>{convertBytesToSize(file.attributes.size)}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setDeleteAttachment(file);
|
|
|
|
setAttachmentDeleteModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-4 w-4 text-gray-500 hover:text-gray-800" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|