ultisuite-client/lib/api/hooks/use-message-attachments.ts
R3D347HR4Y 8a02c10ba3 Add environment configuration and update email view components
- Created a .cursorignore file to manage local environment files.
- Updated .env.example to reflect changes in the public app URL.
- Modified the gmail workspace configuration to include the drive-suite path.
- Enhanced email view components to support attachment handling and fallback for plain text bodies.
- Improved user experience by updating attachment display logic and integrating inline attachment support.
2026-06-04 00:12:43 +02:00

37 lines
1004 B
TypeScript

"use client"
import { useQuery } from "@tanstack/react-query"
import { apiClient } from "../client"
import { useAuthReady } from "../use-auth-ready"
import {
mapApiAttachmentsToEmail,
type ApiMessageAttachment,
} from "../map-message-attachments"
import type { EmailAttachment } from "@/lib/email-data"
type AttachmentsResponse = {
attachments?: ApiMessageAttachment[]
}
export function fetchMessageAttachments(
messageId: string
): Promise<EmailAttachment[]> {
return apiClient
.get<AttachmentsResponse>(`/mail/messages/${messageId}/attachments`)
.then((res) => mapApiAttachmentsToEmail(res.attachments))
}
export function useMessageAttachments(
messageId: string | undefined,
enabled = true
) {
const { ready, authenticated } = useAuthReady()
return useQuery({
queryKey: ["message-attachments", messageId],
queryFn: () => fetchMessageAttachments(messageId!),
enabled: ready && authenticated && enabled && Boolean(messageId),
staleTime: 5 * 60_000,
})
}