ultisuite-client/lib/api/hooks/use-mail-drive-save.ts
R3D347HR4Y 6ec95262af Add OnlyOffice integration and update project configurations
- Updated .env.example to include configuration for OnlyOffice Document Server.
- Modified the workspace configuration to remove the drive-suite path.
- Adjusted TypeScript environment imports for consistency.
- Enhanced Next.js configuration to disable canvas in Webpack.
- Updated package.json to include new dependencies for OnlyOffice and PDF.js.
- Added global styles for OnlyOffice theme integration in the CSS.
- Created new layout and page components for the Drive feature, including public sharing and editing functionalities.
- Updated metadata handling across various layouts to reflect the new app structure.
2026-06-07 15:49:21 +02:00

67 lines
2.1 KiB
TypeScript

"use client"
import { useMutation, useQueryClient, type QueryClient } from "@tanstack/react-query"
import { apiClient } from "../client"
import type { ApiMessageAttachment } from "../map-message-attachments"
import {
MAIL_DRIVE_DEFAULT_FOLDER,
normalizeMailDriveFolder,
} from "@/lib/mail/mail-drive"
type SaveToDriveResponse = {
drive_path: string
}
type SaveAllToDriveResponse = {
attachments?: ApiMessageAttachment[]
}
export function useSaveAttachmentToDrive(messageId: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({
attachmentId,
folderPath = MAIL_DRIVE_DEFAULT_FOLDER,
}: {
attachmentId: string
folderPath?: string
}) => {
const res = await apiClient.post<SaveToDriveResponse>(
`/mail/messages/${messageId}/attachments/${attachmentId}/save-to-drive`,
{ folder_path: folderPath }
)
return res.drive_path
},
onSuccess: (_drivePath, variables) => {
queryClient.invalidateQueries({ queryKey: ["message-attachments", messageId] })
invalidateDriveAfterMailSave(queryClient, variables.folderPath)
},
})
}
export function useSaveMessageAttachmentsToDrive(messageId: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (folderPath: string = MAIL_DRIVE_DEFAULT_FOLDER) => {
const res = await apiClient.post<SaveAllToDriveResponse>(
`/mail/messages/${messageId}/attachments/save-to-drive`,
{ folder_path: folderPath }
)
return res.attachments ?? []
},
onSuccess: (_attachments, folderPath) => {
queryClient.invalidateQueries({ queryKey: ["message-attachments", messageId] })
invalidateDriveAfterMailSave(queryClient, folderPath)
},
})
}
function invalidateDriveAfterMailSave(queryClient: QueryClient, folderPath?: string) {
queryClient.invalidateQueries({ queryKey: ["drive"] })
const folder = normalizeMailDriveFolder(folderPath ?? MAIL_DRIVE_DEFAULT_FOLDER)
queryClient.invalidateQueries({ queryKey: ["drive", "files", folder] })
queryClient.invalidateQueries({ queryKey: ["drive", "recent"] })
}