Skip to content

[PB-7033]: feat: load the wholesaler partner detail page from its URL - #186

Open
jzunigax2 wants to merge 3 commits into
mainfrom
feat/wholesaler-partner-detail
Open

jzunigax2 wants to merge 3 commits into
mainfrom
feat/wholesaler-partner-detail

Conversation

@jzunigax2

Copy link
Copy Markdown
Contributor

What

The wholesaler partner detail page (/wholesalers/partners/:id) now works when opened from a shared link, a new tab or a refresh, not only when navigating from the partners table.

Why

The page read the partner only from the router state set by the partners table, and there was no endpoint to fetch a partner by id. Opening the URL directly showed the title "Partner" with no email, status or actions; only the usage cards loaded

How

  • Service: wholesalersService.getPartner(id) calls the new GET /wholesalers/partners/:id (backend PR below).
  • Hook: loading moved out of the page into useWholesalerPartner.
    • When the user comes from the partners table, the row in router state is used and the partner request is skipped. That state is read once and then cleared, so a refresh or a later visit fetches fresh data.
    • Partner and usage load in parallel. If the partner request fails, its error alone decides what happens.
    • 400 (malformed id), 403 (another wholesaler's partner) and 404 redirect to the partners list. Other errors show the server message via apiErrorMessage.

@jzunigax2
jzunigax2 requested a review from sg-gs November 27, 2026 21:05
@jzunigax2 jzunigax2 self-assigned this Nov 27, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
object-storage-management-web 8efda28 Commit Preview URL

Branch Preview URL
Dec 01 2026, 01:43 PM

const [notFound, setNotFound] = useState(false);
// The partners table passes the row in router state, which saves the partner request. It is read once
// here because the effect below clears it, and StrictMode's second effect run must still see it.
const [statePartner] = useState(() => (location.state as { partner?: WholesalerPartnerDetail } | null)?.partner);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now that GET /partners/:id exists, why keep the router state at all? It saves one cheap request that runs in parallel with the usage one anyway, and it costs the state-clearing effect, the useState snapshot for StrictMode, the known branch in loadWholesalerPartner and a row that can be stale. Always fetching would remove all of that, and the table wouldn't need to pass state either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed


// When the partner can't be loaded the usage request fails for the same reason, so only the partner error counts.
if (partner.status === 'rejected') {
if (NOT_FOUND_STATUSES.includes(partner.reason?.response?.status)) return { kind: 'notFound' };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's already hasApiErrorStatus in utils/apiError, use it instead of reading reason.response.status by hand.

@jzunigax2 jzunigax2 Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, also added a lint rule which I read somewhere was a the best way to stop repeated mistakes by agents. we can give it a try. I also added eslint-suppressions to ignore places in the codebase already using this anti pattern, we should refactor those later

…d syntax rules

- Introduced eslint-suppressions.json to manage specific ESLint rule suppressions across various files.
- Updated eslint.config.mjs to include new rules for handling restricted syntax in TypeScript files, ensuring better error handling for API responses.
@jzunigax2
jzunigax2 requested a review from sg-gs December 1, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants