import { ReactElement, useMemo, useState } from 'react' import './UploadConflictModal.scss' import '../../styles/global.scss' import { Button } from '../Button/Button' import WarningIcon from 'remixicon-react/ErrorWarningLineIcon' interface Props { filename: string suggestedName: string existingNames: Set isTrashedExisting?: boolean onKeepBoth: (newName: string) => void onReplace: () => void onCancel: () => void } export function UploadConflictModal({ filename, suggestedName, existingNames, isTrashedExisting, onKeepBoth, onReplace, onCancel, }: Props): ReactElement { const [customName, setCustomName] = useState(suggestedName) const isNameValid = useMemo(() => { const n = (customName || '').trim() return n.length > 0 && !existingNames.has(n) }, [customName, existingNames]) return (
File already exists
A file named “{filename}” already exists in this drive.
What would you like to do?
Keep both
Upload the new file as a separate item with a different name.
setCustomName(e.target.value)} className="fm-input" placeholder={suggestedName} /> {!isNameValid && customName.trim().length > 0 && existingNames.has(customName.trim()) && (
That name already exists.
)}
Replace
Replace the existing file by uploading this as a new version of “{filename}”.
{isTrashedExisting && (
Heads up: The existing '{filename}' is currently in Trash.
)}
) }