Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions frontend/app/api/dashboard/activities/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { NextResponse } from 'next/server';
import type { Activity } from '@/types/dashboard';

function parseRange(range: string | null) {
const r = (range || '30d').toLowerCase();
if (['7d', '30d', '90d', '6m', '12m'].includes(r)) return r;
return '30d';
}

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
parseRange(searchParams.get('range'));

const actions: Activity['actionType'][] = ['created', 'assigned', 'transferred', 'retired'];
const users = ['Alice Dev', 'Bob Ops', 'Chioma Admin', 'Jane IT'];
const assets = ['MacBook Pro M3', 'Dell XPS 15', 'iPhone 15', 'Lenovo ThinkPad', 'Office Chair'];

const data: Activity[] = Array.from({ length: 10 }).map((_, i) => {
const actionType = actions[i % actions.length];
const assetName = assets[i % assets.length];
const assetId = `asset-${(i % 5) + 1}`;
return {
id: `act-${i}`,
assetId,
assetName,
actionType,
user: users[i % users.length],
timestamp: new Date(Date.now() - i * 36e5).toISOString(),
};
});

return NextResponse.json(data);
}

51 changes: 51 additions & 0 deletions frontend/app/api/dashboard/charts/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { NextResponse } from 'next/server';
import type { ChartData } from '@/types/dashboard';

function parseRange(range: string | null) {
const r = (range || '30d').toLowerCase();
if (['7d', '30d', '90d', '6m', '12m'].includes(r)) return r;
return '30d';
}

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const range = parseRange(searchParams.get('range'));

// In production: compute based on real assets filtered by `range`.
const reg =
range === '7d'
? [8, 12, 10, 14, 16, 18]
: range === '90d'
? [26, 34, 42, 40, 60, 72]
: range === '6m'
? [30, 45, 60, 50, 80, 95]
: range === '12m'
? [34, 52, 70, 66, 92, 120]
: [24, 32, 48, 44, 68, 84];

const data: ChartData = {
categoryData: [
{ name: 'Hardware', value: 400, color: '#3b82f6' },
{ name: 'Software', value: 300, color: '#10b981' },
{ name: 'Furniture', value: 300, color: '#f59e0b' },
{ name: 'Vehicles', value: 200, color: '#ef4444' },
],
departmentData: [
{ name: 'Eng', assets: 120 },
{ name: 'HR', assets: 50 },
{ name: 'Sales', assets: 80 },
{ name: 'Ops', assets: 95 },
],
registrationData: [
{ date: 'Jan', count: reg[0] },
{ date: 'Feb', count: reg[1] },
{ date: 'Mar', count: reg[2] },
{ date: 'Apr', count: reg[3] },
{ date: 'May', count: reg[4] },
{ date: 'Jun', count: reg[5] },
],
};

return NextResponse.json(data);
}

48 changes: 48 additions & 0 deletions frontend/app/api/dashboard/stats/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { NextResponse } from 'next/server';
import type { DashboardStatsResponse } from '@/types/dashboard';

function parseRange(range: string | null) {
// accepted: 7d, 30d, 90d, 6m, 12m
const r = (range || '30d').toLowerCase();
if (['7d', '30d', '90d', '6m', '12m'].includes(r)) return r;
return '30d';
}

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const range = parseRange(searchParams.get('range'));

// In production: fetch from your backend/service using `range`.
// For now: deterministic mock values that can vary slightly by range.
const multiplier =
range === '7d' ? 0.8 : range === '90d' ? 1.15 : range === '6m' ? 1.25 : range === '12m' ? 1.4 : 1;

const totalAssets = Math.round(12450 * multiplier);
const active = Math.round(8234 * multiplier);
const assigned = Math.round(3120 * multiplier);
const maintenance = Math.round(420 * multiplier);
const retired = Math.max(0, totalAssets - active - assigned - maintenance);

const warrantyExpiring = Math.round(18 * multiplier);
const maintenanceDue = Math.round(27 * multiplier);

const data: DashboardStatsResponse = {
cards: [
{ label: 'Total Assets', value: totalAssets, trend: 12, trendDirection: 'up', icon: 'asset' },
{ label: 'Active Assets', value: active.toLocaleString(), trend: 5, trendDirection: 'up', icon: 'status' },
{ label: 'Total Value', value: '$4.2M', trend: 2.1, trendDirection: 'up', icon: 'value' },
{
label: 'Attention Needed',
value: warrantyExpiring + maintenanceDue,
trend: 15,
trendDirection: 'down',
icon: 'alert',
},
],
statusBreakdown: { active, assigned, maintenance, retired },
attentionBreakdown: { warrantyExpiring, maintenanceDue },
};

return NextResponse.json(data);
}

Loading
Loading