Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
feat: add test data for sales graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ArshiLamba committed Aug 8, 2024
1 parent 8551f22 commit 51e4bb3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 126 deletions.
130 changes: 18 additions & 112 deletions client/src/pages/user/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,116 +1,22 @@
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import httpClient from '@utils/http';
import { getAuthCookie } from '@utils/jwt'; // Assuming you have an auth utility to get the token

const Dashboard = () => {
const navigate = useNavigate();
const [dashboardData, setDashboardData] = useState<{
id: number;
title: string;
description?: string;
isActive: boolean;
createdAt: string;
updatedAt: string;
} | null>(null);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
const fetchDashboardData = async () => {
const token = getAuthCookie('access'); // Pass 'access' tokenType here
if (!token) {
setError('No authentication token found');
setLoading(false);
return;
}

try {
const response = await httpClient.get<{
status: number;
data: {
id: number;
title: string;
description?: string;
isActive: boolean;
createdAt: string;
updatedAt: string;
};
}>({
uri: '/dashboard', // Ensure this is the correct endpoint
options: {
headers: {
Authorization: `Bearer ${token}`, // Include the token in the request
},
},
});

const { data } = response;

if (data) {
setDashboardData(data);
} else {
setError('Invalid data received from the server');
}
} catch (err) {
console.error('Error fetching dashboard data:', err);
setError('Error fetching dashboard data');
} finally {
setLoading(false);
}
};

fetchDashboardData();
}, []);

const navigateToPage = (path: string) => {
navigate(path);
};

if (loading) return <p>Loading...</p>;
if (error) return <p className="text-red-500">{error}</p>;

// src/pages/Dashboard.tsx
import Graph from '@components/ui/graph';
import { PageComponent } from '@pages/route-map';

// Sample sales data
const salesData = [
{ date: '2023-01-01', amount: 300 },
{ date: '2023-02-01', amount: 200 },
{ date: '2023-03-01', amount: 150 },
{ date: '2023-04-01', amount: 300 },
{ date: '2023-05-01', amount: 250 },
{ date: '2023-06-01', amount: 400 },
];

const Dashboard: PageComponent = () => {
return (
<div>
<h1 className="mb-6 text-3xl font-bold">Dashboard</h1>
<div className="space-y-8">
<div>
<h2 className="mb-2 text-xl font-semibold">Overview</h2>
<p className="text-gray-700">
{dashboardData?.description || 'No overview information available.'}
</p>
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">Recent Activities</h2>
<ul>
<li>Activity 1</li>
<li>Activity 2</li>
<li>Activity 3</li>
</ul>
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">Statistics</h2>
<p className="text-gray-700">Some statistics here...</p>
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">Settings</h2>
<button onClick={() => navigateToPage('/settings')}>
Go to Settings
</button>
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">User Management</h2>
<button onClick={() => navigateToPage('/user-management')}>
Manage Users
</button>
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">Reports</h2>
<button onClick={() => navigateToPage('/reports')}>
View Reports
</button>
</div>
</div>
<div className="container">
<h1>Dashboard</h1>
<Graph salesData={salesData} />
</div>
);
};
Expand Down
19 changes: 5 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51e4bb3

Please sign in to comment.