Export fails from Post Inspection Revenue widget
Objective
- Fix HomeBinder CSV export from the Concierge Adoption section on Admin Post-Inspection Revenue so staff can download the same data they already see in the widget.
- Remove the generic “Export failed” dead-end when charts/KPIs load successfully for the same filters.
- Align export authentication with the rest of the Admin dashboard (session must work in production on the Admin host).
Background
- Reproduced by Ryan on Admin Attik: open Post-Inspection Revenue → Concierge Adoption → Export (either option) → toast “Export failed” with no useful detail. Widget data for the same company/date filters loads normally.
- Screen: Admin → Post-Inspection Revenue (
/admin/post-inspection-revenue). Export lives inConciergeAdoptionSectiononly (ProPair section has no export). - Two export modes (both fail today):
- By Inspection Date — Attik inspections in range with a HomeBinder integration record.
- Sent Within Date Range — HomeBinder records sent in range (spreadsheet column format).
- Root cause hypothesis (code trace): Dashboard fetches use
callServerAction, which forwards theauthjs.session_tokencookie from the Next server to the API. Export usesclientApiFetch(browserfetchwithcredentials: 'include'directly toNEXT_PUBLIC_SERVER_URL). On Admin production (cross-origin to API), the session cookie often does not reach the API → 401 from auth middleware inlogin.ts. The export error handler only readsmessage/errorfrom JSON bodies; auth failures return{ result: 'failed', reason: '...' }, so the UI shows a generic “Export failed” title with no description. - Backend export endpoints exist and are gated correctly (same permission as the widget):
GET /homebinder/export/by-inspection-dateandGET /homebinder/export/sent-spreadsheet, both behindrequireAdminPerm('admin-post-inspection-revenue-view')inhomebinder.ts. CSV builders inexportHomeBinderResults.tsandexportHomeBinderSentSpreadsheet.tsreturn validation errors as{ message }or CSV on success (empty data → header-only CSV, not an error). - Page access already requires
admin-post-inspection-revenue-viewviaadminLoginCheckin the Post-Inspection Revenue layout.
Product decisions (v1)
- Export must work for users who can view the Post-Inspection Revenue widget with the same filter params (
companyIds,startDate,endDate). - Both export menu items must succeed after fix.
- Failed exports should surface a actionable error message when the API rejects the request (not a silent/generic toast).
- Decision needed (dev): exact transport fix—likely match dashboard pattern (
callServerActionor a server action returning CSV) rather than browser-directclientApiFetch; dev owns approach.
Scope
Frontend (attik-frontend)
src/app/admin/post-inspection-revenue/_components/ConciergeAdoptionSection.tsx—handleExportcallsclientApiFetchtohomebinder/export/...; error parsing in catch block (lines ~252–282).src/app/admin/post-inspection-revenue/PostInspectionRevenueClient.tsx— passesexportParamsfrom applied filters; dashboard loads viacallServerActiontopost-inspection-revenue/concierge-adoption(working path to mirror).src/util/functions/fetching/clientApiFetch.tsvssrc/util/functions/fetching/callServerAction.ts— auth/cookie forwarding difference is the likely break.src/app/admin/post-inspection-revenue/layout.tsx— page permission gate.
Backend (attik-backend)
src/routes/homebinder.ts— export route handlers +requireAdminPerm('admin-post-inspection-revenue-view').src/util/functions/homebinder/exportHomeBinderResults.ts— by-inspection-date CSV aggregation.src/util/functions/homebinder/exportHomeBinderSentSpreadsheet.ts— sent-spreadsheet CSV.src/routes/login.ts— session auth middleware; 401 body shape{ result, reason }.src/routes/adminPostInspectionRevenue.ts— concierge-adoption data endpoint (reference for working auth path).src/util/functions/admin/hasAdminPerm.ts— admin permission check.
Out of scope
- Changing concierge-adoption chart/KPI aggregation logic.
- New export formats or ProPair export (not requested).
Done when
- [ ] Ryan (or any user with
admin-post-inspection-revenue-view) can export By Inspection Date CSV from Concierge Adoption on Admin production. - [ ] Same user can export Sent Within Date Range CSV.
- [ ] Export uses the same applied filters as the visible widget (
companyIds,startDate,endDate). - [ ] Auth failures and API errors show a readable message in the toast (not generic “Export failed” only).
- [ ] Network trace on repro shows 200 + CSV body (not 401) after fix.
References
- Admin page: Post-Inspection Revenue → Concierge Adoption (
/admin/post-inspection-revenue) - Slack report: attik-talk message
attik-frontend/src/app/admin/post-inspection-revenue/_components/ConciergeAdoptionSection.tsxattik-backend/src/routes/homebinder.ts
Status: Completed
Log in to comment and vote
No comments yet
Be the first to share your thoughts.