import { useState } from 'react' import { Link } from 'react-router-dom' import Button from '@/components/ui/Button' import Notice from '@/components/ui/Notice' import { formatParisTime } from '@/editor/format' import { copySheetId } from '@/editor/otherCopies' import { useEditorStore } from '@/editor/state/editorStore' import type { StoredCopyInfo } from '@/editor/state/recovery' import type { Locale } from '@/i18n/types' import { useLocaleStore } from '@/state/localeStore' import { useT } from '@/i18n/useT' import ConfirmDialog from './ConfirmDialog' type Translate = ReturnType /** « · révision R · », each part only when the copy tells it. */ function copyLine(t: Translate, locale: Locale, copy: StoredCopyInfo): string { return [ copy.sheetName ?? t('editor.draft.copy.unreadable'), copy.revision === null ? null : t('editor.draft.copy.revision').replace( '{revision}', String(copy.revision), ), copy.writtenAt === null ? null : formatParisTime(copy.writtenAt, locale), ] .filter(Boolean) .join(' · ') } /** * The write failed (C28: cap of two other copies, or a full storage): the account's other * copies are listed, each openable and abandonable (confirmed); abandoning writes the * current copy again at once. Nothing is evicted by itself. */ export default function CopyIssueNotice() { const t = useT() const locale = useLocaleStore((s) => s.locale) const issue = useEditorStore((s) => s.copyIssue) const copies = useEditorStore((s) => s.otherCopies) const userId = useEditorStore((s) => s.userId) const [asking, setAsking] = useState(null) if (issue === null) return null const abandon = () => { if (asking) useEditorStore .getState() .abandonOtherCopy(asking.versionId, { confirmed: true }) setAsking(null) } return ( <>

{t(`editor.draft.copy_issue.${issue}`)}

    {copies.map((copy) => { const sheetId = userId ? copySheetId(userId, copy.versionId) : null return (
  • {copyLine(t, locale, copy)} {sheetId && ( {t('editor.draft.copy.open')} )}
  • ) })}
{issue === 'quota' && ( )}
setAsking(null)} /> ) }