Skip to content

chore: Refactor template update mutations and actions#7386

Merged
dsamojlenko merged 33 commits into
mainfrom
chore/refactor_template_update_mutations
Jun 18, 2026
Merged

chore: Refactor template update mutations and actions#7386
dsamojlenko merged 33 commits into
mainfrom
chore/refactor_template_update_mutations

Conversation

@dsamojlenko

@dsamojlenko dsamojlenko commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary | Résumé

Related: #7336

This PR refactors the template update flow to use a consolidated updateTemplate mutation path with shared command types across the frontend and backend. The goal is to reduce duplicated mutation logic, make the update surface easier to reason about, and improve type safety from the form builder actions all the way through to persistence.

This is part of a broader effort (#7302, #7323) to reduce surface area in the lib/templates module for upcoming Template Versioning work.

What changed

  • Consolidated the template update mutations into a shared command-based flow.
  • Moved update-specific types into a central shared definition so frontend callers and backend handlers use the same contract.
  • Updated the form builder actions and API route to use the new typed update commands.
  • Removed the old per-field mutation helpers in favor of the unified update implementation.
  • Updated tests to cover the refactored update behavior and type-shape changes.

Why

The previous structure spread template update behaviour across several separate mutation helpers, which made the update path harder to maintain and easier to drift out of sync. This refactor makes the mutation flow more consistent, reduces duplication, and gives us stronger compile-time guarantees around the data being sent from the UI to the backend.

@github-actions

Copy link
Copy Markdown
Contributor

@timarney timarney changed the title Chore/refactor template update mutations refactor: template update mutations Jun 17, 2026
@dsamojlenko dsamojlenko changed the title refactor: template update mutations chore: Refactor template update mutations and actions Jun 17, 2026
@dsamojlenko dsamojlenko requested a review from Copilot June 17, 2026 16:49
@dsamojlenko dsamojlenko marked this pull request as ready for review June 17, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the template update flow to a single command-based updateTemplate mutation, with shared update command types consumed across the UI/server actions and template persistence layer. It reduces the number of per-field mutation helpers and centralizes authorization, validation, cache invalidation, and audit logging around update operations.

Changes:

  • Introduces shared UpdateTemplateCommand / UpdateTemplateAction types and migrates callers to the command-based update surface.
  • Consolidates multiple template update mutations into lib/templates/mutations/updateTemplate.ts and removes the old per-field mutation helpers.
  • Updates form builder UI and server actions to call the unified update path; updates tests accordingly.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/tests/templates.test.ts Updates tests to use the new command-based updateTemplate calls and updated Prisma update shapes.
lib/templates/types.ts Adds shared command/action types for template updates.
lib/templates/mutations/updateTemplate.ts Refactors mutation into a consolidated command handler with per-action authorization, validation, query building, and audit logging.
lib/templates/mutations/updateSecurityAttribute.ts Removes legacy per-field mutation (replaced by unified update).
lib/templates/mutations/updateIsPublishedForTemplate.ts Removes legacy publish mutation (replaced by unified update).
lib/templates/mutations/updateFormSaveAndResume.ts Removes legacy save/resume mutation (replaced by unified update).
lib/templates/mutations/updateFormPurpose.ts Removes legacy purpose mutation (replaced by unified update).
lib/templates/mutations/updateFormBranding.ts Removes legacy branding mutation (replaced by unified update).
lib/templates/mutations/updateClosedData.ts Removes legacy closed-data mutation (replaced by unified update).
components/clientComponents/globals/Header/PublishMenu/PublishButton.tsx Switches publish/close flows to call the unified updateTemplate action with commands.
app/api/templates/[formID]/route.ts Removes active PUT handler (currently left as commented-out code); keeps GET/DELETE.
app/(gcforms)/[locale]/(form administration)/form-builder/actions.ts Refactors server actions to route multiple update operations through unified command handling.
app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/components/close/SetClosingDate.tsx Updates close-date UI to use unified updateTemplate commands.
app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/saveAndResume/SetSaveAndResume.tsx Updates save/resume UI to use unified updateTemplate commands.
app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/FormProfile.tsx Updates form purpose/security attribute updates to use unified updateTemplate commands.
app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/branding/Branding.tsx Updates branding updates to use unified updateTemplate commands.
app/(gcforms)/[locale]/(form administration)/form-builder/[id]/publish/components/Publish.tsx Updates publish flow to use unified updateTemplate commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/templates/mutations/updateTemplate.ts Outdated
Comment thread lib/templates/mutations/updateTemplate.ts
Comment thread app/api/templates/[formID]/route.ts Outdated
@dsamojlenko dsamojlenko merged commit ec7c706 into main Jun 18, 2026
14 checks passed
@dsamojlenko dsamojlenko deleted the chore/refactor_template_update_mutations branch June 18, 2026 18:12
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.

3 participants