690402:2240 fix dashboard
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
// File: lib/api/dashboard.ts
|
||||
// Change Log:
|
||||
// - Fixed TypeScript type error in mock data (id: number -> id: string)
|
||||
// - Updated PendingTask mock data to match interface
|
||||
|
||||
import { DashboardStats, ActivityLog, PendingTask } from '@/types/dashboard';
|
||||
|
||||
export const dashboardApi = {
|
||||
@@ -17,7 +22,7 @@ export const dashboardApi = {
|
||||
await new Promise((resolve) => setTimeout(resolve, 600));
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
id: 'activity-1',
|
||||
user: { name: 'John Doe', initials: 'JD' },
|
||||
action: 'Created RFA',
|
||||
description: 'RFA-001: Concrete Pouring Request',
|
||||
@@ -25,7 +30,7 @@ export const dashboardApi = {
|
||||
targetUrl: '/rfas/1',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
id: 'activity-2',
|
||||
user: { name: 'Jane Smith', initials: 'JS' },
|
||||
action: 'Approved Correspondence',
|
||||
description: 'COR-005: Site Safety Report',
|
||||
@@ -33,7 +38,7 @@ export const dashboardApi = {
|
||||
targetUrl: '/correspondences/5',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
id: 'activity-3',
|
||||
user: { name: 'Mike Johnson', initials: 'MJ' },
|
||||
action: 'Uploaded Drawing',
|
||||
description: 'A-101: Ground Floor Plan Rev B',
|
||||
@@ -47,7 +52,14 @@ export const dashboardApi = {
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
publicId: 'task-1',
|
||||
workflowCode: 'RFA_WORKFLOW',
|
||||
currentState: 'REVIEWING',
|
||||
entityType: 'RFA',
|
||||
entityId: 'rfa-001-uuid',
|
||||
documentNumber: 'RFA-002',
|
||||
subject: 'Review RFA-002',
|
||||
assignedAt: new Date().toISOString(),
|
||||
title: 'Review RFA-002',
|
||||
description: 'Approval required for steel reinforcement',
|
||||
daysOverdue: 2,
|
||||
@@ -55,7 +67,14 @@ export const dashboardApi = {
|
||||
priority: 'HIGH',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
publicId: 'task-2',
|
||||
workflowCode: 'CORR_WORKFLOW',
|
||||
currentState: 'PENDING_APPROVAL',
|
||||
entityType: 'Correspondence',
|
||||
entityId: 'corr-010-uuid',
|
||||
documentNumber: 'COR-101',
|
||||
subject: 'Approve Monthly Report',
|
||||
assignedAt: new Date().toISOString(),
|
||||
title: 'Approve Monthly Report',
|
||||
description: 'January 2025 Progress Report',
|
||||
daysOverdue: 0,
|
||||
|
||||
@@ -45,11 +45,11 @@ export const circulationService = {
|
||||
},
|
||||
|
||||
/**
|
||||
* ดึงรายการใบเวียนของ correspondence (by correspondence UUID)
|
||||
* ดึงรายการใบเวียนของ correspondence (by correspondence publicId)
|
||||
*/
|
||||
getByCorrespondenceUuid: async (correspondenceUuid: string) => {
|
||||
getByCorrespondenceUuid: async (correspondencePublicId: string) => {
|
||||
const response = await apiClient.get('/circulations', {
|
||||
params: { correspondenceUuid, limit: 50 },
|
||||
params: { correspondencePublicId, limit: 50 },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
@@ -27,14 +27,16 @@ interface RawPendingTask {
|
||||
}
|
||||
|
||||
export const dashboardService = {
|
||||
getStats: async (): Promise<DashboardStats> => {
|
||||
const response = await apiClient.get('/dashboard/stats');
|
||||
getStats: async (projectId?: string | null): Promise<DashboardStats> => {
|
||||
const params = projectId ? { projectId } : undefined;
|
||||
const response = await apiClient.get('/dashboard/stats', { params });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getRecentActivity: async (): Promise<ActivityLog[]> => {
|
||||
getRecentActivity: async (projectId?: string | null): Promise<ActivityLog[]> => {
|
||||
try {
|
||||
const response = await apiClient.get('/dashboard/activity');
|
||||
const params = projectId ? { projectId } : undefined;
|
||||
const response = await apiClient.get('/dashboard/activity', { params });
|
||||
if (Array.isArray(response.data)) {
|
||||
return (response.data as RawActivityLog[]).map((log) => {
|
||||
const firstName = log.user?.firstName || '';
|
||||
@@ -59,9 +61,10 @@ export const dashboardService = {
|
||||
}
|
||||
},
|
||||
|
||||
getPendingTasks: async (): Promise<PendingTask[]> => {
|
||||
getPendingTasks: async (projectId?: string | null): Promise<PendingTask[]> => {
|
||||
try {
|
||||
const response = await apiClient.get('/dashboard/pending');
|
||||
const params = projectId ? { projectId } : undefined;
|
||||
const response = await apiClient.get('/dashboard/pending', { params });
|
||||
const rawTasks = (response.data?.data || (Array.isArray(response.data) ? response.data : [])) as RawPendingTask[];
|
||||
|
||||
return rawTasks.map((task) => {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// File: lib/stores/project-store.ts
|
||||
// Change Log:
|
||||
// - Created store for managing currently selected project context
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
interface ProjectState {
|
||||
selectedProjectId: string | null;
|
||||
setSelectedProjectId: (projectId: string | null) => void;
|
||||
}
|
||||
|
||||
export const useProjectStore = create<ProjectState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
selectedProjectId: null,
|
||||
setSelectedProjectId: (projectId) => set({ selectedProjectId: projectId }),
|
||||
}),
|
||||
{
|
||||
name: 'project-storage',
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user