Move the billing details form to TanStack Query

React · React · intermediate · modification

The billing details page was the last settings page still fetching by hand in a `useEffect` with its own cancel flag and loading and error flags. `src/settings/BillingDetailsPage.jsx` now loads the details with `useQuery` under the `['billing-details']` key and fills the form from the result, and saves with `useMutation`, writing the saved details back into the query cache. The loading, error and save states come from the query and the mutation. `src/settings/BillingDetailsPage.test.jsx` (new) mocks `src/api.js` and tests the page's load, save and error states.

Admin SPA in plain JavaScript (no TypeScript, no type-check step): React 18.3, Vite 5, function components. `package.json` pins `@tanstack/react-query` `^5.59.0` (the lockfile has 5.59.20); `src/main.jsx` (existing, unchanged) renders the app inside one `QueryClientProvider`, and the other settings pages already use `useQuery`/`useMutation`. Tests run with `npm test`: Vitest 2 with @testing-library/react 16 in jsdom. Existing and unchanged: `src/api.js` exports `apiGet(path)` and `apiPut(path, body)`, which send same-origin JSON requests, resolve to the parsed JSON body and throw `ApiError` (with `status`) for any non-2xx answer. `GET /api/billing/details` answers `{ companyName, billingEmail, vatId }`, all strings; `vatId` is `""` when the workspace has none. `PUT /api/billing/details` takes the same shape, validates it (company name and email required, VAT ID optional), stores it and answers with the stored details. The page is the route `/settings/billing` and has no other callers.

Requirements

Files touched

Review this PR

React practice