Skip to content

Commit 37752e9

Browse files
committed
implemented task A14
1 parent 3e6a9d0 commit 37752e9

4 files changed

Lines changed: 457 additions & 115 deletions

File tree

frontend/src/app/dashboard/page.tsx

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,44 @@
22
* Dashboard Page
33
*
44
* Protected dashboard page with modern shadcn/ui components and professional design.
5+
* Integrated with Zustand project store for state management.
56
*/
67

78
"use client";
89

9-
import React, { useState, useEffect } from 'react';
10+
import React, { useEffect } from 'react';
1011
import { useRouter } from 'next/navigation';
1112
import { ProtectedRoute } from '@/components/auth/ProtectedRoute';
1213
import { useAuth } from '@/components/auth/AuthProvider';
1314
import { BentoGrid } from '@/components/dashboard/bento-grid';
1415
import { Button } from '@/components/ui/button';
1516
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
16-
import { Badge } from '@/components/ui/badge';
17-
import { api } from '@/lib/api';
1817
import { FolderIcon, CheckCircleIcon, ClockIcon, AlertCircleIcon, LogOutIcon } from 'lucide-react';
19-
import type { Project } from '../../../../shared/api-contract';
18+
import { useProjects, useProjectActions } from '@/lib/store/project';
2019

2120
function DashboardContent() {
2221
const { user, logout } = useAuth();
2322
const router = useRouter();
24-
const [projects, setProjects] = useState<Project[]>([]);
25-
const [isLoading, setIsLoading] = useState(true);
26-
const [error, setError] = useState<string | null>(null);
23+
const { projects, isLoading, error, total } = useProjects();
24+
const { fetchProjects, clearError } = useProjectActions();
2725

2826
useEffect(() => {
29-
const fetchProjects = async () => {
30-
try {
31-
setIsLoading(true);
32-
setError(null);
33-
const response = await api.projects.getProjects();
34-
35-
if (response.success && response.data) {
36-
setProjects(response.data.items);
37-
} else {
38-
setError(response.error || 'Failed to fetch projects');
39-
}
40-
} catch (err) {
41-
setError('Failed to fetch projects');
42-
console.error('Project fetch error:', err);
43-
} finally {
44-
setIsLoading(false);
45-
}
46-
};
47-
4827
if (user) {
4928
fetchProjects();
5029
}
51-
}, [user]);
30+
}, [user, fetchProjects]);
5231

5332
const handleLogout = async () => {
5433
await logout();
5534
};
5635

5736
const getProjectStats = () => {
58-
const total = projects.length;
5937
const ready = projects.filter(p => p.status === 'ready').length;
6038
const processing = projects.filter(p => p.status === 'processing').length;
6139
return { total, ready, processing };
6240
};
6341

64-
const { total, ready, processing } = getProjectStats();
65-
66-
const fetchProjects = async () => {
67-
try {
68-
setIsLoading(true);
69-
setError(null);
70-
const response = await api.projects.getProjects();
71-
72-
if (response.success && response.data) {
73-
setProjects(response.data.items);
74-
} else {
75-
setError(response.error || 'Failed to fetch projects');
76-
}
77-
} catch (err) {
78-
setError('Failed to fetch projects');
79-
console.error('Project fetch error:', err);
80-
} finally {
81-
setIsLoading(false);
82-
}
83-
};
42+
const { ready, processing } = getProjectStats();
8443

8544
return (
8645
<div className="min-h-screen bg-background">
@@ -178,9 +137,14 @@ function DashboardContent() {
178137
{error && (
179138
<Card className="border-destructive">
180139
<CardContent className="p-4">
181-
<div className="flex items-center space-x-2">
182-
<AlertCircleIcon className="h-4 w-4 text-destructive" />
183-
<p className="text-sm text-destructive">{error}</p>
140+
<div className="flex items-center justify-between">
141+
<div className="flex items-center space-x-2">
142+
<AlertCircleIcon className="h-4 w-4 text-destructive" />
143+
<p className="text-sm text-destructive">{error}</p>
144+
</div>
145+
<Button variant="outline" size="sm" onClick={clearError}>
146+
Dismiss
147+
</Button>
184148
</div>
185149
</CardContent>
186150
</Card>

0 commit comments

Comments
 (0)