Skip to content

fix(directory): keep failed owner actions in place#364

Open
Zekbot001 wants to merge 2 commits into
profullstack:masterfrom
Zekbot001:money/ugig-poll-vote-upsert
Open

fix(directory): keep failed owner actions in place#364
Zekbot001 wants to merge 2 commits into
profullstack:masterfrom
Zekbot001:money/ugig-poll-vote-upsert

Conversation

@Zekbot001
Copy link
Copy Markdown

Summary

  • keep directory owners on the listing when hide/show requests fail
  • avoid redirecting away after failed delete requests
  • show API errors for failed owner actions and cover both regressions with focused UI tests

Paid task

https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e

Verification

  • pnpm exec vitest run 'src/app/directory/[id]/DirectoryOwnerActions.test.tsx'
  • pnpm exec eslint 'src/app/directory/[id]/DirectoryOwnerActions.tsx' 'src/app/directory/[id]/DirectoryOwnerActions.test.tsx'
  • git diff --check

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 31, 2026

Greptile Summary

This PR fixes owner action regressions in the directory listing component by wrapping all three mutation handlers (handleToggleVisibility, handleDelete, and handleUpdate) in try/catch/finally blocks, preventing silent failures from redirecting users away or leaving buttons disabled indefinitely. Error messages from the API are now surfaced inline via a role="alert" div that is rendered in both the editing and owner-action views, and stale error state is cleared on Edit/Cancel transitions.

  • Error handling standardised: all three handlers now use responseError() to extract API error text and a shared finally block to reset loading, matching the same pattern throughout.
  • UI state preserved on failure: failed hide/show and delete requests no longer call router.refresh() or router.push(), keeping the owner in context with a visible error.
  • Tests added: three focused Vitest cases cover the visibility-failure, delete-failure, and network-layer-edit-failure scenarios.

Confidence Score: 5/5

Safe to merge — all three handlers now correctly preserve UI state on failure and the changes are well-covered by the new focused tests.

The refactoring is mechanically sound: try/catch/finally is applied consistently across all three handlers, the responseError helper gracefully falls back when parsing fails, and error state is cleared at every transition point. The two regressions called out in the PR description are both directly exercised by the new tests. No unguarded state mutations or uncaught promise rejections remain in the changed code paths.

No files require special attention.

Important Files Changed

Filename Overview
src/app/directory/[id]/DirectoryOwnerActions.tsx Refactors all three action handlers to use try/catch/finally, surfaces API error messages in a new alert div on the Owner Actions panel, and clears stale error state when transitioning between Edit and Owner Actions views.
src/app/directory/[id]/DirectoryOwnerActions.test.tsx New test file covering the three regressions: failed visibility toggle stays in place, failed delete stays in place, and a network-layer edit failure re-enables the Save button.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Owner Action Button Clicked] --> B{Action Type}
    B -->|Edit| C[Clear error, set editing true]
    B -->|Hide or Show| D[Clear error, set loading true]
    B -->|Delete| E{confirm dialog}
    E -->|Cancelled| F[return early]
    E -->|Confirmed| G[Clear error, set loading true]
    C --> H[Render Edit Form]
    H -->|Submit| I[Clear error, set loading true]
    H -->|Cancel| J[Clear error, set editing false]
    I --> K[fetch PATCH]
    D --> L[fetch PATCH status]
    G --> M[fetch DELETE]
    K -->|Network error| N[catch: setError Update failed]
    K -->|not ok| O[setError from responseError]
    K -->|ok| P[setEditing false + router.refresh]
    L -->|Network error| Q[catch: setError Visibility update failed]
    L -->|not ok| R[setError from responseError]
    L -->|ok| S[router.refresh]
    M -->|Network error| T[catch: setError Delete failed]
    M -->|not ok| U[setError from responseError]
    M -->|ok| V[router.push /directory]
    N --> W[finally: setLoading false]
    O --> W
    P --> W
    Q --> X[finally: setLoading false]
    R --> X
    S --> X
    T --> Y[finally: setLoading false]
    U --> Y
    V --> Y
    W --> Z[Show alert in Edit form]
    X --> AA[Show alert in Owner Actions panel]
    Y --> AA
Loading

Reviews (2): Last reviewed commit: "fix(directory): recover from edit networ..." | Re-trigger Greptile

Comment thread src/app/directory/[id]/DirectoryOwnerActions.tsx Outdated
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