mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-05 09:32:01 +00:00
RoleGuard: New component wrapping admin routes — dispatchers navigating to /admin/* by URL now redirect to / instead of seeing error states. Dashboard: Add mine=true filter so dispatchers only see their own proposals and stats, not all users' data. AdminWorkspace: Auto-save dirty changes before approving so edits to refined scope and line items aren't silently discarded. ProposalFormPage: Add onError toast and 300ms debounce on customer search (was firing an API call per keystroke). admin.ts: Stop swallowing errors in getPdf — let them propagate to the mutation's onError handler. Fix AuditEntry.details type to string|null. LoginPage: Fix pre-existing TS error with noUncheckedIndexedAccess.
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import apiClient from './client';
|
|
|
|
export interface DashboardStats {
|
|
pendingCount: number;
|
|
approvedThisWeek: number;
|
|
avgTurnaroundHours: number;
|
|
totalProposals: number;
|
|
}
|
|
|
|
export interface UpdateProposalRequest {
|
|
refinedScope?: string;
|
|
notes?: string;
|
|
assignedAdminId?: string;
|
|
}
|
|
|
|
export interface AuditEntry {
|
|
id: string;
|
|
proposalId: string | null;
|
|
userId: string;
|
|
userName: string;
|
|
action: string;
|
|
details: string | null;
|
|
timestamp: string;
|
|
ipAddress: string | null;
|
|
}
|
|
|
|
export const adminApi = {
|
|
getDashboard: async (): Promise<DashboardStats> => {
|
|
const res = await apiClient.get('/admin/dashboard');
|
|
return res.data;
|
|
},
|
|
|
|
updateProposal: async (id: string, data: UpdateProposalRequest): Promise<void> => {
|
|
await apiClient.put(`/proposals/${id}`, data);
|
|
},
|
|
|
|
approveProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/approve`);
|
|
},
|
|
|
|
sendProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/send`);
|
|
},
|
|
|
|
reviseProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/revise`);
|
|
},
|
|
|
|
getHistory: async (id: string): Promise<unknown[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/history`);
|
|
return res.data;
|
|
},
|
|
|
|
getAudit: async (id: string): Promise<AuditEntry[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/audit`);
|
|
return res.data;
|
|
},
|
|
|
|
generateSuggestions: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/generate-suggestions`);
|
|
},
|
|
|
|
getSimilar: async (id: string): Promise<unknown[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/similar`);
|
|
return res.data;
|
|
},
|
|
|
|
getPdf: async (id: string): Promise<{ downloadUrl: string; expiresAt: string } | null> => {
|
|
const res = await apiClient.get(`/proposals/${id}/pdf`);
|
|
if (res.status === 202) return null;
|
|
return res.data;
|
|
},
|
|
};
|