feat: add confirmation prompts for activating contract and GDPR templates

This commit is contained in:
seaznCode 2026-01-14 22:16:17 +01:00
parent 19e6d34b1c
commit 35b0abd005
2 changed files with 21 additions and 0 deletions

View File

@ -160,6 +160,14 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi
return;
}
if (publish && type === 'contract') {
const kind = contractType === 'gdpr' ? 'GDPR' : 'Contract';
const ok = window.confirm(
`Activate this ${kind} template now?\n\nThis will deactivate other active ${kind} templates that apply to the same user type and language.`
);
if (!ok) return;
}
setSaving(true);
setStatusMsg(null);

View File

@ -79,6 +79,19 @@ export default function ContractTemplateList({ refreshKey = 0, onEdit }: Props)
const onToggleState = async (id: string, current: string) => {
const target = current === 'published' ? 'inactive' : 'active';
// Confirmation: activating a contract/GDPR will deactivate other active templates of the same kind
if (target === 'active') {
const tpl = items.find((i) => i.id === id);
if (tpl?.type === 'contract') {
const kind = tpl.contract_type === 'gdpr' ? 'GDPR' : 'Contract';
const ok = window.confirm(
`Activate this ${kind} template now?\n\nThis will deactivate other active ${kind} templates that apply to the same user type and language.`
);
if (!ok) return;
}
}
try {
const updated = await updateTemplateState(id, target as 'active' | 'inactive');
setItems((prev) => prev.map((i) => i.id === id ? { ...i, status: updated.state === 'active' ? 'published' : 'draft' } : i));