141 lines
7.9 KiB
TypeScript
141 lines
7.9 KiB
TypeScript
import { DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
import { useTranslation } from 'react-i18next';
|
|
import { FileText, Tag, Calendar, Download, User, AlertTriangle, Clock, CheckCircle, Eye } from 'lucide-react';
|
|
interface ViewHrDocumentProps {
|
|
document: any;
|
|
}
|
|
export default function View({ document }: ViewHrDocumentProps) {
|
|
const { t } = useTranslation();
|
|
const getStatusClass = (status: string) => {
|
|
switch (status) {
|
|
case 'Draft': return 'bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/10';
|
|
case 'Under Review': return 'bg-yellow-50 text-yellow-800 ring-1 ring-inset ring-yellow-600/20';
|
|
case 'Approved': return 'bg-green-50 text-green-700 ring-1 ring-inset ring-green-600/20';
|
|
case 'Published': return 'bg-blue-50 text-blue-700 ring-1 ring-inset ring-blue-600/20';
|
|
case 'Archived': return 'bg-purple-50 text-purple-700 ring-1 ring-inset ring-purple-600/20';
|
|
case 'Expired': return 'bg-red-50 text-red-700 ring-1 ring-inset ring-red-600/10';
|
|
default: return 'bg-gray-50 text-gray-600 ring-1 ring-inset ring-gray-500/10';
|
|
}
|
|
};
|
|
const getStatusIcon = (status: string) => {
|
|
switch (status) {
|
|
case 'Under Review': return <Clock className="h-3 w-3" />;
|
|
case 'Approved': return <CheckCircle className="h-3 w-3" />;
|
|
case 'Published': return <Eye className="h-3 w-3" />;
|
|
case 'Expired': return <AlertTriangle className="h-3 w-3" />;
|
|
default: return <FileText className="h-3 w-3" />;
|
|
}
|
|
};
|
|
const formatFileSize = (bytes: number) => {
|
|
if (!bytes) return '-';
|
|
if (bytes >= 1073741824) return (bytes / 1073741824).toFixed(2) + ' GB';
|
|
if (bytes >= 1048576) return (bytes / 1048576).toFixed(2) + ' MB';
|
|
if (bytes >= 1024) return (bytes / 1024).toFixed(2) + ' KB';
|
|
return bytes + ' bytes';
|
|
};
|
|
const isExpired = document.expiry_date && new Date(document.expiry_date) < new Date();
|
|
return (
|
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto p-0" onOpenAutoFocus={(e) => e.preventDefault()}>
|
|
<DialogHeader className="px-6 pt-6 pb-4 border-b">
|
|
<div className="flex items-center gap-3">
|
|
<div className="w-10 h-10 rounded-lg flex items-center justify-center text-white shrink-0" style={{ backgroundColor: document.category?.color || '#3B82F6' }}>
|
|
<FileText className="h-5 w-5" />
|
|
</div>
|
|
<div>
|
|
<DialogTitle className="text-xl font-semibold">{document.title || t('Document Details')}</DialogTitle>
|
|
</div>
|
|
</div>
|
|
</DialogHeader>
|
|
<div className="px-6 py-4 pb-6 space-y-4">
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<Tag className="h-4 w-4" />
|
|
{t('Category')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">{document.category?.name || '-'}</p>
|
|
</div>
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<FileText className="h-4 w-4" />
|
|
{t('Status')}
|
|
</label>
|
|
<p className="mt-1">
|
|
<span className={`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium ${getStatusClass(document.status)}`}>
|
|
{getStatusIcon(document.status)}
|
|
{t(document.status) || '-'}
|
|
</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<FileText className="h-4 w-4" />
|
|
{t('File Size')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">{formatFileSize(document.file_size)}</p>
|
|
</div>
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<Download className="h-4 w-4" />
|
|
{t('Downloads')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">{document.download_count || 0}</p>
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<Calendar className="h-4 w-4" />
|
|
{t('Effective Date')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">
|
|
{document.effective_date ? (window.appSettings?.formatDateTimeSimple(document.effective_date, false) || document.effective_date) : '-'}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<Calendar className="h-4 w-4" />
|
|
{t('Expiry Date')}
|
|
</label>
|
|
<p className={`mt-1 text-sm font-medium ${isExpired ? 'text-red-600' : 'text-gray-900'}`}>
|
|
{document.expiry_date ? (window.appSettings?.formatDateTimeSimple(document.expiry_date, false) || document.expiry_date) : '-'}
|
|
{isExpired && <span className="ml-2 text-xs text-red-500">({t('Expired')})</span>}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<User className="h-4 w-4" />
|
|
{t('Uploaded By')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">{document.uploader?.name || '-'}</p>
|
|
</div>
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<AlertTriangle className="h-4 w-4" />
|
|
{t('Requires Acknowledgment')}
|
|
</label>
|
|
<p className="mt-1">
|
|
<span className={`inline-flex items-center rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset ${document.requires_acknowledgment ? 'bg-green-50 text-green-700 ring-green-600/20' : 'bg-red-50 text-red-700 ring-red-600/10'}`}>
|
|
{document.requires_acknowledgment ? t('Yes') : t('No')}
|
|
</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
{document.description && (
|
|
<div>
|
|
<label className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
|
<FileText className="h-4 w-4" />
|
|
{t('Description')}
|
|
</label>
|
|
<p className="mt-1 text-sm font-medium text-gray-900">{document.description}</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</DialogContent>
|
|
);
|
|
}
|