Compare commits

...

2 Commits

Author SHA1 Message Date
hamid zarghami 13781df281 show attachment in task card and show check list item in task card
deploy to danak / build_and_deploy (push) Has been cancelled
2026-07-25 09:20:48 +03:30
hamid zarghami 086db34c12 preview image 2026-07-25 09:13:54 +03:30
7 changed files with 117 additions and 40 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ const Task: FC<Props> = ({ task, isDragging, onClick }) => {
</div>
{task.users?.length ? (
<div className="mt-2 flex justify-end">
<div className="mt-2 flex justify-end pl-1.5">
<div className="flex items-center -space-x-1.5 rtl:space-x-reverse">
{task.users.map((user) => (
<UserAvatar
@@ -1,7 +1,9 @@
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
import { Document, Link2, More } from "iconsax-react";
import { type FC } from "react";
import { CloseCircle, Document, Link2, More } from "iconsax-react";
import { useEffect, useState, type FC } from "react";
import { createPortal } from "react-dom";
import { timeAgo } from "../../../../../config/func";
import { isImageAttachment } from "./isImageAttachment";
type Props = {
title: string;
@@ -13,15 +15,48 @@ type Props = {
};
const AttachmentItem: FC<Props> = ({ title, createdAt, type, url, onEdit, onDelete }) => {
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
const isImage = type === "file" && isImageAttachment(url);
useEffect(() => {
if (!isPreviewOpen) return;
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") setIsPreviewOpen(false);
};
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [isPreviewOpen]);
return (
<>
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2 flex-1 min-w-0">
{isImage && url ? (
<button
type="button"
onClick={() => setIsPreviewOpen(true)}
className="shrink-0 size-14 rounded-[10px] overflow-hidden bg-white outline-none"
>
<img src={url} alt={title} className="size-full object-cover" />
</button>
) : (
<div className="shrink-0 size-9 bg-white rounded-[10px] flex items-center justify-center">
{type === "file" ? <Document size={20} color="#292D32" /> : <Link2 size={20} color="#292D32" />}
</div>
)}
<div className="min-w-0">
{url ? (
{isImage && url ? (
<button
type="button"
onClick={() => setIsPreviewOpen(true)}
className="text-xs font-bold text-[#0047FF] underline truncate block max-w-full text-right outline-none"
>
{title}
</button>
) : url ? (
<a href={url} target="_blank" rel="noopener noreferrer" className="text-xs font-bold text-[#0047FF] underline truncate block">
{title}
</a>
@@ -48,6 +83,34 @@ const AttachmentItem: FC<Props> = ({ title, createdAt, type, url, onEdit, onDele
</PopoverPanel>
</Popover>
</div>
{isPreviewOpen &&
url &&
createPortal(
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4" role="dialog" aria-modal="true">
<button
type="button"
aria-label="بستن"
className="absolute inset-0 bg-black/70 outline-none"
onClick={() => setIsPreviewOpen(false)}
/>
<div className="relative z-10 max-w-[90vw] max-h-[90vh]">
<button
type="button"
aria-label="بستن"
onClick={() => setIsPreviewOpen(false)}
className="absolute -top-3 -left-3 size-9 rounded-full bg-white flex items-center justify-center shadow outline-none"
>
<CloseCircle size={22} color="#292D32" />
</button>
<img src={url} alt={title} className="max-w-[90vw] max-h-[90vh] rounded-2xl object-contain bg-white" />
</div>
</div>,
document.body,
)}
</>
);
};
@@ -0,0 +1,10 @@
const IMAGE_EXTENSIONS = new Set(["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg", "avif"]);
export const isImageAttachment = (url?: string): boolean => {
if (!url) return false;
const path = url.split("?")[0].split("#")[0];
const extension = path.split(".").pop()?.toLowerCase();
return !!extension && IMAGE_EXTENSIONS.has(extension);
};
@@ -124,6 +124,7 @@ export const useCreateCheckListItem = () => {
mutationFn: (variables: CreateCheckListItemType) => api.createCheckListItem(variables),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({ queryKey: ["task-detail", variables.taskId] });
queryClient.invalidateQueries({ queryKey: ["tasks-by-task-phase"] });
queryClient.invalidateQueries({ queryKey: ["project"] });
},
});
@@ -137,6 +138,7 @@ export const useUpdateCheckListItem = () => {
api.updateCheckListItem(id, params),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({ queryKey: ["task-detail", variables.taskId] });
queryClient.invalidateQueries({ queryKey: ["tasks-by-task-phase"] });
queryClient.invalidateQueries({ queryKey: ["project"] });
},
});
@@ -149,6 +151,7 @@ export const useDeleteCheckListItem = () => {
mutationFn: ({ id }: { id: string; taskId: string }) => api.deleteCheckListItem(id),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({ queryKey: ["task-detail", variables.taskId] });
queryClient.invalidateQueries({ queryKey: ["tasks-by-task-phase"] });
queryClient.invalidateQueries({ queryKey: ["project"] });
},
});
@@ -161,6 +164,7 @@ export const useCreateTaskAttachment = () => {
mutationFn: (variables: CreateTaskAttachmentType) => api.createTaskAttachment(variables),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({ queryKey: ["task-detail", variables.taskId] });
queryClient.invalidateQueries({ queryKey: ["tasks-by-task-phase"] });
queryClient.invalidateQueries({ queryKey: ["project"] });
},
});
@@ -23,9 +23,9 @@ export type TaskItemType = {
endDate?: string | null;
tag?: string;
dateRange?: string;
attachments?: number;
checklistDone?: number;
checklistTotal?: number;
attachmentCount?: number;
checkListItemCount?: number;
completedCheckListItemCount?: number;
ticketId?: string | null;
users?: TaskUserType[];
};
@@ -9,9 +9,9 @@ export const mapTaskItemToTask = (task: TaskItemType, taskPhaseId: string, fallb
tag: task.tag ?? "",
dateRange: task.dateRange ?? "",
color: task.color || null,
attachments: task.attachments ?? 0,
checklistDone: task.checklistDone ?? 0,
checklistTotal: task.checklistTotal ?? 0,
attachments: task.attachmentCount ?? 0,
checklistDone: task.completedCheckListItemCount ?? 0,
checklistTotal: task.checkListItemCount ?? 0,
ticketId: task.ticketId ?? null,
users: task.users ?? [],
});
+3 -3
View File
@@ -115,9 +115,9 @@ const Workspace: FC = () => {
tag: activeTask.tag,
dateRange: activeTask.dateRange,
color: activeTask.color,
attachments: activeTask.attachments,
checklistDone: activeTask.checklistDone,
checklistTotal: activeTask.checklistTotal,
attachmentCount: activeTask.attachments,
completedCheckListItemCount: activeTask.checklistDone,
checkListItemCount: activeTask.checklistTotal,
ticketId: activeTask.ticketId,
users: activeTask.users,
},