import { FileTreeEntity } from '../../../../../../types/file-tree-entity' import { useTranslation } from 'react-i18next' import { useProjectContext } from '@/shared/context/project-context' import { useCallback } from 'react' import { syncDelete } from '@/features/file-tree/util/sync-mutation' import { Button } from 'react-bootstrap' import { TFunction } from 'i18next' export type Conflict = { entity: FileTreeEntity type: 'file' | 'folder' } const getConflictText = (conflicts: Conflict[], t: TFunction) => { const hasFolderConflict = conflicts.some( conflict => conflict.type === 'folder' ) const hasFileConflict = conflicts.some(conflict => conflict.type === 'file') if (hasFolderConflict && hasFileConflict) { return t('the_following_files_and_folders_already_exist_in_this_project') } if (hasFolderConflict) { return t('the_following_folder_already_exists_in_this_project', { count: conflicts.length, }) } return t('the_following_files_already_exist_in_this_project') } export function FileUploadConflicts({ cancel, conflicts, handleOverwrite, }: { cancel: () => void conflicts: Conflict[] handleOverwrite: () => void }) { const { t } = useTranslation() // Don't allow overwriting folders with files const hasFolderConflict = conflicts.some( conflict => conflict.type === 'folder' ) return (
{getConflictText(conflicts, t)}
{t('do_you_want_to_overwrite_them')}
)}{!hasFolderConflict && ( )}
{getConflictText(conflicts, t)}
{t('overwriting_the_original_folder')}
{t('do_you_want_to_overwrite_it', {
count: conflicts.length,
})}
{!hasFileConflict && ( )}