3.3 KiB
DynamicSidebar Refactor - DRY & Consistent UX
Created: 2025-11-24
Last Modified: 2025-12-05
Last Modified Summary: Fixed asset guidance JSX crash and aligned security wrapper context for asset endpoints
Problem Identified
Initially, I created a duplicate component (FieldGuidanceSidebar) when we already had DynamicSidebar for projects. This violated:
- ❌ DRY principle (Don't Repeat Yourself)
- ❌ Single source of truth
- ❌ Consistent UX (users should see the same familiar interface)
Solution: Refactor Existing Component
Instead of creating a new component, we refactored the existing DynamicSidebar to accept content as props.
What Changed
2025-12-05
- Converted
asset-guidanceto useReact.createElement(no JSX in.tsfiles) to stop Next.js SWC parse errors that blocked/assetsand/assets/create. - Passed Supabase user context into
withSecurityfor asset-related APIs to return clean 401/429 responses instead of 500s when unauthenticated or rate-limited.
- Made
DynamicSidebargeneric - AcceptsguidanceContentanddefaultContentas props - Extracted project content - Moved to
lib/project-guidance.ts - Profile content - Already in
lib/profile-guidance.ts - Wallet content - Added
lib/wallet-guidance.tsfor wallet flows - Deleted duplicates - Removed
FieldGuidanceSidebarandProfileGuidanceSidebar
Architecture Now
DynamicSidebar (single component)
├─> Used by projects (with projectGuidanceContent)
├─> Used by profiles (with profileGuidanceContent)
└─> Used by wallets (with walletGuidanceContent)
Same UI/UX, different content - exactly what we wanted!
Files Changed
Modified
src/components/create/DynamicSidebar.tsx- Made generic, accepts content as propssrc/app/projects/create/page.tsx- Passes project content to DynamicSidebarsrc/app/(authenticated)/dashboard/info/page.tsx- Passes profile content to DynamicSidebarsrc/components/wizard/ProjectWizard.tsx- Updated type importssrc/lib/profile-guidance.ts- Updated import to use shared types
Created
src/lib/project-guidance.ts- Extracted project guidance content
Deleted
src/components/ui/FieldGuidanceSidebar.tsx- Duplicate, removedsrc/components/profile/ProfileGuidanceSidebar.tsx- Duplicate, removed
Benefits
✅ DRY - One component, not two
✅ Consistent UX - Same familiar interface for projects and profiles
✅ Maintainable - Fix bugs once, works everywhere
✅ Type-safe - TypeScript generics ensure type safety
✅ No breaking changes - Projects still work exactly the same
Code Quality Principles Followed
- DRY (Don't Repeat Yourself) - Single component for both use cases
- Separation of Concerns - UI (component) vs Content (config files)
- Single Source of Truth - One DynamicSidebar component
- Consistent UX - Same interface, different content
- No Duplicates - Removed duplicate components
- No Conflicts - Clean refactor, no breaking changes
Result
- ✅ Build succeeds
- ✅ No linter errors
- ✅ Same familiar UI/UX for both projects and profiles
- ✅ Less code to maintain
- ✅ Easier to extend in the future
This is the correct approach - refactor existing code rather than creating duplicates.