feat(tenders): add Tender Management module (SRS, backend, frontend)
- SRS document: docs/SRS_TENDER_MANAGEMENT.md - Prisma: Tender, TenderDirective models; Deal.sourceTenderId; Attachment.tenderId/tenderDirectiveId - Backend: tenders module (CRUD, duplicate check, directives, notifications, file upload, convert-to-deal) - Frontend: tenders list, detail, create/edit forms, directives, convert to deal, i18n (en/ar), dashboard card - Seed: tenders permissions for admin and sales positions - Auth: admin.service findFirst for email check (Prisma compatibility) Made-with: Cursor
This commit is contained in:
@@ -18,7 +18,8 @@ import {
|
||||
Building2,
|
||||
Settings,
|
||||
Bell,
|
||||
Shield
|
||||
Shield,
|
||||
FileText
|
||||
} from 'lucide-react'
|
||||
import { dashboardAPI } from '@/lib/api'
|
||||
|
||||
@@ -56,6 +57,16 @@ function DashboardContent() {
|
||||
description: 'الفرص التجارية والعروض والصفقات',
|
||||
permission: 'crm'
|
||||
},
|
||||
{
|
||||
id: 'tenders',
|
||||
name: 'إدارة المناقصات',
|
||||
nameEn: 'Tender Management',
|
||||
icon: FileText,
|
||||
color: 'bg-indigo-500',
|
||||
href: '/tenders',
|
||||
description: 'تسجيل ومتابعة المناقصات وتحويلها إلى فرص',
|
||||
permission: 'crm'
|
||||
},
|
||||
{
|
||||
id: 'inventory',
|
||||
name: 'المخزون والأصول',
|
||||
|
||||
528
frontend/src/app/tenders/[id]/page.tsx
Normal file
528
frontend/src/app/tenders/[id]/page.tsx
Normal file
@@ -0,0 +1,528 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import {
|
||||
ArrowLeft,
|
||||
FileText,
|
||||
Calendar,
|
||||
Building2,
|
||||
DollarSign,
|
||||
User,
|
||||
History,
|
||||
Plus,
|
||||
Loader2,
|
||||
CheckCircle2,
|
||||
Upload,
|
||||
ExternalLink,
|
||||
AlertCircle,
|
||||
} from 'lucide-react'
|
||||
import ProtectedRoute from '@/components/ProtectedRoute'
|
||||
import LoadingSpinner from '@/components/LoadingSpinner'
|
||||
import Modal from '@/components/Modal'
|
||||
import { tendersAPI, Tender, TenderDirective, CreateDirectiveData } from '@/lib/api/tenders'
|
||||
import { contactsAPI } from '@/lib/api/contacts'
|
||||
import { pipelinesAPI } from '@/lib/api/pipelines'
|
||||
import { employeesAPI } from '@/lib/api/employees'
|
||||
import { useLanguage } from '@/contexts/LanguageContext'
|
||||
|
||||
const DIRECTIVE_TYPE_LABELS: Record<string, string> = {
|
||||
BUY_TERMS: 'Buy terms booklet',
|
||||
VISIT_CLIENT: 'Visit client',
|
||||
MEET_COMMITTEE: 'Meet committee',
|
||||
PREPARE_TO_BID: 'Prepare to bid',
|
||||
}
|
||||
|
||||
function TenderDetailContent() {
|
||||
const params = useParams()
|
||||
const router = useRouter()
|
||||
const tenderId = params.id as string
|
||||
const { t } = useLanguage()
|
||||
|
||||
const [tender, setTender] = useState<Tender | null>(null)
|
||||
const [history, setHistory] = useState<any[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [activeTab, setActiveTab] = useState<'info' | 'directives' | 'attachments' | 'history'>('info')
|
||||
const [showDirectiveModal, setShowDirectiveModal] = useState(false)
|
||||
const [showConvertModal, setShowConvertModal] = useState(false)
|
||||
const [showCompleteModal, setShowCompleteModal] = useState<TenderDirective | null>(null)
|
||||
const [employees, setEmployees] = useState<any[]>([])
|
||||
const [contacts, setContacts] = useState<any[]>([])
|
||||
const [pipelines, setPipelines] = useState<any[]>([])
|
||||
const [directiveForm, setDirectiveForm] = useState<CreateDirectiveData>({ type: 'BUY_TERMS', assignedToEmployeeId: '', notes: '' })
|
||||
const [convertForm, setConvertForm] = useState({ contactId: '', pipelineId: '', ownerId: '' })
|
||||
const [completeNotes, setCompleteNotes] = useState('')
|
||||
const [directiveTypeValues, setDirectiveTypeValues] = useState<string[]>([])
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const directiveFileInputRef = useRef<HTMLInputElement>(null)
|
||||
const [uploadingDirectiveId, setUploadingDirectiveId] = useState<string | null>(null)
|
||||
const [directiveIdForUpload, setDirectiveIdForUpload] = useState<string | null>(null)
|
||||
|
||||
const fetchTender = async () => {
|
||||
try {
|
||||
const data = await tendersAPI.getById(tenderId)
|
||||
setTender(data)
|
||||
} catch {
|
||||
toast.error(t('tenders.loadError'))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchHistory = async () => {
|
||||
try {
|
||||
const data = await tendersAPI.getHistory(tenderId)
|
||||
setHistory(data)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchTender()
|
||||
}, [tenderId])
|
||||
|
||||
useEffect(() => {
|
||||
if (tender) fetchHistory()
|
||||
}, [tender?.id])
|
||||
|
||||
useEffect(() => {
|
||||
tendersAPI.getDirectiveTypeValues().then(setDirectiveTypeValues).catch(() => {})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (showDirectiveModal || showConvertModal) {
|
||||
employeesAPI.getAll({ status: 'ACTIVE', pageSize: 500 }).then((r: any) => setEmployees(r.employees || [])).catch(() => {})
|
||||
}
|
||||
if (showConvertModal) {
|
||||
contactsAPI.getAll({ pageSize: 500 }).then((r: any) => setContacts(r.contacts || [])).catch(() => {})
|
||||
pipelinesAPI.getAll().then(setPipelines).catch(() => {})
|
||||
}
|
||||
}, [showDirectiveModal, showConvertModal])
|
||||
|
||||
const handleAddDirective = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!directiveForm.assignedToEmployeeId) {
|
||||
toast.error(t('tenders.assignee') + ' ' + t('common.required'))
|
||||
return
|
||||
}
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await tendersAPI.createDirective(tenderId, directiveForm)
|
||||
toast.success('Directive created')
|
||||
setShowDirectiveModal(false)
|
||||
setDirectiveForm({ type: 'BUY_TERMS', assignedToEmployeeId: '', notes: '' })
|
||||
fetchTender()
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Failed')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCompleteDirective = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!showCompleteModal) return
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await tendersAPI.updateDirective(showCompleteModal.id, { status: 'COMPLETED', completionNotes: completeNotes })
|
||||
toast.success('Task completed')
|
||||
setShowCompleteModal(null)
|
||||
setCompleteNotes('')
|
||||
fetchTender()
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Failed')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleConvertToDeal = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!convertForm.contactId || !convertForm.pipelineId) {
|
||||
toast.error('Contact and Pipeline are required')
|
||||
return
|
||||
}
|
||||
setSubmitting(true)
|
||||
try {
|
||||
const deal = await tendersAPI.convertToDeal(tenderId, convertForm)
|
||||
toast.success('Tender converted to deal')
|
||||
setShowConvertModal(false)
|
||||
router.push(`/crm/deals/${deal.id}`)
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Failed')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleTenderFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (!file) return
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await tendersAPI.uploadTenderAttachment(tenderId, file)
|
||||
toast.success(t('tenders.uploadFile'))
|
||||
fetchTender()
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Upload failed')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
e.target.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const handleDirectiveFileSelect = (directiveId: string) => {
|
||||
setDirectiveIdForUpload(directiveId)
|
||||
setTimeout(() => directiveFileInputRef.current?.click(), 0)
|
||||
}
|
||||
|
||||
const handleDirectiveFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
const directiveId = directiveIdForUpload
|
||||
e.target.value = ''
|
||||
setDirectiveIdForUpload(null)
|
||||
if (!file || !directiveId) return
|
||||
setUploadingDirectiveId(directiveId)
|
||||
try {
|
||||
await tendersAPI.uploadDirectiveAttachment(directiveId, file)
|
||||
toast.success(t('tenders.uploadFile'))
|
||||
fetchTender()
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Upload failed')
|
||||
} finally {
|
||||
setUploadingDirectiveId(null)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading || !tender) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<LoadingSpinner />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
{ id: 'info', label: t('tenders.titleLabel') || 'Info', icon: FileText },
|
||||
{ id: 'directives', label: t('tenders.directives'), icon: CheckCircle2 },
|
||||
{ id: 'attachments', label: t('tenders.attachments'), icon: Upload },
|
||||
{ id: 'history', label: t('tenders.history'), icon: History },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<div className="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/tenders" className="p-2 hover:bg-gray-200 rounded-lg">
|
||||
<ArrowLeft className="h-5 w-5" />
|
||||
</Link>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">{tender.tenderNumber} – {tender.title}</h1>
|
||||
<p className="text-sm text-gray-600">{tender.issuingBodyName}</p>
|
||||
</div>
|
||||
</div>
|
||||
{tender.status === 'ACTIVE' && (
|
||||
<button
|
||||
onClick={() => setShowConvertModal(true)}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700"
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" />
|
||||
{t('tenders.convertToDeal')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
||||
<div className="border-b border-gray-200 flex gap-1 p-1">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id as any)}
|
||||
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium ${
|
||||
activeTab === tab.id ? 'bg-indigo-100 text-indigo-800' : 'text-gray-600 hover:bg-gray-100'
|
||||
}`}
|
||||
>
|
||||
<tab.icon className="h-4 w-4" />
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="p-6">
|
||||
{activeTab === 'info' && (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="flex items-start gap-2">
|
||||
<Calendar className="h-5 w-5 text-gray-400 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">{t('tenders.announcementDate')}</p>
|
||||
<p>{tender.announcementDate?.split('T')[0]}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-2">
|
||||
<Calendar className="h-5 w-5 text-gray-400 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">{t('tenders.closingDate')}</p>
|
||||
<p>{tender.closingDate?.split('T')[0]}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-2">
|
||||
<DollarSign className="h-5 w-5 text-gray-400 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">{t('tenders.termsValue')}</p>
|
||||
<p>{Number(tender.termsValue)} SAR</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-2">
|
||||
<DollarSign className="h-5 w-5 text-gray-400 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">{t('tenders.bondValue')}</p>
|
||||
<p>{Number(tender.bondValue)} SAR</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{tender.announcementLink && (
|
||||
<p>
|
||||
<a href={tender.announcementLink} target="_blank" rel="noopener noreferrer" className="text-indigo-600 hover:underline">
|
||||
{t('tenders.announcementLink')}
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
{tender.notes && (
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">{t('common.notes')}</p>
|
||||
<p className="whitespace-pre-wrap">{tender.notes}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'directives' && (
|
||||
<div>
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h3 className="font-medium">{t('tenders.directives')}</h3>
|
||||
<button
|
||||
onClick={() => setShowDirectiveModal(true)}
|
||||
className="flex items-center gap-1 text-indigo-600 hover:underline"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
{t('tenders.addDirective')}
|
||||
</button>
|
||||
</div>
|
||||
{!tender.directives?.length ? (
|
||||
<p className="text-gray-500">{t('common.noData')}</p>
|
||||
) : (
|
||||
<ul className="space-y-3">
|
||||
{tender.directives.map((d) => (
|
||||
<li key={d.id} className="border rounded-lg p-4 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="font-medium">{DIRECTIVE_TYPE_LABELS[d.type] || d.type}</p>
|
||||
<p className="text-sm text-gray-600">
|
||||
{d.assignedToEmployee ? `${d.assignedToEmployee.firstName} ${d.assignedToEmployee.lastName}` : ''} · {d.status}
|
||||
</p>
|
||||
{d.completionNotes && <p className="text-sm mt-1">{d.completionNotes}</p>}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{d.status !== 'COMPLETED' && d.assignedToEmployee?.user?.id && (
|
||||
<button
|
||||
onClick={() => setShowCompleteModal(d)}
|
||||
className="text-sm text-green-600 hover:underline"
|
||||
>
|
||||
{t('tenders.completeTask')}
|
||||
</button>
|
||||
)}
|
||||
<input
|
||||
type="file"
|
||||
ref={directiveFileInputRef}
|
||||
className="hidden"
|
||||
onChange={handleDirectiveFileUpload}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDirectiveFileSelect(d.id)}
|
||||
disabled={uploadingDirectiveId === d.id}
|
||||
className="text-sm text-indigo-600 hover:underline flex items-center gap-1"
|
||||
>
|
||||
{uploadingDirectiveId === d.id ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />}
|
||||
{t('tenders.uploadFile')}
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'attachments' && (
|
||||
<div>
|
||||
<div className="flex items-center gap-4 mb-4">
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
className="hidden"
|
||||
onChange={handleTenderFileUpload}
|
||||
/>
|
||||
<button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
disabled={submitting}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 disabled:opacity-50"
|
||||
>
|
||||
{submitting ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />}
|
||||
{t('tenders.uploadFile')}
|
||||
</button>
|
||||
</div>
|
||||
{!tender.attachments?.length ? (
|
||||
<p className="text-gray-500">{t('common.noData')}</p>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
{tender.attachments.map((a: any) => (
|
||||
<li key={a.id} className="text-sm text-gray-700">
|
||||
{a.originalName || a.fileName}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'history' && (
|
||||
<div>
|
||||
{history.length === 0 ? (
|
||||
<p className="text-gray-500">{t('common.noData')}</p>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
{history.map((h: any) => (
|
||||
<li key={h.id} className="text-sm border-b border-gray-100 pb-2">
|
||||
<span className="font-medium">{h.action}</span> · {h.user?.username} · {h.createdAt?.split('T')[0]}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal isOpen={showDirectiveModal} onClose={() => setShowDirectiveModal(false)} title={t('tenders.addDirective')}>
|
||||
<form onSubmit={handleAddDirective} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.directiveType')}</label>
|
||||
<select
|
||||
value={directiveForm.type}
|
||||
onChange={(e) => setDirectiveForm({ ...directiveForm, type: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
>
|
||||
{directiveTypeValues.map((v) => (
|
||||
<option key={v} value={v}>{DIRECTIVE_TYPE_LABELS[v] || v}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.assignee')} *</label>
|
||||
<select
|
||||
value={directiveForm.assignedToEmployeeId}
|
||||
onChange={(e) => setDirectiveForm({ ...directiveForm, assignedToEmployeeId: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
required
|
||||
>
|
||||
<option value="">Select employee</option>
|
||||
{employees.map((emp) => (
|
||||
<option key={emp.id} value={emp.id}>{emp.firstName} {emp.lastName}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('common.notes')}</label>
|
||||
<textarea
|
||||
value={directiveForm.notes || ''}
|
||||
onChange={(e) => setDirectiveForm({ ...directiveForm, notes: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<button type="button" onClick={() => setShowDirectiveModal(false)} className="px-4 py-2 border rounded-lg">{t('common.cancel')}</button>
|
||||
<button type="submit" disabled={submitting} className="px-4 py-2 bg-indigo-600 text-white rounded-lg disabled:opacity-50 flex items-center gap-2">
|
||||
{submitting && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal isOpen={!!showCompleteModal} onClose={() => setShowCompleteModal(null)} title={t('tenders.completeTask')}>
|
||||
<form onSubmit={handleCompleteDirective} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.completionNotes')}</label>
|
||||
<textarea
|
||||
value={completeNotes}
|
||||
onChange={(e) => setCompleteNotes(e.target.value)}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<button type="button" onClick={() => setShowCompleteModal(null)} className="px-4 py-2 border rounded-lg">{t('common.cancel')}</button>
|
||||
<button type="submit" disabled={submitting} className="px-4 py-2 bg-green-600 text-white rounded-lg disabled:opacity-50 flex items-center gap-2">
|
||||
{submitting && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal isOpen={showConvertModal} onClose={() => setShowConvertModal(false)} title={t('tenders.convertToDeal')}>
|
||||
<form onSubmit={handleConvertToDeal} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Contact *</label>
|
||||
<select
|
||||
value={convertForm.contactId}
|
||||
onChange={(e) => setConvertForm({ ...convertForm, contactId: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
required
|
||||
>
|
||||
<option value="">Select contact</option>
|
||||
{contacts.map((c) => (
|
||||
<option key={c.id} value={c.id}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Pipeline *</label>
|
||||
<select
|
||||
value={convertForm.pipelineId}
|
||||
onChange={(e) => setConvertForm({ ...convertForm, pipelineId: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
required
|
||||
>
|
||||
<option value="">Select pipeline</option>
|
||||
{pipelines.map((p) => (
|
||||
<option key={p.id} value={p.id}>{p.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<button type="button" onClick={() => setShowConvertModal(false)} className="px-4 py-2 border rounded-lg">{t('common.cancel')}</button>
|
||||
<button type="submit" disabled={submitting} className="px-4 py-2 bg-green-600 text-white rounded-lg disabled:opacity-50 flex items-center gap-2">
|
||||
{submitting && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{t('tenders.convertToDeal')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function TenderDetailPage() {
|
||||
return (
|
||||
<ProtectedRoute>
|
||||
<TenderDetailContent />
|
||||
</ProtectedRoute>
|
||||
)
|
||||
}
|
||||
447
frontend/src/app/tenders/page.tsx
Normal file
447
frontend/src/app/tenders/page.tsx
Normal file
@@ -0,0 +1,447 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import ProtectedRoute from '@/components/ProtectedRoute'
|
||||
import Modal from '@/components/Modal'
|
||||
import LoadingSpinner from '@/components/LoadingSpinner'
|
||||
import Link from 'next/link'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import {
|
||||
FileText,
|
||||
Plus,
|
||||
Search,
|
||||
Calendar,
|
||||
Building2,
|
||||
DollarSign,
|
||||
AlertCircle,
|
||||
ArrowLeft,
|
||||
Eye,
|
||||
Loader2,
|
||||
} from 'lucide-react'
|
||||
import { tendersAPI, Tender, CreateTenderData, TenderFilters } from '@/lib/api/tenders'
|
||||
import { useLanguage } from '@/contexts/LanguageContext'
|
||||
|
||||
const SOURCE_LABELS: Record<string, string> = {
|
||||
GOVERNMENT_SITE: 'Government site',
|
||||
OFFICIAL_GAZETTE: 'Official gazette',
|
||||
PERSONAL: 'Personal relations',
|
||||
PARTNER: 'Partner companies',
|
||||
WHATSAPP_TELEGRAM: 'WhatsApp/Telegram',
|
||||
PORTAL: 'Tender portals',
|
||||
EMAIL: 'Email',
|
||||
MANUAL: 'Manual entry',
|
||||
}
|
||||
|
||||
const ANNOUNCEMENT_LABELS: Record<string, string> = {
|
||||
FIRST: 'First announcement',
|
||||
RE_ANNOUNCEMENT_2: 'Re-announcement 2nd',
|
||||
RE_ANNOUNCEMENT_3: 'Re-announcement 3rd',
|
||||
RE_ANNOUNCEMENT_4: 'Re-announcement 4th',
|
||||
}
|
||||
|
||||
function TendersContent() {
|
||||
const { t } = useLanguage()
|
||||
const [tenders, setTenders] = useState<Tender[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [totalPages, setTotalPages] = useState(1)
|
||||
const [total, setTotal] = useState(0)
|
||||
const pageSize = 10
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
const [selectedStatus, setSelectedStatus] = useState('all')
|
||||
const [showCreateModal, setShowCreateModal] = useState(false)
|
||||
const [formData, setFormData] = useState<CreateTenderData>({
|
||||
tenderNumber: '',
|
||||
issuingBodyName: '',
|
||||
title: '',
|
||||
termsValue: 0,
|
||||
bondValue: 0,
|
||||
announcementDate: '',
|
||||
closingDate: '',
|
||||
source: 'MANUAL',
|
||||
announcementType: 'FIRST',
|
||||
})
|
||||
const [formErrors, setFormErrors] = useState<Record<string, string>>({})
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [possibleDuplicates, setPossibleDuplicates] = useState<Tender[]>([])
|
||||
const [showDuplicateWarning, setShowDuplicateWarning] = useState(false)
|
||||
const [sourceValues, setSourceValues] = useState<string[]>([])
|
||||
const [announcementTypeValues, setAnnouncementTypeValues] = useState<string[]>([])
|
||||
|
||||
const fetchTenders = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const filters: TenderFilters = { page: currentPage, pageSize }
|
||||
if (searchTerm) filters.search = searchTerm
|
||||
if (selectedStatus !== 'all') filters.status = selectedStatus
|
||||
const data = await tendersAPI.getAll(filters)
|
||||
setTenders(data.tenders)
|
||||
setTotal(data.total)
|
||||
setTotalPages(data.totalPages)
|
||||
} catch {
|
||||
toast.error(t('tenders.loadError') || 'Failed to load tenders')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [currentPage, searchTerm, selectedStatus, t])
|
||||
|
||||
useEffect(() => {
|
||||
fetchTenders()
|
||||
}, [fetchTenders])
|
||||
|
||||
useEffect(() => {
|
||||
tendersAPI.getSourceValues().then(setSourceValues).catch(() => {})
|
||||
tendersAPI.getAnnouncementTypeValues().then(setAnnouncementTypeValues).catch(() => {})
|
||||
}, [])
|
||||
|
||||
const handleCreate = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
const errors: Record<string, string> = {}
|
||||
if (!formData.tenderNumber?.trim()) errors.tenderNumber = t('common.required')
|
||||
if (!formData.issuingBodyName?.trim()) errors.issuingBodyName = t('common.required')
|
||||
if (!formData.title?.trim()) errors.title = t('common.required')
|
||||
if (!formData.announcementDate) errors.announcementDate = t('common.required')
|
||||
if (!formData.closingDate) errors.closingDate = t('common.required')
|
||||
if (Number(formData.termsValue) < 0) errors.termsValue = t('common.required')
|
||||
if (Number(formData.bondValue) < 0) errors.bondValue = t('common.required')
|
||||
setFormErrors(errors)
|
||||
if (Object.keys(errors).length > 0) return
|
||||
|
||||
setSubmitting(true)
|
||||
try {
|
||||
const result = await tendersAPI.create(formData)
|
||||
if (result.possibleDuplicates && result.possibleDuplicates.length > 0) {
|
||||
setPossibleDuplicates(result.possibleDuplicates)
|
||||
setShowDuplicateWarning(true)
|
||||
toast(t('tenders.duplicateWarning') || 'Possible duplicates found. Please review.', { icon: '⚠️' })
|
||||
} else {
|
||||
toast.success(t('tenders.createSuccess') || 'Tender created successfully')
|
||||
setShowCreateModal(false)
|
||||
resetForm()
|
||||
fetchTenders()
|
||||
}
|
||||
} catch (err: any) {
|
||||
toast.error(err.response?.data?.message || 'Failed to create tender')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
setFormData({
|
||||
tenderNumber: '',
|
||||
issuingBodyName: '',
|
||||
title: '',
|
||||
termsValue: 0,
|
||||
bondValue: 0,
|
||||
announcementDate: '',
|
||||
closingDate: '',
|
||||
source: 'MANUAL',
|
||||
announcementType: 'FIRST',
|
||||
})
|
||||
setFormErrors({})
|
||||
setPossibleDuplicates([])
|
||||
setShowDuplicateWarning(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="p-2 hover:bg-gray-200 rounded-lg transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-5 w-5" />
|
||||
</Link>
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-8 w-8 text-indigo-600" />
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">{t('nav.tenders') || 'Tenders'}</h1>
|
||||
<p className="text-sm text-gray-600">{t('tenders.subtitle') || 'Tender Management'}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => { setShowCreateModal(true); resetForm(); }}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700"
|
||||
>
|
||||
<Plus className="h-5 w-5" />
|
||||
{t('tenders.addTender') || 'Add Tender'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
||||
<div className="p-4 border-b border-gray-200 flex flex-wrap gap-4 items-center">
|
||||
<div className="relative flex-1 min-w-[200px]">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder={t('tenders.searchPlaceholder') || 'Search by number, title, issuing body...'}
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<select
|
||||
value={selectedStatus}
|
||||
onChange={(e) => setSelectedStatus(e.target.value)}
|
||||
className="px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
||||
>
|
||||
<option value="all">{t('common.all') || 'All status'}</option>
|
||||
<option value="ACTIVE">Active</option>
|
||||
<option value="CONVERTED_TO_DEAL">Converted</option>
|
||||
<option value="CANCELLED">Cancelled</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<LoadingSpinner />
|
||||
</div>
|
||||
) : tenders.length === 0 ? (
|
||||
<div className="text-center py-12 text-gray-500">
|
||||
{t('tenders.noTenders') || 'No tenders found.'}
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">{t('tenders.tenderNumber') || 'Number'}</th>
|
||||
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">{t('tenders.title') || 'Title'}</th>
|
||||
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">{t('tenders.issuingBody') || 'Issuing body'}</th>
|
||||
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">{t('tenders.closingDate') || 'Closing date'}</th>
|
||||
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">{t('common.status')}</th>
|
||||
<th className="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase">{t('common.actions')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{tenders.map((t) => (
|
||||
<tr key={t.id} className="hover:bg-gray-50">
|
||||
<td className="px-4 py-3 text-sm font-medium text-gray-900">{t.tenderNumber}</td>
|
||||
<td className="px-4 py-3 text-sm text-gray-900">{t.title}</td>
|
||||
<td className="px-4 py-3 text-sm text-gray-600">{t.issuingBodyName}</td>
|
||||
<td className="px-4 py-3 text-sm text-gray-600">{t.closingDate?.split('T')[0]}</td>
|
||||
<td className="px-4 py-3">
|
||||
<span className={`px-2 py-1 text-xs rounded-full ${
|
||||
t.status === 'ACTIVE' ? 'bg-green-100 text-green-800' :
|
||||
t.status === 'CONVERTED_TO_DEAL' ? 'bg-blue-100 text-blue-800' : 'bg-gray-100 text-gray-800'
|
||||
}`}>
|
||||
{t.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
<Link
|
||||
href={`/tenders/${t.id}`}
|
||||
className="inline-flex items-center gap-1 text-indigo-600 hover:underline"
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
{t('common.view') || 'View'}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{totalPages > 1 && (
|
||||
<div className="px-4 py-3 border-t border-gray-200 flex items-center justify-between">
|
||||
<p className="text-sm text-gray-600">
|
||||
{t('common.showing') || 'Showing'} {(currentPage - 1) * pageSize + 1}–{Math.min(currentPage * pageSize, total)} {t('common.of') || 'of'} {total}
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
disabled={currentPage <= 1}
|
||||
onClick={() => setCurrentPage((p) => p - 1)}
|
||||
className="px-3 py-1 border rounded disabled:opacity-50"
|
||||
>
|
||||
{t('crm.paginationPrevious') || 'Previous'}
|
||||
</button>
|
||||
<button
|
||||
disabled={currentPage >= totalPages}
|
||||
onClick={() => setCurrentPage((p) => p + 1)}
|
||||
className="px-3 py-1 border rounded disabled:opacity-50"
|
||||
>
|
||||
{t('crm.paginationNext') || 'Next'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
isOpen={showCreateModal}
|
||||
onClose={() => { setShowCreateModal(false); setShowDuplicateWarning(false); resetForm(); }}
|
||||
title={t('tenders.addTender') || 'Add Tender'}
|
||||
>
|
||||
<form onSubmit={handleCreate} className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.tenderNumber')} *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.tenderNumber}
|
||||
onChange={(e) => setFormData({ ...formData, tenderNumber: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
{formErrors.tenderNumber && <p className="text-red-500 text-xs mt-1">{formErrors.tenderNumber}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.issuingBody')} *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.issuingBodyName}
|
||||
onChange={(e) => setFormData({ ...formData, issuingBodyName: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
{formErrors.issuingBodyName && <p className="text-red-500 text-xs mt-1">{formErrors.issuingBodyName}</p>}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.titleLabel')} *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.title}
|
||||
onChange={(e) => setFormData({ ...formData, title: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
{formErrors.title && <p className="text-red-500 text-xs mt-1">{formErrors.title}</p>}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.termsValue')} *</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={formData.termsValue || ''}
|
||||
onChange={(e) => setFormData({ ...formData, termsValue: Number(e.target.value) || 0 })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.bondValue')} *</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={formData.bondValue || ''}
|
||||
onChange={(e) => setFormData({ ...formData, bondValue: Number(e.target.value) || 0 })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.announcementDate')} *</label>
|
||||
<input
|
||||
type="date"
|
||||
value={formData.announcementDate}
|
||||
onChange={(e) => setFormData({ ...formData, announcementDate: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
{formErrors.announcementDate && <p className="text-red-500 text-xs mt-1">{formErrors.announcementDate}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.closingDate')} *</label>
|
||||
<input
|
||||
type="date"
|
||||
value={formData.closingDate}
|
||||
onChange={(e) => setFormData({ ...formData, closingDate: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
{formErrors.closingDate && <p className="text-red-500 text-xs mt-1">{formErrors.closingDate}</p>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.source')}</label>
|
||||
<select
|
||||
value={formData.source}
|
||||
onChange={(e) => setFormData({ ...formData, source: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
>
|
||||
{sourceValues.map((s) => (
|
||||
<option key={s} value={s}>{SOURCE_LABELS[s] || s}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.announcementType')}</label>
|
||||
<select
|
||||
value={formData.announcementType}
|
||||
onChange={(e) => setFormData({ ...formData, announcementType: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
>
|
||||
{announcementTypeValues.map((a) => (
|
||||
<option key={a} value={a}>{ANNOUNCEMENT_LABELS[a] || a}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('tenders.announcementLink')}</label>
|
||||
<input
|
||||
type="url"
|
||||
value={formData.announcementLink || ''}
|
||||
onChange={(e) => setFormData({ ...formData, announcementLink: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{t('common.notes')}</label>
|
||||
<textarea
|
||||
value={formData.notes || ''}
|
||||
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
|
||||
className="w-full px-3 py-2 border rounded-lg"
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
{showDuplicateWarning && possibleDuplicates.length > 0 && (
|
||||
<div className="p-3 bg-amber-50 border border-amber-200 rounded-lg flex items-start gap-2">
|
||||
<AlertCircle className="h-5 w-5 text-amber-600 flex-shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-sm font-medium text-amber-800">{t('tenders.duplicateWarning') || 'Possible duplicates found'}</p>
|
||||
<ul className="text-sm text-amber-700 mt-1 list-disc list-inside">
|
||||
{possibleDuplicates.slice(0, 3).map((d) => (
|
||||
<li key={d.id}>
|
||||
<Link href={`/tenders/${d.id}`} className="underline">{d.tenderNumber} - {d.title}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-end gap-2 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setShowCreateModal(false); resetForm(); }}
|
||||
className="px-4 py-2 border rounded-lg"
|
||||
>
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitting}
|
||||
className="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 disabled:opacity-50 flex items-center gap-2"
|
||||
>
|
||||
{submitting && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function TendersPage() {
|
||||
return (
|
||||
<ProtectedRoute>
|
||||
<TendersContent />
|
||||
</ProtectedRoute>
|
||||
)
|
||||
}
|
||||
@@ -99,12 +99,17 @@ const translations = {
|
||||
active: 'Active',
|
||||
inactive: 'Inactive',
|
||||
archived: 'Archived',
|
||||
deleted: 'Deleted'
|
||||
deleted: 'Deleted',
|
||||
all: 'All',
|
||||
view: 'View',
|
||||
showing: 'Showing',
|
||||
of: 'of'
|
||||
},
|
||||
nav: {
|
||||
dashboard: 'Dashboard',
|
||||
contacts: 'Contacts',
|
||||
crm: 'CRM',
|
||||
tenders: 'Tenders',
|
||||
projects: 'Projects',
|
||||
inventory: 'Inventory',
|
||||
hr: 'HR',
|
||||
@@ -318,6 +323,36 @@ const translations = {
|
||||
paidAmount: 'Paid Amount',
|
||||
paidDate: 'Paid Date'
|
||||
},
|
||||
tenders: {
|
||||
title: 'Tenders',
|
||||
subtitle: 'Tender Management',
|
||||
addTender: 'Add Tender',
|
||||
tenderNumber: 'Tender number',
|
||||
issuingBody: 'Issuing body',
|
||||
titleLabel: 'Title',
|
||||
termsValue: 'Terms booklet value',
|
||||
bondValue: 'Bond value',
|
||||
announcementDate: 'Announcement date',
|
||||
closingDate: 'Closing date',
|
||||
announcementLink: 'Announcement link',
|
||||
source: 'Source',
|
||||
announcementType: 'Announcement type',
|
||||
searchPlaceholder: 'Search by number, title, issuing body...',
|
||||
noTenders: 'No tenders found.',
|
||||
loadError: 'Failed to load tenders',
|
||||
createSuccess: 'Tender created successfully',
|
||||
duplicateWarning: 'Possible duplicates found. Please review.',
|
||||
directives: 'Directives',
|
||||
addDirective: 'Add directive',
|
||||
directiveType: 'Directive type',
|
||||
assignee: 'Assignee',
|
||||
convertToDeal: 'Convert to Opportunity',
|
||||
history: 'History',
|
||||
attachments: 'Attachments',
|
||||
uploadFile: 'Upload file',
|
||||
completeTask: 'Complete task',
|
||||
completionNotes: 'Completion notes'
|
||||
},
|
||||
import: {
|
||||
title: 'Import Contacts',
|
||||
downloadTemplate: 'Download Excel Template',
|
||||
@@ -381,6 +416,7 @@ const translations = {
|
||||
dashboard: 'لوحة التحكم',
|
||||
contacts: 'جهات الاتصال',
|
||||
crm: 'إدارة العملاء',
|
||||
tenders: 'المناقصات',
|
||||
projects: 'المشاريع',
|
||||
inventory: 'المخزون',
|
||||
hr: 'الموارد البشرية',
|
||||
@@ -388,6 +424,36 @@ const translations = {
|
||||
settings: 'الإعدادات',
|
||||
logout: 'تسجيل الخروج'
|
||||
},
|
||||
tenders: {
|
||||
title: 'المناقصات',
|
||||
subtitle: 'نظام إدارة المناقصات',
|
||||
addTender: 'إضافة مناقصة',
|
||||
tenderNumber: 'رقم المناقصة',
|
||||
issuingBody: 'الجهة الطارحة',
|
||||
titleLabel: 'عنوان المناقصة',
|
||||
termsValue: 'قيمة دفتر الشروط',
|
||||
bondValue: 'قيمة التأمينات',
|
||||
announcementDate: 'تاريخ الإعلان',
|
||||
closingDate: 'تاريخ الإغلاق',
|
||||
announcementLink: 'رابط الإعلان',
|
||||
source: 'مصدر المناقصة',
|
||||
announcementType: 'نوع الإعلان',
|
||||
searchPlaceholder: 'البحث بالرقم أو العنوان أو الجهة الطارحة...',
|
||||
noTenders: 'لم يتم العثور على مناقصات.',
|
||||
loadError: 'فشل تحميل المناقصات',
|
||||
createSuccess: 'تم إنشاء المناقصة بنجاح',
|
||||
duplicateWarning: 'يوجد مناقصات مشابهة. يرجى المراجعة.',
|
||||
directives: 'التوجيهات',
|
||||
addDirective: 'إضافة توجيه',
|
||||
directiveType: 'نوع التوجيه',
|
||||
assignee: 'الموظف المسؤول',
|
||||
convertToDeal: 'تحويل إلى فرصة',
|
||||
history: 'السجل',
|
||||
attachments: 'المرفقات',
|
||||
uploadFile: 'رفع ملف',
|
||||
completeTask: 'إتمام المهمة',
|
||||
completionNotes: 'ملاحظات الإنجاز'
|
||||
},
|
||||
contacts: {
|
||||
title: 'جهات الاتصال',
|
||||
addContact: 'إضافة جهة اتصال',
|
||||
|
||||
183
frontend/src/lib/api/tenders.ts
Normal file
183
frontend/src/lib/api/tenders.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { api } from '../api'
|
||||
|
||||
export interface Tender {
|
||||
id: string
|
||||
tenderNumber: string
|
||||
issuingBodyName: string
|
||||
title: string
|
||||
termsValue: number
|
||||
bondValue: number
|
||||
announcementDate: string
|
||||
closingDate: string
|
||||
announcementLink?: string
|
||||
source: string
|
||||
sourceOther?: string
|
||||
announcementType: string
|
||||
notes?: string
|
||||
status: string
|
||||
contactId?: string
|
||||
contact?: any
|
||||
createdById: string
|
||||
createdBy?: any
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
directives?: TenderDirective[]
|
||||
attachments?: any[]
|
||||
_count?: { directives: number }
|
||||
}
|
||||
|
||||
export interface TenderDirective {
|
||||
id: string
|
||||
tenderId: string
|
||||
type: string
|
||||
notes?: string
|
||||
assignedToEmployeeId: string
|
||||
assignedToEmployee?: any
|
||||
issuedById: string
|
||||
issuedBy?: any
|
||||
status: string
|
||||
completedAt?: string
|
||||
completionNotes?: string
|
||||
completedById?: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
attachments?: any[]
|
||||
}
|
||||
|
||||
export interface CreateTenderData {
|
||||
tenderNumber: string
|
||||
issuingBodyName: string
|
||||
title: string
|
||||
termsValue: number
|
||||
bondValue: number
|
||||
announcementDate: string
|
||||
closingDate: string
|
||||
announcementLink?: string
|
||||
source: string
|
||||
sourceOther?: string
|
||||
announcementType: string
|
||||
notes?: string
|
||||
contactId?: string
|
||||
}
|
||||
|
||||
export interface CreateDirectiveData {
|
||||
type: string
|
||||
assignedToEmployeeId: string
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface TenderFilters {
|
||||
search?: string
|
||||
status?: string
|
||||
source?: string
|
||||
announcementType?: string
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface TendersResponse {
|
||||
data: Tender[]
|
||||
pagination: {
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
totalPages: number
|
||||
}
|
||||
}
|
||||
|
||||
export const tendersAPI = {
|
||||
getAll: async (filters: TenderFilters = {}): Promise<{ tenders: Tender[]; total: number; page: number; pageSize: number; totalPages: number }> => {
|
||||
const params = new URLSearchParams()
|
||||
if (filters.search) params.append('search', filters.search)
|
||||
if (filters.status) params.append('status', filters.status)
|
||||
if (filters.source) params.append('source', filters.source)
|
||||
if (filters.announcementType) params.append('announcementType', filters.announcementType)
|
||||
if (filters.page) params.append('page', filters.page.toString())
|
||||
if (filters.pageSize) params.append('pageSize', filters.pageSize.toString())
|
||||
|
||||
const response = await api.get(`/tenders?${params.toString()}`)
|
||||
const { data, pagination } = response.data
|
||||
return {
|
||||
tenders: data || [],
|
||||
total: pagination?.total ?? 0,
|
||||
page: pagination?.page ?? 1,
|
||||
pageSize: pagination?.pageSize ?? 20,
|
||||
totalPages: pagination?.totalPages ?? 0,
|
||||
}
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<Tender> => {
|
||||
const response = await api.get(`/tenders/${id}`)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
create: async (data: CreateTenderData): Promise<{ tender: Tender; possibleDuplicates?: Tender[] }> => {
|
||||
const response = await api.post('/tenders', data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
update: async (id: string, data: Partial<CreateTenderData>): Promise<Tender> => {
|
||||
const response = await api.put(`/tenders/${id}`, data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
checkDuplicates: async (data: Partial<CreateTenderData>): Promise<Tender[]> => {
|
||||
const response = await api.post('/tenders/check-duplicates', data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
getHistory: async (id: string): Promise<any[]> => {
|
||||
const response = await api.get(`/tenders/${id}/history`)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
createDirective: async (tenderId: string, data: CreateDirectiveData): Promise<TenderDirective> => {
|
||||
const response = await api.post(`/tenders/${tenderId}/directives`, data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
updateDirective: async (directiveId: string, data: { status?: string; completionNotes?: string }): Promise<TenderDirective> => {
|
||||
const response = await api.put(`/tenders/directives/${directiveId}`, data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
convertToDeal: async (tenderId: string, data: { contactId: string; pipelineId: string; ownerId?: string }): Promise<any> => {
|
||||
const response = await api.post(`/tenders/${tenderId}/convert-to-deal`, data)
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
uploadTenderAttachment: async (tenderId: string, file: File, category?: string): Promise<any> => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (category) formData.append('category', category)
|
||||
const response = await api.post(`/tenders/${tenderId}/attachments`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
uploadDirectiveAttachment: async (directiveId: string, file: File, category?: string): Promise<any> => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (category) formData.append('category', category)
|
||||
const response = await api.post(`/tenders/directives/${directiveId}/attachments`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
getSourceValues: async (): Promise<string[]> => {
|
||||
const response = await api.get('/tenders/source-values')
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
getAnnouncementTypeValues: async (): Promise<string[]> => {
|
||||
const response = await api.get('/tenders/announcement-type-values')
|
||||
return response.data.data
|
||||
},
|
||||
|
||||
getDirectiveTypeValues: async (): Promise<string[]> => {
|
||||
const response = await api.get('/tenders/directive-type-values')
|
||||
return response.data.data
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user