import { useCallback, useState } from 'preact/hooks' import { Analytics } from '../../Analytics.js' import { useLocale } from '../../contexts/index.js' import { useModal } from '../../contexts/Modal.jsx' import { Btn } from '../Btn.js' import { TextInput } from '../forms/index.js' import { Modal } from '../Modal.js' interface Props { oldId: string, onRename: (newId: string) => void, } export function FileRenaming({ oldId, onRename }: Props) { const { locale } = useLocale() const { hideModal } = useModal() const [fileId, setFileId] = useState(oldId) const [error, setError] = useState() const changeFileId = useCallback((str: string) => { setError(undefined) setFileId(str) }, []) const doRename = useCallback(() => { if (!fileId.match(/^([a-z0-9_.-]+:)?[a-z0-9/_.-]+$/)) { setError('Invalid resource location') return } Analytics.renameProjectFile('menu') onRename(fileId) hideModal() }, [fileId, hideModal]) return

{locale('project.rename_file')}

{error !== undefined && {error}}
}