GhaylStackDocumentationv1.0.2
العربيةWebsite
Build and extend

Build and extend

Add a Dashboard page

Connect a React page to its route, translation namespace, navigation entry, permissions and API queries using the existing Tickets screen.

Start with an existing feature contract

Use the Dashboard Tickets screen as a complete example of the application's conventions. Its page is src/pages/tickets/tickets.tsx, its typed client is src/api/tickets.ts, and its list endpoint is GET /api/v1/tickets. Work from clients/dashboard throughout this guide.

For a new feature, identify its server contract and permission before building the screen. If no endpoint exists, implement it using Add a feature first. Reuse the matching API client function rather than embedding an assumed URL in the component.

Create the component and data query

Pages export a named component, such as TicketsPage. The Tickets implementation uses useTranslation("tickets"), React Query, and shared EntityPageHeader, loading, empty-state and pagination components from @/components/list.

The following reduced query uses the existing searchTickets contract. It belongs inside a component; initialize pageNumber in state and import the referenced helpers:

tsx
const query = useQuery({
  queryKey: ["tickets", "list", { pageNumber }],
  queryFn: () => searchTickets({
    pageNumber,
    pageSize: 20,
    sortBy: "createdAtUtc",
    sortDir: "desc",
  }),
});

Include every effective filter in the query key. The complete screen debounces search, resets pagination when filters change and retains previous results during pagination. Its create flow invalidates ["tickets"] after success. Follow that pattern for mutations and render loading, empty, success and error states deliberately. Reuse apiFetch through the API module to keep request behavior consistent.

Register the route and its namespace

src/routes.tsx uses lazyNamed to load a page and its translation catalogs together. The existing registration is:

tsx
const TicketsPage = lazyNamed(
  () => import("@/pages/tickets/tickets"),
  "TicketsPage",
  ["tickets"],
);

Its route sits beneath ProtectedRoute and AppShell:

tsx
{ path: "tickets", element: withSuspense(<TicketsPage />) }

Adapt the component, import and path for your new screen; do not add a duplicate Tickets route. Include namespaces used by child components as well. Existing multi-namespace registrations, such as product details with ["catalog", "files"], show this relationship.

Add the translated text

For a new namespace, create matching src/locales/en-US/<namespace>.json and src/locales/ar-OM/<namespace>.json. Register the English import in lazyCatalogs in src/i18n.ts, then list the namespace in lazyNamed. The Arabic bundle discovers JSON catalogs through src/locales/ar-OM.ts.

Keep navigation labels in the common catalog, because the shell renders before route catalogs load. Translate field labels, loading messages, empty results, errors and action feedback, not only the page heading. Missing Arabic text can fall back to English; that is a recovery path, not completion of the Arabic screen. Follow Localization for direction and language switching.

Connect navigation and permissions

Add navigation data in src/components/layout/nav-data.ts. Desktop and mobile navigation share this data; avoid adding a second hand-written sidebar link. The Tickets entry demonstrates its shape:

tsx
{
  to: "/tickets",
  labelKey: "nav.tickets",
  icon: Ticket,
  perm: "Permissions.Tickets.View",
}

Choose the actual permission enforced by your endpoint. Navigation visibility improves the interface, while server authorization controls access. ProtectedRoute restores and checks authentication; it does not enforce each feature permission. For permission-dependent queries and actions, wait for hydrated permissions and handle direct URL access as well. See Authorization.

Verify the complete user journey

Run npm run build and npm run lint; the build includes TypeScript checking. Verify direct navigation and reload, English and Arabic, narrow-screen navigation, denied access, empty results and an API error. Change a filter and confirm the request and query key change together. After a successful mutation, confirm the affected list refreshes.

Use the existing npm run test:e2e setup for meaningful behavior checks. A route that renders successfully still needs an API authorization check and a translated error path. Inspect the Network response and stable error code when diagnosing access failures; localized error prose is unsuitable for branching.

Implementation references

View MarkdownBack to top

Search documentation

Use ↑ ↓ to move, Enter to open and Esc to close.