fix(sell): replace assetType text input with canonical Select and add homepage filter - #421
Open
azahjessica49-commits wants to merge 1 commit into
Conversation
… homepage filter - Add frontend/app/lib/assetTypes.ts as single source of truth for ASSET_TYPE_VALUES, ASSET_TYPE_LABELS, ASSET_OPTIONS and formatAssetType. Includes all 5 carriers (MTN, Glo, Airtel, 9mobile, Spectranet) x asset types (Airtime/Data) producing canonical uppercase values (e.g. MTN_AIRTIME). - Replace open text input on sell/page.tsx with a structured <select> driven by ASSET_OPTIONS imported from the shared constants file. - Replace open regex in server/src/schemas/trade.schemas.ts with z.enum(ASSET_TYPE_VALUES) so the backend rejects arbitrary strings and validates against the same allowlist as the frontend. - Extend paginationSchema with an optional assetType enum field so the GET /api/v1/trades route can accept and validate filter queries. - Update GET /trades handler in server/src/routes/trades.ts to apply parameterised WHERE asset_type = \ clause when assetType is supplied, keeping both the data and count queries in sync. - Add frontend/app/components/ListingsGrid.tsx (client component) with a FilterBar of pill buttons (All + one per canonical asset type) that drives useTradeList, replacing the server-rendered static grid on the homepage. - Replace inline server-fetched listings section in frontend/app/page.tsx with <ListingsGrid /> to support live client-side filtering. Closes #assettype-canonical
|
@azahjessica49-commits Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #377
Overview
This PR replaces the free-text
assetTypeinput on the sell form with a structured<select>component backed by a canonical allowlist, wires the same allowlist into backend schema validation, and adds a live filter bar to the homepage listings grid.Related Issue
Closes #assettype-canonical
Changes
🛒 Sell Form — Structured Asset Type Select
[ADD]
frontend/app/lib/assetTypes.tsASSET_TYPE_VALUES(9 canonical uppercase entries: MTN, Glo, Airtel, 9mobile, Spectranet × Airtime/Data).ASSET_OPTIONS({value, label}pairs),ASSET_TYPE_LABELSrecord, andformatAssetTypehelper.CARRIER_TYPEuppercase pattern (e.g.MTN_AIRTIME).[MODIFY]
frontend/app/sell/page.tsxASSET_OPTIONSconst array.assetTypefield is now a<select>importing from the shared constants — Spectranet now included.🔒 Backend Schema — Allowlist Validation
[MODIFY]
server/src/schemas/trade.schemas.tsz.string().regex()onassetTypewithz.enum(ASSET_TYPE_VALUES)."mtn","Mtn Nigeria") are now rejected with a clear error listing valid values.paginationSchemawith an optionalassetTypeenum field for the filter query.ASSET_TYPE_VALUESandAssetTypeValuetype for downstream consumers.[MODIFY]
server/src/schemas/index.tsASSET_TYPE_VALUESandAssetTypeValue.[MODIFY]
server/src/routes/trades.tsGET /api/v1/tradesreads optionalassetTypefrom validated query params.AND t.asset_type = $Nclause to both the data query and the count query when the filter is present.🏠 Homepage — Live Filter Bar
[ADD]
frontend/app/components/ListingsGrid.tsx"use client"component owning filter state.FilterBarrenders pill buttons: All + one per canonical asset type, usingaria-pressedfor accessibility.useTradeListwhich forwards it as?assetType=to the API.[MODIFY]
frontend/app/page.tsxgetActiveListingsfetch and all inlineTradeCard/EmptyState/AssetBadgecomponents.<ListingsGrid />— keeps the page as a lightweight server component for hero and footer.Verification Results
<select>with MTN, Glo, Airtel, 9mobile, Spectranet × Airtime/DataMTN_AIRTIME,SPECTRANET_DATAz.enum(ASSET_TYPE_VALUES)increateTradeSchema+paginationSchemaFilterBarimports fromassetTypes.ts, passes touseTradeList→ API