Files
faunosteo/apps/app/src/components/editor/ModeNotice.tsx
T

66 lines
1.9 KiB
TypeScript

import { Link } from 'react-router-dom'
import Notice from '@/components/ui/Notice'
import { roundLabel } from '@/admin/labels'
import { freezingRound, type EditorMode } from '@/editor/mode'
import { useEditorStore } from '@/editor/state/editorStore'
import { useT } from '@/i18n/useT'
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
type Translate = ReturnType<typeof useT>
/** « Revue n° N · vérification en cours », else the round's status label. */
function frozenText(t: Translate, sheet: OfficialSheetAdmin): string {
const round = freezingRound(sheet)
if (!round) return t('editor.draft.mode.frozen_generic')
const number = t('admin.overview.round').replace(
'{round}',
String(round.round),
)
if (round.status === 'verifying') {
return t('editor.draft.mode.frozen_verifying').replace('{round}', number)
}
return `${number} · ${roundLabel(t, round).title}`
}
function modeText(
t: Translate,
mode: EditorMode,
sheet: OfficialSheetAdmin,
): string {
return mode === 'frozen'
? frozenText(t, sheet)
: t(`editor.draft.mode.${mode}`)
}
/**
* Why the draft is read-only (boards 05): the reason alone, nothing repeated (L15). The
* frozen state links to the overview; a recovery copy that this state cannot use is named.
*/
export default function ModeNotice({
mode,
sheet,
}: {
mode: EditorMode
sheet: OfficialSheetAdmin
}) {
const t = useT()
const unusableCopy = useEditorStore((s) => s.unusableCopy)
if (mode === 'edit') return null
return (
<Notice tone="info">
<p className="font-medium">{modeText(t, mode, sheet)}</p>
{unusableCopy && (
<p className="mt-1">{t('editor.draft.mode.unusable_copy')}</p>
)}
{mode === 'frozen' && (
<Link
to={`/app/admin/sheets/${sheet.sheet_id}`}
className="mt-1 inline-block underline"
>
{t('editor.draft.overview_link')}
</Link>
)}
</Notice>
)
}