refactor(dashboard): consolidate guided actions into TasksSection SSOT

- Remove duplicate guidedSuggestions from DashboardJourney (~130 lines)
- DashboardJourney now delegates to TasksSection as thin wrapper
- Remove unused props and memoized variables from dashboard page
- TasksSection is now SSOT for all recommendations (useRecommendations hook)

DRY violation fixed: recommendations were previously defined in both
DashboardJourney (guidedSuggestions) and TasksSection (TASK_DEFINITIONS).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.5 committed 2026-01-28 18:58:48 +01:00
1 parent 3a784b5052
commit c94abb233b
2 files changed
+15 -177

No files matched your search

+3 -31
View File
@@ -239,27 +239,8 @@ export default function DashboardPage() {
[safeProjects]
);
// Profile completion
const profileCompletion = useMemo(() => {
const hasUsername = !!profile?.username;
const hasBio = !!profile?.bio;
const hasBitcoinAddress = !!profile?.bitcoin_address;
const profileFields = [hasUsername, hasBio, hasBitcoinAddress];
return Math.round((profileFields.filter(Boolean).length / profileFields.length) * 100);
}, [profile?.username, profile?.bio, profile?.bitcoin_address]);
const hasBitcoinAddress = useMemo(() => !!profile?.bitcoin_address, [profile?.bitcoin_address]);
// Derived state (profile completion now handled by TasksSection SSOT)
const hasProjects = useMemo(() => safeProjects.length > 0, [safeProjects]);
const hasAnyDraft = useMemo(() => safeDrafts.length > 0, [safeDrafts]);
const hasTimelineActivity = useMemo(() => {
const feed = timelineFeed as unknown as {
events?: unknown[];
items?: unknown[];
data?: unknown[];
};
return Boolean(feed?.events?.length || feed?.items?.length || feed?.data?.length);
}, [timelineFeed]);
// Loading states
if (!hydrated || localLoading) {
@@ -319,17 +300,8 @@ export default function DashboardPage() {
/>
)}
{/* Getting Started Section (only if incomplete) */}
{(profileCompletion < 100 || !hasBitcoinAddress || !hasProjects || hasAnyDraft) && (
<DashboardJourney
profileCompletion={profileCompletion}
hasBitcoinAddress={hasBitcoinAddress}
hasProjects={hasProjects}
hasAnyDraft={hasAnyDraft}
totalDrafts={totalDrafts}
hasTimelineActivity={hasTimelineActivity}
/>
)}
{/* Recommended Next Steps - TasksSection handles its own visibility */}
<DashboardJourney />
{/* Primary Content: Economic Activity */}
<div className="space-y-4 sm:space-y-6">
@@ -1,155 +1,21 @@
'use client';
import { useMemo } from 'react';
import Link from 'next/link';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/Card';
import { Wallet, Plus, Target, MessageCircle, Eye } from 'lucide-react';
import { ENTITY_REGISTRY } from '@/config/entity-registry';
import TasksSection from '@/components/dashboard/TasksSection';
interface GuidedSuggestion {
title: string;
description: string;
href: string;
icon: React.ReactNode;
priority: number;
reason: string;
}
interface DashboardJourneyProps {
profileCompletion: number;
hasBitcoinAddress: boolean;
hasProjects: boolean;
hasAnyDraft: boolean;
totalDrafts: number;
hasTimelineActivity: boolean;
}
/**
* DashboardJourney - Profile completion and guided suggestions
* Uses ENTITY_REGISTRY for entity-related routes
* DashboardJourney - Recommended next steps for users
*
* DRY: All task/recommendation logic is in TasksSection (SSOT: useRecommendations hook)
* This component is a thin wrapper that can be extended for journey-specific UI if needed.
*
* TasksSection handles:
* - Profile completion tracking
* - Task recommendations
* - Celebration state when complete
* - Loading/error states
*/
export function DashboardJourney({
profileCompletion,
hasBitcoinAddress,
hasProjects,
hasAnyDraft,
totalDrafts,
hasTimelineActivity,
}: DashboardJourneyProps) {
// PRIORITIZED guided suggestions - most important actions first
const guidedSuggestions = useMemo(() => {
const suggestions: GuidedSuggestion[] = [];
// Priority 1: Bitcoin address is critical for receiving funds
if (!hasBitcoinAddress) {
suggestions.push({
title: 'Add your Bitcoin address',
description: 'Required to receive funds from supporters.',
href: ENTITY_REGISTRY.wallet.basePath,
icon: <Wallet className="w-4 h-4 text-orange-600" />,
priority: 1,
reason: 'unlock-payments',
});
}
// Priority 2: First project is the main value prop
if (!hasProjects) {
suggestions.push({
title: 'Create your first project',
description: 'Launch a Bitcoin crowdfunding campaign in minutes.',
href: ENTITY_REGISTRY.project.createPath,
icon: <Plus className="w-4 h-4 text-blue-600" />,
priority: 2,
reason: 'core-feature',
});
}
// Priority 3: Complete drafts (they're already started)
if (hasAnyDraft) {
suggestions.push({
title: 'Finish your draft',
description: `Complete ${totalDrafts} pending project${totalDrafts > 1 ? 's' : ''}.`,
href: ENTITY_REGISTRY.project.basePath,
icon: <Target className="w-4 h-4 text-emerald-600" />,
priority: 3,
reason: 'continue-work',
});
}
// Priority 4: Engage with community
if (!hasTimelineActivity) {
suggestions.push({
title: 'Post an update',
description: 'Share with the community and build your audience.',
href: '/timeline',
icon: <MessageCircle className="w-4 h-4 text-indigo-600" />,
priority: 4,
reason: 'community',
});
}
// Priority 5: Explore what others are doing
if (hasProjects && hasBitcoinAddress) {
suggestions.push({
title: 'Discover projects',
description: 'See what others are building and get inspired.',
href: '/discover',
icon: <Eye className="w-4 h-4 text-purple-600" />,
priority: 5,
reason: 'explore',
});
}
// Sort by priority and return top 4
return suggestions.sort((a, b) => a.priority - b.priority).slice(0, 4);
}, [hasAnyDraft, hasBitcoinAddress, hasTimelineActivity, hasProjects, totalDrafts]);
return (
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
<Card className="lg:col-span-2">
<CardHeader>
<CardTitle>Your OrangeCat journey</CardTitle>
<CardDescription>Stay on track with clear next steps.</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div>
<div className="flex items-center justify-between mb-2">
<span className="text-sm text-gray-600">Profile completion</span>
<span className="text-sm font-semibold text-gray-900">{profileCompletion}%</span>
</div>
<div className="h-2 w-full rounded-full bg-gray-100">
<div
className="h-2 rounded-full bg-gradient-to-r from-orange-500 to-tiffany-500 transition-all"
style={{ width: `${profileCompletion}%` }}
/>
</div>
<p className="text-xs text-gray-600 mt-2">
Complete your profile to build trust and unlock suggestions tailored to you.
</p>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 gap-3">
{guidedSuggestions.map(suggestion => (
<Link key={suggestion.title} href={suggestion.href}>
<div className="flex items-start gap-3 rounded-lg border border-gray-200 bg-white p-4 hover:border-orange-200 hover:shadow-sm transition-colors">
<div className="mt-1">{suggestion.icon}</div>
<div>
<h3 className="font-semibold text-gray-900">{suggestion.title}</h3>
<p className="text-sm text-gray-600 leading-tight">{suggestion.description}</p>
</div>
</div>
</Link>
))}
</div>
</CardContent>
</Card>
<div className="lg:col-span-1">
<TasksSection />
</div>
</div>
);
export function DashboardJourney() {
return <TasksSection showQuestions={true} maxTasks={5} />;
}
export default DashboardJourney;