Skip to content

feat(templates): allow deleting custom event templates#276

Merged
mindsers merged 1 commit into
mainfrom
feat/remove-event-templates
Jul 20, 2026
Merged

feat(templates): allow deleting custom event templates#276
mindsers merged 1 commit into
mainfrom
feat/remove-event-templates

Conversation

@mindsers

Copy link
Copy Markdown
Contributor

Summary

Adds the ability to delete custom event templates from the template view page. Previously templates could only be created and updated, never removed.

Behavior

  • Delete button on the template view page (/settings/congregation/templates/:id), manager-only.
  • System templates refusedday-off and freeform are looked up by key at runtime (createDayOff / createFreeformEvent), so they can never be deleted. The button is hidden for them and the server refuses the intent.
  • In-use templates refusedEvent.templateId is ON DELETE SET NULL. Deleting a template still linked to events would orphan those events (templateId → NULL), and key-filtered queries silently drop null-template rows — the exact class of bug the 20260720* migration series had to repair. The server blocks deletion and surfaces the event count; the button is disabled while events reference the template.
  • Cascade FKs (parts, serviceParts, responsibles, allowed-role rows) handle child cleanup, so a single delete suffices.

Implementation

  • deleteTemplate(db, templateId, congregationId) returns a discriminated result (ok / not-found / system / in-use).
  • view.tsx action branches on intent (delete vs default duplicate); loader exposes canDelete + eventCount; UI adds a destructive button + InlineDeleteDialog.
  • New i18n keys (en/fr) for success / error / in-use messages.
  • Extracted duplicateTemplate into its own duplicate-template.server.ts module (+ co-located test) to keep event-templates.server.ts under the file-size budget.
  • Drive-by fix: missing React key on a bare fragment in the template edit parts table.

Testing

  • TDD: 5 new unit tests for deleteTemplate covering success, not-found, system-refusal, in-use-refusal (asserts no delete + reports count), and congregation scoping.
  • Full events suite green; typecheck, lint, file-size, and service-test-coverage gates all pass.

Add a delete action for event templates from the template view page,
guarded server-side. System templates (day-off, freeform) are refused
because they are looked up by key at runtime, and templates still linked
to events are refused because Event.templateId is ON DELETE SET NULL and
removing them would orphan those events out of key-filtered queries.

Whole-template removal is manager-only; the button is hidden for system
templates and disabled while events reference the template.

Also fix a missing React key warning in the template edit parts table
(bare fragment inside a list) surfaced while testing.
@mindsers
mindsers force-pushed the feat/remove-event-templates branch from c9290cb to c5a85ad Compare July 20, 2026 21:22
@mindsers
mindsers merged commit aecc4a1 into main Jul 20, 2026
7 checks passed
@mindsers
mindsers deleted the feat/remove-event-templates branch July 20, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant