Skip to content

frontend: extract shared run()/useMutation helper (duplicated in 2 admin views) #61

Description

@countercheck

Source: codebase audit, 2026-06-11 (audit finding F7, Tier 1)
Severity: Low
Category: DRY

Problem

The same mutation-wrapper pattern is duplicated:

const run = (action: () => Promise<unknown>, onSuccess: () => void): void => {
  setError(null); setNotice(null); setBusy(true);
  action().then(onSuccess).catch(err => setError(errorMessage(err))).finally(() => setBusy(false));
};

Sites:

Only two sites today, so it's not worth its own hook in isolation — but it folds naturally into the cluster with #55 / #57 / #58.

Suggested approach

Either:

  1. If doing the frontend: extract useAsyncData<T> hook to replace duplicated three-state load pattern (7 views) #57 useAsyncData refactor: pair it with a sibling useMutation(action, { onSuccess, refresh? }) hook in the same frontend/src/hooks/ module.
  2. Else: defer — the duplication is small and isolated.

Test alongside whichever hook lands.

Part of a cluster

Same PR as #55, #56, #57, #58.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions