Build a support ticket viewer with 25-per-page paging and a detail view that returns to the same page
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">withLoading tickets…while a page loads,Showing 26-50 of 101 ticketswhen it arrives, andNo ticketswhen 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
countis more thanperPage, render<nav aria-label="Pagination">with a Previous button, a<span>readingPage 2 of 5and 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
ticketsarray or no numericcount, show<div role="alert">containingCould not load tickets.and a Retry button that loads the same page. When the error hasstatus401 or 403, the alert also saysCheck 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
count0 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 showsNone, a missing requesterUnknown. Created shows the UTC time asYYYY-MM-DD HH:MM UTC(2022-01-15 09:30 UTC), orUnknownwhen the date is missing or invalid. - A
<p>shows the description, orNo descriptionwhen 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
Unlock this question
Its tests and the tested solution are part of Pro.
- 2
- code listings
- 9
- edge cases
- 5
- follow-up questions
What's inside
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Private, and saved in this browser as you type. All your notes are on My lists.