fix: Documents page - remove category field references, align with backend schema
- Removed category field usage (doesn't exist in Prisma schema) - Changed grouping from category to type - Removed GUIDE type (not in backend) - Updated filter dropdown with correct types
This commit is contained in:
parent
bd9b485d99
commit
b946955f49
2 changed files with 10 additions and 24 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import api from './api';
|
||||
|
||||
export type DocumentType = 'SOP' | 'POLICY' | 'FORM' | 'CHECKLIST' | 'GUIDE' | 'TRAINING' | 'OTHER';
|
||||
export type DocumentType = 'SOP' | 'POLICY' | 'FORM' | 'CHECKLIST' | 'TRAINING' | 'OTHER';
|
||||
export type DocumentStatus = 'DRAFT' | 'PENDING_APPROVAL' | 'APPROVED' | 'ARCHIVED';
|
||||
|
||||
export interface Document {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|||
import {
|
||||
FileText, Search, Plus, Clock, User, Check, X,
|
||||
AlertCircle, Eye, Edit, FolderOpen, Book,
|
||||
ClipboardList, FileCheck, HelpCircle, History, Download, Loader2,
|
||||
ClipboardList, FileCheck, History, Download, Loader2,
|
||||
LucideIcon
|
||||
} from 'lucide-react';
|
||||
import { documentsApi, Document, DocumentType, DocumentStatus, DocumentVersion } from '../lib/documentsApi';
|
||||
|
|
@ -13,7 +13,6 @@ const TYPE_CONFIG: Record<DocumentType, { icon: LucideIcon; badge: string; label
|
|||
POLICY: { icon: FileCheck, badge: 'badge-accent', label: 'Policy' },
|
||||
FORM: { icon: ClipboardList, badge: 'badge-accent', label: 'Form' },
|
||||
CHECKLIST: { icon: Check, badge: 'badge-success', label: 'Checklist' },
|
||||
GUIDE: { icon: HelpCircle, badge: 'badge-warning', label: 'Guide' },
|
||||
TRAINING: { icon: Book, badge: 'badge-success', label: 'Training' },
|
||||
OTHER: { icon: FileText, badge: 'badge', label: 'Document' }
|
||||
};
|
||||
|
|
@ -32,7 +31,6 @@ export default function DocumentsPage() {
|
|||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [filterType, setFilterType] = useState<DocumentType | ''>('');
|
||||
const [filterStatus, setFilterStatus] = useState<DocumentStatus | ''>('');
|
||||
const [filterCategory, setFilterCategory] = useState('');
|
||||
const [selectedDoc, setSelectedDoc] = useState<Document | null>(null);
|
||||
const [versions, setVersions] = useState<DocumentVersion[]>([]);
|
||||
const [showVersions, setShowVersions] = useState(false);
|
||||
|
|
@ -41,7 +39,7 @@ export default function DocumentsPage() {
|
|||
useEffect(() => {
|
||||
loadDocuments();
|
||||
loadPendingAcks();
|
||||
}, [filterType, filterStatus, filterCategory]);
|
||||
}, [filterType, filterStatus]);
|
||||
|
||||
async function loadDocuments() {
|
||||
setLoading(true);
|
||||
|
|
@ -49,7 +47,6 @@ export default function DocumentsPage() {
|
|||
const docs = await documentsApi.getDocuments({
|
||||
type: filterType || undefined,
|
||||
status: filterStatus || undefined,
|
||||
category: filterCategory || undefined,
|
||||
search: searchTerm || undefined
|
||||
});
|
||||
setDocuments(docs);
|
||||
|
|
@ -92,8 +89,7 @@ export default function DocumentsPage() {
|
|||
}
|
||||
}
|
||||
|
||||
const categories = [...new Set(documents.map(d => d.category).filter(Boolean))];
|
||||
|
||||
// Filter documents by search term
|
||||
const filteredDocs = documents.filter(doc => {
|
||||
if (searchTerm && !doc.title.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||
return false;
|
||||
|
|
@ -101,10 +97,11 @@ export default function DocumentsPage() {
|
|||
return true;
|
||||
});
|
||||
|
||||
// Group by type for display
|
||||
const groupedDocs = filteredDocs.reduce((acc, doc) => {
|
||||
const cat = doc.category || 'Uncategorized';
|
||||
if (!acc[cat]) acc[cat] = [];
|
||||
acc[cat].push(doc);
|
||||
const typeLabel = TYPE_CONFIG[doc.type]?.label || doc.type;
|
||||
if (!acc[typeLabel]) acc[typeLabel] = [];
|
||||
acc[typeLabel].push(doc);
|
||||
return acc;
|
||||
}, {} as Record<string, Document[]>);
|
||||
|
||||
|
|
@ -162,9 +159,10 @@ export default function DocumentsPage() {
|
|||
<option value="">All Types</option>
|
||||
<option value="SOP">SOPs</option>
|
||||
<option value="POLICY">Policies</option>
|
||||
<option value="TRAINING">Training</option>
|
||||
<option value="FORM">Forms</option>
|
||||
<option value="CHECKLIST">Checklists</option>
|
||||
<option value="GUIDE">Guides</option>
|
||||
<option value="OTHER">Other</option>
|
||||
</select>
|
||||
<select
|
||||
value={filterStatus}
|
||||
|
|
@ -177,18 +175,6 @@ export default function DocumentsPage() {
|
|||
<option value="DRAFT">Draft</option>
|
||||
<option value="ARCHIVED">Archived</option>
|
||||
</select>
|
||||
{categories.length > 0 && (
|
||||
<select
|
||||
value={filterCategory}
|
||||
onChange={(e) => setFilterCategory(e.target.value)}
|
||||
className="input"
|
||||
>
|
||||
<option value="">All Categories</option>
|
||||
{categories.map(cat => (
|
||||
<option key={cat} value={cat}>{cat}</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Documents Grid */}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue