import { useState } from 'react'; import { useGetImportDirectory, usePostImport } from '../generated/anthoLumeAPIV1'; import type { DirectoryItem, DirectoryListResponse } from '../generated/model'; import { getErrorMessage } from '../utils/errors'; import { Button } from '../components/Button'; import { FolderOpenIcon } from '../icons'; import { useToasts } from '../components/ToastContext'; export default function AdminImportPage() { const [currentPath, setCurrentPath] = useState(''); const [selectedDirectory, setSelectedDirectory] = useState(''); const [importType, setImportType] = useState<'DIRECT' | 'COPY'>('DIRECT'); const { showInfo, showError } = useToasts(); const { data: directoryData, isLoading } = useGetImportDirectory( currentPath ? { directory: currentPath } : {} ); const postImport = usePostImport(); const directoryResponse = directoryData?.status === 200 ? (directoryData.data as DirectoryListResponse) : null; const directories = directoryResponse?.items ?? []; const currentPathDisplay = directoryResponse?.current_path ?? currentPath ?? '/data'; const handleSelectDirectory = (directory: string) => { setSelectedDirectory(`${currentPath}/${directory}`); }; const handleNavigateUp = () => { if (currentPathDisplay !== '/') { const parts = currentPathDisplay.split('/'); parts.pop(); setCurrentPath(parts.join('/') || ''); } }; const handleImport = () => { if (!selectedDirectory) return; postImport.mutate( { data: { directory: selectedDirectory, type: importType, }, }, { onSuccess: _response => { showInfo('Import completed successfully'); setTimeout(() => { window.location.href = '/admin/import-results'; }, 1500); }, onError: error => { showError('Import failed: ' + getErrorMessage(error)); }, } ); }; const handleCancel = () => { setSelectedDirectory(''); }; if (isLoading && !currentPath) { return
Loading...
; } if (selectedDirectory) { return (

Selected Import Directory

{selectedDirectory}

setImportType('DIRECT')} />
setImportType('COPY')} />
); } return (
{currentPath !== '/' && ( )} {directories.length === 0 ? ( ) : ( directories.map((item: DirectoryItem) => ( )) )}
{currentPath}
No Folders
); }