2025-09-21 11:02:31 -07:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import type { Attachment } from "@/lib/types";
|
2026-03-20 09:37:02 +00:00
|
|
|
import { Spinner } from "../ui/spinner";
|
2025-09-21 11:02:31 -07:00
|
|
|
import { CrossSmallIcon } from "./icons";
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
export const PreviewAttachment = ({
|
|
|
|
|
attachment,
|
|
|
|
|
isUploading = false,
|
2025-08-28 14:15:36 +01:00
|
|
|
onRemove,
|
2024-10-11 18:00:22 +05:30
|
|
|
}: {
|
|
|
|
|
attachment: Attachment;
|
|
|
|
|
isUploading?: boolean;
|
2025-08-28 14:15:36 +01:00
|
|
|
onRemove?: () => void;
|
2024-10-11 18:00:22 +05:30
|
|
|
}) => {
|
|
|
|
|
const { name, url, contentType } = attachment;
|
|
|
|
|
|
|
|
|
|
return (
|
2025-09-10 16:59:48 +01:00
|
|
|
<div
|
2026-03-20 09:37:02 +00:00
|
|
|
className="group relative h-24 w-24 shrink-0 overflow-hidden rounded-xl border border-border/40 bg-muted"
|
2025-09-21 11:02:31 -07:00
|
|
|
data-testid="input-attachment-preview"
|
2025-09-10 16:59:48 +01:00
|
|
|
>
|
2025-09-21 11:02:31 -07:00
|
|
|
{contentType?.startsWith("image") ? (
|
2025-09-08 21:02:06 +01:00
|
|
|
<Image
|
2026-03-20 09:37:02 +00:00
|
|
|
alt={name ?? "attachment"}
|
2025-09-21 12:03:29 +01:00
|
|
|
className="size-full object-cover"
|
2026-03-20 09:37:02 +00:00
|
|
|
height={96}
|
2025-09-21 11:02:31 -07:00
|
|
|
src={url}
|
2026-03-20 09:37:02 +00:00
|
|
|
width={96}
|
2025-08-28 14:15:36 +01:00
|
|
|
/>
|
|
|
|
|
) : (
|
2025-09-10 16:59:48 +01:00
|
|
|
<div className="flex size-full items-center justify-center text-muted-foreground text-xs">
|
2025-08-28 14:15:36 +01:00
|
|
|
File
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2025-08-28 14:15:36 +01:00
|
|
|
{isUploading && (
|
2025-10-31 20:06:16 -04:00
|
|
|
<div
|
2026-03-20 09:37:02 +00:00
|
|
|
className="absolute inset-0 flex items-center justify-center rounded-xl bg-black/40 backdrop-blur-sm"
|
2025-11-29 13:02:24 +00:00
|
|
|
data-testid="input-attachment-loader"
|
|
|
|
|
>
|
2026-03-20 09:37:02 +00:00
|
|
|
<Spinner className="size-5" />
|
2025-08-28 14:15:36 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{onRemove && !isUploading && (
|
2026-03-20 09:37:02 +00:00
|
|
|
<button
|
|
|
|
|
className="absolute top-1.5 right-1.5 flex size-5 items-center justify-center rounded-full bg-black/60 text-white opacity-0 backdrop-blur-sm transition-opacity hover:bg-black/80 group-hover:opacity-100"
|
2025-08-28 14:15:36 +01:00
|
|
|
onClick={onRemove}
|
2026-03-20 09:37:02 +00:00
|
|
|
type="button"
|
2025-08-28 14:15:36 +01:00
|
|
|
>
|
2026-03-20 09:37:02 +00:00
|
|
|
<CrossSmallIcon size={10} />
|
|
|
|
|
</button>
|
2025-08-28 14:15:36 +01:00
|
|
|
)}
|
2024-10-24 16:35:51 -04:00
|
|
|
</div>
|
2024-10-11 18:00:22 +05:30
|
|
|
);
|
|
|
|
|
};
|