Build a support ticket viewer with 25-per-page paging and a detail view that returns to the same page

mediumAbout 45 minutesUpdated CodingProAsked atZendeskreactpaginationmaster-detailfetchabort-controllerrace-conditionsfocus-managementaccessibility
Not solved

Share this question

Problem

Build the front end of a support ticket viewer for a help desk. It lists an account's tickets 25 per page, lets the agent page through them, and opens one ticket's details. Back must return to the same page of the list. The API is passed in as a prop, so the component can be tested without the network.

<TicketViewer fetchTickets perPage={25} />

fetchTickets({ page, perPage, signal }) returns a promise of { tickets, count }. page starts at 1, count is the total number of tickets in the account, and each ticket is:

{ id: 12, subject: "Printer on fire", status: "open", priority: "high",
  requester: "Ana Lima", created_at: "2022-01-15T09:30:00Z", description: "Smoke is coming out of tray 2." }

List view

  • On mount, load page 1. Show <p role="status"> with Loading tickets… while a page loads, Showing 26-50 of 101 tickets when it arrives, and No tickets when there are none.
  • The tickets render as <ul aria-label="Tickets">. Each <li> holds a <button type="button"> whose text is #{id} {subject} (use (no subject) for an empty subject) and a <span> with the status. The list is not shown while a page loads.
  • When count is more than perPage, render <nav aria-label="Pagination"> with a Previous button, a <span> reading Page 2 of 5 and a Next button. Previous is disabled on page 1 and Next on the last page. The nav uses the last known count, so it stays on screen while the next page loads.
  • If the promise rejects, or the response has no tickets array or no numeric count, show <div role="alert"> containing Could not load tickets. and a Retry button that loads the same page. When the error has status 401 or 403, the alert also says Check the API credentials.
  • Loading a page aborts the previous request, and a response that is not the latest is ignored. Unmounting aborts the request in flight.
  • If a response says the requested page is past the last page (for example tickets were deleted and page 5 of 4 was asked for), load the last page instead. With count 0 the last page is 1.

Detail view

  • Clicking a ticket's button replaces the list view (status, list and nav are not rendered) with an <article> that has an <h2 tabIndex={-1}> with the same #{id} {subject} text, which receives focus.
  • A <dl> lists, in order, Status, Priority, Requester and Created, each a <dt> followed by its <dd>. A missing priority shows None, a missing requester Unknown. Created shows the UTC time as YYYY-MM-DD HH:MM UTC (2022-01-15 09:30 UTC), or Unknown when the date is missing or invalid.
  • A <p> shows the description, or No description when it is empty.
  • A Back to tickets button shows the list again on the same page, without a new request, and moves focus to the button of the ticket that was open.

Ref. UR-1538 · © UIRound · uiround.com/questions/build-a-support-ticket-viewer-with-25-per-page-paging-and-a-detail-view-that-returns-to-the-same-page

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment