Skip to content

TSA-267: undo verification ctrl z - #311

Merged
arturobdev merged 13 commits into
mainfrom
feat/TSA-267-undo-verification-ctrl-z
Sep 22, 2026
Merged

arturobdev merged 13 commits into
mainfrom
feat/TSA-267-undo-verification-ctrl-z

Conversation

@MatiStb

@MatiStb MatiStb commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator
image image

Closes #267

What

Adds the frontend half of #56 — Ctrl+Z undoes the last page verification and returns the user back to that page, transcribed again, with its original transcription.

Why

The backend endpoint POST /pages/:id/undo does not exist yet (#147). This PR ships a dev-only mock of it (guarded by process.env["NODE_ENV"] !== "production") so the flow can be exercised locally until #147 lands. It is therefore not available on the deployed QA environment.

What changed

  • FE — apps/frontend/src/pages/verification/verification.tsx: handleUndo (guards on lastVerifiedPageId, isVerifying, isEditing; rolls back on rejection with a notification)
  • FE — use-verification-keyboard.hook.ts: keydown listener for Ctrl/Cmd+Z (skips input/textarea/select/contentEditable, event.repeat)
  • FE — pages.slice.ts / actions.ts: undoPage thunk + undoOptimistic, lastVerifiedPageId, selectLastVerifiedPageId; verification-header.tsx hints Ctrl+Z Undo
  • shared — UndoPageResponseDto ({ pageId, status, transcription })
  • BE mock (dev only) — POST /api/v1/pages/:id/undo in page.controller.ts / page.service.ts, reusing DocumentGetPagesTranscriptionResponseDto

How to test

Local environment only — the mock endpoint is disabled in production.

  1. Start backend and frontend locally (npm run dev -w apps/backend and npm run dev -w apps/frontend).
  2. Create an account for the user owning the test document. The account used during development, undo-mock@test.dev / Password123! (user id 7), only exists in the local database where it was created — it is not part of the seed, so it cannot be reused by someone else's machine. Either sign up your own user or insert rows locally.
  3. Have a document with at least one transcribed page for that user (through the normal upload pipeline, or seeded locally).
  4. Open the verification screen for the document and confirm a page (Enter or the check button). The page becomes confirmed and the cursor advances.
  5. Press Ctrl+Z → you are put back on that page, it shows transcribed again with the original transcription.
  6. Confirm the same page again → it can be confirmed after undo ([BE] Allow a page to be confirmed again after undo #147).
  7. Inside the edit textarea, press Ctrl+Z while typing → it undoes your typing; the page is untouched.
  8. Failed undo (e.g. backend stopped, or nothing to undo) → the screen stays exactly as it was and a message shows: "The undo could not be completed. The page state has been restored."

Verified

  • Confirming a page and pressing Ctrl+Z puts the user back on that page, transcribed again
  • The undone page shows its original transcription
  • A failed undo leaves the screen as it was, with a message
  • Ctrl+Z inside the edit textarea undoes typing, not the verification
  • The page can be confirmed again after undo
  • POST /api/v1/pages/:id/undo → 200 with { pageId, status: "transcribed", transcription }; DB reverts (status → transcribed, verified_by → null)

@MatiStb MatiStb changed the title Feat/tsa 267 undo verification ctrl z TSA-267: undo verification ctrl z Sep 16, 2026
…ification-ctrl-z

# Conflicts:
#	apps/backend/src/modules/pages/page.controller.ts
#	apps/backend/src/modules/pages/page.service.ts
@MatiStb MatiStb added the feature New feature (auto-applied by the feature template) label Sep 16, 2026

@arturobdev arturobdev left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I noticed the confirm → undo → confirm AC cannot really be validated with the current dev mock.
The UI advances after the second confirm, but the DB still keeps the page as transcribed, which matches the known backend issue from #147.

Since #147 is still pending, should this AC remain blocked by that ticket instead of being tested against the temporary mock?

Undo test

Comment thread apps/backend/src/modules/pages/page.service.ts Outdated
Comment thread apps/backend/src/modules/pages/page.service.ts
@MatiStb MatiStb added the blocked Stalled by a dependency, question or external blocker label Sep 18, 2026
…6-transcripta into feat/TSA-267-undo-verification-ctrl-z

# Conflicts:
#	apps/frontend/src/modules/pages/pages-api.ts
#	apps/frontend/src/modules/pages/slices/actions.ts
#	apps/frontend/src/modules/pages/slices/pages.slice.ts
#	apps/frontend/src/modules/pages/slices/pages.ts
#	apps/frontend/src/pages/verification/verification.tsx
@MatiStb MatiStb removed the blocked Stalled by a dependency, question or external blocker label Sep 20, 2026
@IlliaMatushchak
IlliaMatushchak force-pushed the feat/TSA-267-undo-verification-ctrl-z branch from 254eeb6 to 64671b2 Compare September 21, 2026 18:58
Comment thread apps/backend/src/modules/pages/page.service.ts Outdated
@IlliaMatushchak

Copy link
Copy Markdown
Collaborator

After resolving conflicts and merge 'PageStatus' dissapear from import in page.service.ts and causes the error. I don`t now why. But if it happens, just check and fix it.

…ification-ctrl-z

# Conflicts:
#	apps/backend/src/modules/pages/libs/constants/constants.ts
#	apps/backend/src/modules/pages/libs/enums/page-error-message.enum.ts
#	apps/backend/src/modules/pages/page.controller.ts
#	apps/backend/src/modules/pages/page.service.ts
#	apps/frontend/src/pages/verification/verification.tsx
#	packages/shared/src/modules/pages/libs/types/page-undo-response-dto.type.ts
@arturobdev

Copy link
Copy Markdown
Collaborator

I tested it locally and it works correctly.

correct → undo → correct works now, and the event history is preserved using attempt:

undo flow

contextWords still comes back as an empty array from the undo endpoint, but that behavior comes from the backend implementation merged in #343, so there is nothing to change on the frontend side here.

@arturobdev
arturobdev merged commit b39e208 into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature (auto-applied by the feature template)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FE] Undo the last verification with Ctrl+Z

4 participants