edits for trenders attachments & claims

This commit is contained in:
Aya
2026-05-19 11:41:44 +03:00
parent 7732a40726
commit 12c4ca8334
19 changed files with 583 additions and 105 deletions

View File

@@ -212,16 +212,34 @@ function TenderDetailContent() {
}
const handleTenderFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0]
if (!file) return
const files = Array.from(e.target.files || [])
if (!files.length) return
setSubmitting(true)
let successCount = 0
let failCount = 0
try {
await tendersAPI.uploadTenderAttachment(tenderId, file)
toast.success(t('tenders.uploadFile'))
fetchTender()
} catch (err: any) {
toast.error(err.response?.data?.message || 'Upload failed')
// Upload files sequentially so a failure of one file doesn't break the rest.
for (const file of files) {
try {
await tendersAPI.uploadTenderAttachment(tenderId, file)
successCount++
} catch (err: any) {
failCount++
const msg = err.response?.data?.message || 'Upload failed'
toast.error(`${file.name}: ${msg}`)
}
}
if (successCount > 0) {
toast.success(
files.length === 1
? t('tenders.uploadFile')
: `${successCount}/${files.length}`
)
}
if (successCount > 0) fetchTender()
} finally {
setSubmitting(false)
e.target.value = ''
@@ -234,20 +252,35 @@ function TenderDetailContent() {
}
const handleDirectiveFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0]
const files = Array.from(e.target.files || [])
const directiveId = directiveIdForUpload
e.target.value = ''
setDirectiveIdForUpload(null)
if (!file || !directiveId) return
if (!files.length || !directiveId) return
setUploadingDirectiveId(directiveId)
let successCount = 0
try {
await tendersAPI.uploadDirectiveAttachment(directiveId, file)
toast.success(t('tenders.uploadFile'))
fetchTender()
} catch (err: any) {
toast.error(err.response?.data?.message || 'Upload failed')
for (const file of files) {
try {
await tendersAPI.uploadDirectiveAttachment(directiveId, file)
successCount++
} catch (err: any) {
const msg = err.response?.data?.message || 'Upload failed'
toast.error(`${file.name}: ${msg}`)
}
}
if (successCount > 0) {
toast.success(
files.length === 1
? t('tenders.uploadFile')
: `${successCount}/${files.length}`
)
fetchTender()
}
} finally {
setUploadingDirectiveId(null)
}
@@ -462,6 +495,7 @@ function TenderDetailContent() {
<input
type="file"
ref={directiveFileInputRef}
multiple
className="hidden"
onChange={handleDirectiveFileUpload}
/>
@@ -493,6 +527,7 @@ function TenderDetailContent() {
<input
type="file"
ref={fileInputRef}
multiple
className="hidden"
onChange={handleTenderFileUpload}
/>