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';
|
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 type DocumentStatus = 'DRAFT' | 'PENDING_APPROVAL' | 'APPROVED' | 'ARCHIVED';
|
||||||
|
|
||||||
export interface Document {
|
export interface Document {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
FileText, Search, Plus, Clock, User, Check, X,
|
FileText, Search, Plus, Clock, User, Check, X,
|
||||||
AlertCircle, Eye, Edit, FolderOpen, Book,
|
AlertCircle, Eye, Edit, FolderOpen, Book,
|
||||||
ClipboardList, FileCheck, HelpCircle, History, Download, Loader2,
|
ClipboardList, FileCheck, History, Download, Loader2,
|
||||||
LucideIcon
|
LucideIcon
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { documentsApi, Document, DocumentType, DocumentStatus, DocumentVersion } from '../lib/documentsApi';
|
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' },
|
POLICY: { icon: FileCheck, badge: 'badge-accent', label: 'Policy' },
|
||||||
FORM: { icon: ClipboardList, badge: 'badge-accent', label: 'Form' },
|
FORM: { icon: ClipboardList, badge: 'badge-accent', label: 'Form' },
|
||||||
CHECKLIST: { icon: Check, badge: 'badge-success', label: 'Checklist' },
|
CHECKLIST: { icon: Check, badge: 'badge-success', label: 'Checklist' },
|
||||||
GUIDE: { icon: HelpCircle, badge: 'badge-warning', label: 'Guide' },
|
|
||||||
TRAINING: { icon: Book, badge: 'badge-success', label: 'Training' },
|
TRAINING: { icon: Book, badge: 'badge-success', label: 'Training' },
|
||||||
OTHER: { icon: FileText, badge: 'badge', label: 'Document' }
|
OTHER: { icon: FileText, badge: 'badge', label: 'Document' }
|
||||||
};
|
};
|
||||||
|
|
@ -32,7 +31,6 @@ export default function DocumentsPage() {
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [filterType, setFilterType] = useState<DocumentType | ''>('');
|
const [filterType, setFilterType] = useState<DocumentType | ''>('');
|
||||||
const [filterStatus, setFilterStatus] = useState<DocumentStatus | ''>('');
|
const [filterStatus, setFilterStatus] = useState<DocumentStatus | ''>('');
|
||||||
const [filterCategory, setFilterCategory] = useState('');
|
|
||||||
const [selectedDoc, setSelectedDoc] = useState<Document | null>(null);
|
const [selectedDoc, setSelectedDoc] = useState<Document | null>(null);
|
||||||
const [versions, setVersions] = useState<DocumentVersion[]>([]);
|
const [versions, setVersions] = useState<DocumentVersion[]>([]);
|
||||||
const [showVersions, setShowVersions] = useState(false);
|
const [showVersions, setShowVersions] = useState(false);
|
||||||
|
|
@ -41,7 +39,7 @@ export default function DocumentsPage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDocuments();
|
loadDocuments();
|
||||||
loadPendingAcks();
|
loadPendingAcks();
|
||||||
}, [filterType, filterStatus, filterCategory]);
|
}, [filterType, filterStatus]);
|
||||||
|
|
||||||
async function loadDocuments() {
|
async function loadDocuments() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
@ -49,7 +47,6 @@ export default function DocumentsPage() {
|
||||||
const docs = await documentsApi.getDocuments({
|
const docs = await documentsApi.getDocuments({
|
||||||
type: filterType || undefined,
|
type: filterType || undefined,
|
||||||
status: filterStatus || undefined,
|
status: filterStatus || undefined,
|
||||||
category: filterCategory || undefined,
|
|
||||||
search: searchTerm || undefined
|
search: searchTerm || undefined
|
||||||
});
|
});
|
||||||
setDocuments(docs);
|
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 => {
|
const filteredDocs = documents.filter(doc => {
|
||||||
if (searchTerm && !doc.title.toLowerCase().includes(searchTerm.toLowerCase())) {
|
if (searchTerm && !doc.title.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -101,10 +97,11 @@ export default function DocumentsPage() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Group by type for display
|
||||||
const groupedDocs = filteredDocs.reduce((acc, doc) => {
|
const groupedDocs = filteredDocs.reduce((acc, doc) => {
|
||||||
const cat = doc.category || 'Uncategorized';
|
const typeLabel = TYPE_CONFIG[doc.type]?.label || doc.type;
|
||||||
if (!acc[cat]) acc[cat] = [];
|
if (!acc[typeLabel]) acc[typeLabel] = [];
|
||||||
acc[cat].push(doc);
|
acc[typeLabel].push(doc);
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, Document[]>);
|
}, {} as Record<string, Document[]>);
|
||||||
|
|
||||||
|
|
@ -162,9 +159,10 @@ export default function DocumentsPage() {
|
||||||
<option value="">All Types</option>
|
<option value="">All Types</option>
|
||||||
<option value="SOP">SOPs</option>
|
<option value="SOP">SOPs</option>
|
||||||
<option value="POLICY">Policies</option>
|
<option value="POLICY">Policies</option>
|
||||||
|
<option value="TRAINING">Training</option>
|
||||||
<option value="FORM">Forms</option>
|
<option value="FORM">Forms</option>
|
||||||
<option value="CHECKLIST">Checklists</option>
|
<option value="CHECKLIST">Checklists</option>
|
||||||
<option value="GUIDE">Guides</option>
|
<option value="OTHER">Other</option>
|
||||||
</select>
|
</select>
|
||||||
<select
|
<select
|
||||||
value={filterStatus}
|
value={filterStatus}
|
||||||
|
|
@ -177,18 +175,6 @@ export default function DocumentsPage() {
|
||||||
<option value="DRAFT">Draft</option>
|
<option value="DRAFT">Draft</option>
|
||||||
<option value="ARCHIVED">Archived</option>
|
<option value="ARCHIVED">Archived</option>
|
||||||
</select>
|
</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>
|
</div>
|
||||||
|
|
||||||
{/* Documents Grid */}
|
{/* Documents Grid */}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue