FileModal Enhancement - Implementation Summary
Overview
Successfully refactored and enhanced the media selection modal with comprehensive filtering capabilities and optimized performance.
Changes Made
1. Component Renaming ✅
Files Updated:
/src/admin/routes/inventory/[id]/raw-materials/create/media/page.tsx/src/admin/components/forms/raw-material/raw-material-form.tsx/src/admin/components/social-posts/create-social-post-component.tsx
Changes:
- Renamed
RawMaterialMediaModal→FileModal - Renamed
RawMaterialMediaModalProps→FileModalProps - Updated all imports and usages across 3 files
2. New API Routes ✅
Created lightweight endpoints for filter dropdowns:
GET /admin/medias/folders
- Returns all folders with: id, name, path, level, parent_folder_id
- Limit: 1000 folders (sufficient for dropdown)
- Uses
listFolderWorkflow
GET /admin/medias/albums
- Returns all albums with: id, name, type, slug
- Limit: 1000 albums (sufficient for dropdown)
- Uses
listAlbumWorkflow
3. New Hooks ✅
Created /src/admin/hooks/api/media.ts with:
useMediaFiles(query)
- Infinite scroll pagination
- Supports filters:
folder_id: Filter by folderalbum_id: Filter by albumfile_type: Filter by type (image, video, etc.)search: Search by filenamecreated_after: Date range startcreated_before: Date range endlimit: Items per page (default: 40)
useFolders()
- Fetches all folders for dropdown
- Cached with React Query
useAlbums()
- Fetches all albums for dropdown
- Cached with React Query
useFolderDetail(folderId)
- Fetches folder details with media files
- Enabled only when folderId is provided
4. Enhanced MediaUpload Component ✅
New Features:
Filter UI
- Folder Dropdown: Select from all available folders
- Album Dropdown: Select from all available albums with type labels
- Search Input: Search files by name
- Date Range: Filter by creation date (From/To)
- Clear Filters: Button showing active filter count
Folder Navigation
- Click folders to browse their contents
- Breadcrumb showing current location
- "Root" button to return to top level
- Subfolders displayed as clickable cards with folder icon
Visual Improvements
- Folders shown with dashed border and FolderOpen icon
- Files shown with thumbnails (using Cloudflare transforms)
- Empty state with Photo icon and helpful message
- Selected files highlighted with checkmark overlay