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' export function UploadConflicts({ cancel, conflicts, folderConflicts, handleOverwrite, setError, }: { cancel: () => void conflicts: FileTreeEntity[] folderConflicts: FileTreeEntity[] handleOverwrite: () => void setError: (error: string) => void }) { const { t } = useTranslation() // ensure that no uploads happen while there are folder conflicts if (folderConflicts.length > 0) { return ( ) } return (
{conflicts.length > 0 && ( <>

{t('the_following_files_already_exist_in_this_project')}

)}

{t('do_you_want_to_overwrite_them')}

 

) } function FolderUploadConflicts({ cancel, handleOverwrite, folderConflicts, setError, }: { cancel: () => void handleOverwrite: () => void folderConflicts: FileTreeEntity[] setError: (error: string) => void }) { const { t } = useTranslation() const { _id: projectId } = useProjectContext() const deleteAndRetry = useCallback(async () => { // TODO: confirm deletion? try { await Promise.all( folderConflicts.map( entity => syncDelete(projectId, 'folder', entity._id) // TODO: might be a file! ) ) handleOverwrite() } catch (error: any) { setError(error.message) } }, [setError, folderConflicts, handleOverwrite, projectId]) return (

{t('the_following_folder_already_exists_in_this_project', { count: folderConflicts.length, })}

{t('overwriting_the_original_folder')}
{t('do_you_want_to_overwrite_it', { count: folderConflicts.length, })}

 

) }