fix(contacts): decode paginated envelope on company-detail Contacts and Sites cards #64
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
psa-systems/mokosh-apps!64
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/company-detail-cards-shape"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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.