Structural alignment and component splitting #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Structural refactoring to align with Next.js App Router conventions and prepare for Contact Groups. Reorganizes routes, splits components, standardizes naming.
Why I Refactored
Non profit requirements include Contact Groups with member-only authentication via token handoff from pasofoodcooperative.com. The flat route structure made authentication boundaries unclear. Route groups fix this.
The 800+ line data grid handled too much. Splitting it enables reuse for the Contact Groups member selector (376+ members need virtualized lists and search).
Changes
Route Groups
Created route groups by authentication type.
(public)/contains the landing page. No auth required.(protected)/contains the referral database. Requires staff password via query parameter.This prepares for
(member)/where Contact Groups pages will live. Members arrive from the co-op portal with a 60-minute token.Route groups are organizational. URLs stay the same.
Component Splitting
Split
referral-data-grid.tsxinto focused modules.referral-data-grid.tsxhandles the core table. Column definitions, TanStack Table instance, row rendering.data-table-toolbar.tsxhandles desktop controls. Search, filters, column visibility, density, PDF export.data-table-pagination.tsxhandles page navigation. Size selector, prev/next, row count.data-table-filter-panel.tsxhandles desktop filter UI. Operator dropdowns, value inputs.data-table-mobile-drawer.tsxhandles mobile filters. Collapsible drawer for small screens.data-table-types.tsholds shared types and constants. Prevents duplication across components.table-filters.tscontains the custom TanStack filter function.The toolbar and pagination components can now be reused for Contact Groups without duplication.
Service Renaming
Renamed for consistency.
email-service.tsbecomesemail.ts.referral-store.tsbecomesreferral.ts.Moved
table-filters.tsfromsrc/lib/tosrc/components/referral/. It contains referral-specific logic that belongs with its component.Added
import "server-only"to services. This fails the build if someone imports server code into a client component. OWASP recommends this pattern for credential protection.Schema Additions
api.tsdefinesApiReferralwithz.coerce.date()for JSON date handling.error.tscentralizes error codes as a TypeScript enum.auth.tsis a placeholder for token validation. Will support theownerid|timestamp|hmac_signatureformat emails specified.Type Safety
Fixed type mismatch. Components declared
ColumnDef<Referral>but receivedApiReferral[]from the hook. These types handle dates differently. Components now correctly useApiReferral.Updated filter function signature to match TanStack Table v8 spec.
Accessibility
Added
aria-hidden="true"to decorative SVGs. Screen readers skip these.Added
type="button"to non-submit buttons. Prevents unintended form submissions.Other
Removed unused
src/app/api/referral/[id]/route.ts.Removed empty
src/lib/.gitkeep.Added
/team/rutledgepage.Updated middleware for route group paths.
Added
test/mocks/request.tshelper.Files Changed
Test Plan
Breaking Changes
None.