import React, { useState, useEffect } from 'react'; import { OGDialog, OGDialogTitle, OGDialogPortal, OGDialogOverlay, OGDialogContent, } from '@librechat/client'; import type { SharePointBatchProgress } from '~/data-provider/Files/sharepoint'; import { useSharePointPicker, useLocalize } from '~/hooks'; interface SharePointPickerDialogProps { isOpen: boolean; onOpenChange: (open: boolean) => void; onFilesSelected?: (files: any[]) => void; disabled?: boolean; isDownloading?: boolean; downloadProgress?: SharePointBatchProgress | null; maxSelectionCount?: number; } export default function SharePointPickerDialog({ isOpen, onOpenChange, onFilesSelected, disabled = false, isDownloading = false, downloadProgress = null, maxSelectionCount, }: SharePointPickerDialogProps) { const [containerNode, setContainerNode] = useState(null); const localize = useLocalize(); const { openSharePointPicker, closeSharePointPicker, cleanup } = useSharePointPicker({ containerNode, onFilesSelected, disabled, onClose: () => handleOpenChange(false), maxSelectionCount, }); const handleOpenChange = (open: boolean) => { if (!open) { closeSharePointPicker(); } onOpenChange(open); }; // Use callback ref to trigger SharePoint picker when container is attached const containerCallbackRef = React.useCallback((node: HTMLDivElement | null) => { setContainerNode(node); }, []); useEffect(() => { if (containerNode && isOpen) { openSharePointPicker(); } return () => { if (!isOpen) { cleanup(); } }; // we need to run this effect only when the containerNode or isOpen changes // eslint-disable-next-line react-hooks/exhaustive-deps }, [containerNode, isOpen]); return ( {localize('com_files_sharepoint_picker_title')}
{/* SharePoint iframe will be injected here by the hook */} {isDownloading && (

{localize('com_files_downloading')}

{downloadProgress && (

{localize('com_files_download_progress', { 0: downloadProgress.completed, 1: downloadProgress.total, })}

{downloadProgress.currentFile && (

{downloadProgress.currentFile}

)}

{localize('com_files_download_percent_complete', { 0: Math.round( (downloadProgress.completed / downloadProgress.total) * 100, ), })}

{downloadProgress.failed.length > 0 && (

{localize('com_files_download_failed', { 0: downloadProgress.failed.length, })}

)}
)} {!downloadProgress && (

{localize('com_files_preparing_download')}

)}
)}
); }