fix(contacts): decode paginated envelope on company-detail Contacts and Sites cards #64

Merged
YousifShkara merged 1 commit from fix/company-detail-cards-shape into main 2026-06-05 07:58:24 +02:00
Owner

The CompanyDetailPage's Contacts and Sites resources at src/pages/contacts.rs:761 and :772 declared the response as Vec and Vec respectively, but mokosh-server returns the paginated envelope { data: [...], meta: {...} } for both endpoints. Decoding into a bare Vec always failed and .ok() swallowed the error as None, so the cards rendered the "Could not load contacts" / "Could not load sites" empty state even when the API returned data successfully (status 200, body containing the row).

Also fix RemoteContact's field names. Server's ContactResponse uses phone and title; the SPA declared phone_primary and job_title with #[serde(default)], which silently parsed as None whenever the server sent the real names. The Phone and Role columns were therefore always blank even when the row carried the values.

Fix:

  • RemoteContact: rename phone_primary -> phone, job_title -> title to match the server's ContactResponse shape.
  • Add PaginatedSites { data: Vec }; PaginatedContacts already existed.
  • Switch the two resource fetchers in CompanyDetailPage to PaginatedContacts and PaginatedSites.
  • Update CompanyContactsCard and CompanySitesCard signatures + match arms to consume the envelope (page.data is_empty / iter) instead of treating the resource as a bare Vec.
  • Sweep two stale phone_primary/job_title reads at lines 1784-1785 (ContactRow construction in the main contacts list page).

Verified: cargo check, cargo clippy -- -Dwarnings, cargo fmt --all --check all clean.

Reproduced live on staging: contact 1b0fc3ee-c2ba-401a-b480-64862c420c81 was correctly linked to company 4bba244b-0853-4f04-92ea-9f0f922357e4 in the DB and returned by GET /api/v1/contacts/companies/4bba244b.../contacts as { data: [{...the contact...}], meta: { total: 1 } }, but the company detail page rendered "Could not load contacts" because the SPA could not deserialize the response. Same shape for sites.

The CompanyDetailPage's Contacts and Sites resources at src/pages/contacts.rs:761 and :772 declared the response as Vec<RemoteContact> and Vec<SiteSummary> respectively, but mokosh-server returns the paginated envelope { data: [...], meta: {...} } for both endpoints. Decoding into a bare Vec always failed and .ok() swallowed the error as None, so the cards rendered the "Could not load contacts" / "Could not load sites" empty state even when the API returned data successfully (status 200, body containing the row). Also fix RemoteContact's field names. Server's ContactResponse uses phone and title; the SPA declared phone_primary and job_title with #[serde(default)], which silently parsed as None whenever the server sent the real names. The Phone and Role columns were therefore always blank even when the row carried the values. Fix: - RemoteContact: rename phone_primary -> phone, job_title -> title to match the server's ContactResponse shape. - Add PaginatedSites { data: Vec<SiteSummary> }; PaginatedContacts already existed. - Switch the two resource fetchers in CompanyDetailPage to PaginatedContacts and PaginatedSites. - Update CompanyContactsCard and CompanySitesCard signatures + match arms to consume the envelope (page.data is_empty / iter) instead of treating the resource as a bare Vec. - Sweep two stale phone_primary/job_title reads at lines 1784-1785 (ContactRow construction in the main contacts list page). Verified: cargo check, cargo clippy -- -Dwarnings, cargo fmt --all --check all clean. Reproduced live on staging: contact 1b0fc3ee-c2ba-401a-b480-64862c420c81 was correctly linked to company 4bba244b-0853-4f04-92ea-9f0f922357e4 in the DB and returned by GET /api/v1/contacts/companies/4bba244b.../contacts as { data: [{...the contact...}], meta: { total: 1 } }, but the company detail page rendered "Could not load contacts" because the SPA could not deserialize the response. Same shape for sites.
fix(contacts): decode paginated envelope on company-detail Contacts and Sites cards
All checks were successful
Create release / Create release from merged PR (pull_request) Has been skipped
Check / clippy + fmt + tests (pull_request) Successful in 45s
0423fdce0c
The CompanyDetailPage's Contacts and Sites resources at src/pages/contacts.rs:761 and :772 declared the response as Vec<RemoteContact> and Vec<SiteSummary> respectively, but mokosh-server returns the paginated envelope { data: [...], meta: {...} } for both endpoints. Decoding into a bare Vec always failed and .ok() swallowed the error as None, so the cards rendered the "Could not load contacts" / "Could not load sites" empty state even when the API returned data successfully (status 200, body containing the row).

Also fix RemoteContact's field names. Server's ContactResponse uses phone and title; the SPA declared phone_primary and job_title with #[serde(default)], which silently parsed as None whenever the server sent the real names. The Phone and Role columns were therefore always blank even when the row carried the values.

Fix:
- RemoteContact: rename phone_primary -> phone, job_title -> title to match the server's ContactResponse shape.
- Add PaginatedSites { data: Vec<SiteSummary> }; PaginatedContacts already existed.
- Switch the two resource fetchers in CompanyDetailPage to PaginatedContacts and PaginatedSites.
- Update CompanyContactsCard and CompanySitesCard signatures + match arms to consume the envelope (page.data is_empty / iter) instead of treating the resource as a bare Vec.
- Sweep two stale phone_primary/job_title reads at lines 1784-1785 (ContactRow construction in the main contacts list page).

Verified: cargo check, cargo clippy -- -Dwarnings, cargo fmt --all --check all clean.

Reproduced live on staging: contact 1b0fc3ee-c2ba-401a-b480-64862c420c81 was correctly linked to company 4bba244b-0853-4f04-92ea-9f0f922357e4 in the DB and returned by GET /api/v1/contacts/companies/4bba244b.../contacts as { data: [{...the contact...}], meta: { total: 1 } }, but the company detail page rendered "Could not load contacts" because the SPA could not deserialize the response. Same shape for sites.
YousifShkara deleted branch fix/company-detail-cards-shape 2026-06-05 07:58:24 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
psa-systems/mokosh-apps!64
No description provided.