feat: item management #46

Merged
addison merged 50 commits from feat/item-management into main 2025-12-27 05:07:19 -05:00
Owner
No description provided.
The RLS policy requires user_id to match the authenticated user. The API
route was not setting user_id in the insert, causing RLS violations.

Now the API fetches the user's profile ID from auth and includes it in
the item insert.
Remove image previews, status badges, and visibility labels. Keep only:
- Item title
- Type (buy/sell)
- Edit and Delete buttons

This is the MVP version. UI refinements will come later per spec.
Use createSupabaseServerClient which properly handles auth context via
cookies and headers, similar to other authenticated pages. This fixes
items not loading on /items/manage.
- Created DeleteItemButton component for client-side delete functionality
- Replaced all inline button HTML with Button component
- Uses variant system (primary, secondary, danger) for consistent styling
- Created ManageItemsPage component that wraps item list with DialogProvider
- DeleteItemButton now uses showConfirmation dialog instead of browser confirm
- Dialog shows proper title, message, and uses danger variant for delete action
Use createSupabaseServerClient which properly handles auth context via
cookies and headers. This fixes 404 errors when trying to edit items.
- Always use createSupabaseServerClient for authenticated Astro pages
- Never create hand-made buttons or form elements - use existing components
- Check for existing patterns before implementing (components, utilities, similar pages)
- Use correct relative import paths
- Always use RPC functions when available instead of direct queries
Create /api/items/[id].ts to handle dynamic routes for DELETE and PATCH.
Astro only routes static files automatically. Move DELETE and PATCH handlers
to the dynamic route file.

Also update ItemForm to use /api/items/{id} for PATCH requests and simplify
payload construction.
React components in Astro templates need a client directive.
Add client:only="react" to the Button component.
DeleteItemButton was making requests without authentication.
Get session and pass Bearer token in Authorization header,
matching the pattern used in ItemForm.
refactor: use database categories, fix item form, improve item display
Some checks failed
CI / Format Check (pull_request) Failing after 1m18s
CI / Unit Tests (pull_request) Failing after 1m16s
CI / Type Check (pull_request) Failing after 1m20s
CI / Lint (pull_request) Failing after 1m22s
CI / E2E Tests (pull_request) Failing after 2m7s
4bccda64dd
- Fetch categories from Supabase instead of hardcoded values
- Add getAllCategoriesServer for Astro pages, getAllCategories for browser
- Fix price validation: only required for sell items, optional for buy (requests)
- Redirect both create and edit to item detail page
- Update item type labels: 'Selling' -> 'Offering', 'Buying' -> 'Request'
- Create stub item detail page at /items/[id]
- Update CategoryBadge and CategoryFilter to handle async categories
- Simplify categories tests to cover synchronous functions only
refactor: convert ManageItemCard to Astro, merge ManageItemsPage into manage page
Some checks failed
CI / Format Check (pull_request) Failing after 1m10s
CI / Unit Tests (pull_request) Failing after 1m8s
CI / Type Check (pull_request) Failing after 1m12s
CI / Lint (pull_request) Failing after 1m16s
CI / E2E Tests (pull_request) Failing after 1m37s
cb4a4e8496
- Convert ManageItemCard from React to Astro (only delete action uses React)
- Merge ManageItemsPage logic directly into /items/manage.astro page
- Render ManageItemCard grid and empty state in Astro template
- Remove React wrapper component, simplify component tree
fix: revert to React ManageItemsPage with DialogProvider for context
Some checks failed
CI / Lint (pull_request) Failing after 1m3s
CI / Type Check (pull_request) Failing after 1m21s
CI / Unit Tests (pull_request) Failing after 1m16s
CI / Format Check (pull_request) Failing after 2m14s
CI / E2E Tests (pull_request) Failing after 57s
f849e4f88c
- Revert ManageItemCard to React component
- Recreate ManageItemsPage as React component wrapping everything in DialogProvider
- Dialog context (useDialog) must be in same React tree as DeleteItemButton
- Fix 'useDialog must be used within DialogProvider' error
fix(search): escape SQL LIKE special characters in search query
Some checks failed
CI / Format Check (pull_request) Failing after 1m15s
CI / Type Check (pull_request) Failing after 1m17s
CI / Unit Tests (pull_request) Failing after 1m13s
CI / Lint (pull_request) Failing after 1m20s
CI / E2E Tests (pull_request) Failing after 1m57s
73846c356c
fix(search): use parameterized RPC function for safe item search
Some checks failed
CI / Unit Tests (pull_request) Failing after 1m8s
CI / Type Check (pull_request) Failing after 1m12s
CI / Format Check (pull_request) Failing after 1m10s
CI / Lint (pull_request) Failing after 1m14s
CI / E2E Tests (pull_request) Failing after 1m20s
934d9b39a4
- Add search_items() RPC function with proper parameter binding
- Replace manual PostgREST query building with RPC call
- Separate image fetching from search
- Add TypeScript types for search results
- Fix form DOM element type errors
- Use onkeyup instead of deprecated onkeypress
fix(validation): add title/description length validation to API routes
Some checks failed
CI / Format Check (pull_request) Failing after 1m12s
CI / Lint (pull_request) Failing after 1m16s
CI / Type Check (pull_request) Failing after 1m15s
CI / Unit Tests (pull_request) Failing after 1m2s
CI / E2E Tests (pull_request) Failing after 1m1s
fccf56edb3
fix(items): clean up storage files on deletion and use event listeners
Some checks failed
CI / Unit Tests (pull_request) Failing after 1m9s
CI / Type Check (pull_request) Failing after 1m12s
CI / Format Check (pull_request) Failing after 1m9s
CI / Lint (pull_request) Failing after 1m13s
CI / E2E Tests (pull_request) Failing after 2m3s
610620103a
- Delete item images from storage before deleting item record
- Extract path from storage URL and remove files via API
- Continue with item deletion if storage cleanup fails
- Replace inline event handlers with addEventListener for proper ESLint detection
fix: address REVIEW.md issues #7-15 for item management
Some checks failed
CI / Lint (pull_request) Failing after 1m15s
CI / Unit Tests (pull_request) Failing after 1m10s
CI / Type Check (pull_request) Failing after 1m13s
CI / Format Check (pull_request) Failing after 1m11s
CI / E2E Tests (pull_request) Failing after 2m6s
c6d05825d8
- Issue #7: Add user-facing error state and loading indicator to DeleteItemButton
- Issue #4: Add database trigger to enforce 5 image limit per item
- Issue #10: Replace createServerClient with createSupabaseServerClient in items.astro
- Issue #8: Extract ItemWithImage type to shared src/lib/types.ts
- Issue #9: Remove unused id prop from ItemCard.astro
- Issue #11: Verified ManageItemCard properly uses id prop
- Issue #12: Improve ItemForm abort controller to properly handle image upload cleanup
- Issue #13: Fix image preview race condition using fileIndex instead of array length
- Issue #14: Remove 'use client' directive from ItemForm.tsx (not needed in Astro)
- Issue #15: Add server-side validation for image URLs in API route
Mark all items as FIXED and provide implementation details for each issue.
Update security summary to reflect completed fixes.
Add implementation summary organized by issue category.
- Update /api/items/images to extract and store relative paths instead of full URLs
- Add getPublicImageUrl() helper to construct public URLs from relative paths
- Update items.astro and v/[vendor_id].astro to convert paths to URLs when rendering
- Allows seed data and API to use relative paths for environment-agnostic storage
- Update getItemImageSignedUrls() to accept and use cookieHeader parameter
- Pass cookieHeader in manage.astro and [id]/edit.astro when generating signed URLs
- Update ManageItemsPage to accept imageUrl directly instead of item_image array
- Remove imageUrl extraction logic from component, now handled server-side
- Remove unused getItemImageUrlForDisplay() function
- Update AGENTS.md with guidance on server-side functions requiring auth context
- Remove debug console.log from index.astro
- Add supabase/snippets/ to .gitignore

Amp-Thread-ID: https://ampcode.com/threads/T-019b5f1e-8284-7261-a286-a8ecaf86bf68
Co-authored-by: Amp <amp@ampcode.com>
refactor: use ItemWithImage type in manage page
Some checks failed
CI / Type Check (pull_request) Failing after 1m13s
CI / Unit Tests (pull_request) Failing after 1m9s
CI / Format Check (pull_request) Failing after 1m11s
CI / Lint (pull_request) Failing after 1m15s
CI / E2E Tests (pull_request) Failing after 2m4s
4ea7e2b93d
- Import ItemWithImage from lib/types instead of defining ItemData
- Use consistent image_url property naming
- Remove unused getItemImageSignedUrl wrapper function
- Simplify ManageItemsPage component prop typing
refactor(categories): unify client pattern and remove unused functions
Some checks failed
CI / Unit Tests (pull_request) Failing after 1m9s
CI / Format Check (pull_request) Failing after 1m11s
CI / Type Check (pull_request) Failing after 1m13s
CI / Lint (pull_request) Failing after 1m15s
CI / E2E Tests (pull_request) Failing after 2m25s
6d90e59544
- Create getAllCategoriesWithClient() to work with any Supabase client instance
- Replace getAllCategoriesServer() with direct calls to getAllCategoriesWithClient(supabase)
- Create isValidCategoryIdWithClient() to reuse getAllCategoriesWithClient()
- Remove getCategoryById, getCategoryName, formatCategoryFilters, and CategoryId type
- Update CategoryBadge to use getAllCategories() with find()
- Fix 'Invalid category' error in POST /api/items by using isValidCategoryIdWithClient()
- Remove categories.test.ts (tested only unused formatCategoryFilters)

This consolidates category validation logic and eliminates duplicate query code across server and client contexts.
fix(api): use isValidCategoryIdWithClient in PATCH /api/items/[id]
Some checks failed
CI / Unit Tests (pull_request) Failing after 1m9s
CI / Lint (pull_request) Failing after 1m15s
CI / Format Check (pull_request) Failing after 1m11s
CI / Type Check (pull_request) Failing after 1m13s
CI / E2E Tests (pull_request) Failing after 1m56s
1b9ea33be1
refactor: clean up
Some checks failed
CI / Type Check (pull_request) Has been cancelled
CI / E2E Tests (pull_request) Has been cancelled
CI / Lint (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Unit Tests (pull_request) Has been cancelled
f8be6a7db2
addison referenced this pull request from a commit 2025-12-27 05:07:19 -05:00
addison deleted branch feat/item-management 2025-12-27 05:07:19 -05: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
kwila/market!46
No description provided.