From a7c203d7a420e2e3b3fc4ff0616a9ad19fe172bb Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 27 Apr 2026 14:58:54 +0700 Subject: [PATCH] fix file verification upload --- src/app/styles/settings.scss | 4 + .../component/verification-upload-section.tsx | 120 ++++-------------- .../ui/settings/setting-user-verification.tsx | 2 +- src/i18n/messages/en.json | 4 +- src/i18n/messages/ru.json | 4 +- 5 files changed, 34 insertions(+), 100 deletions(-) diff --git a/src/app/styles/settings.scss b/src/app/styles/settings.scss index 23b6f10..6ab5411 100644 --- a/src/app/styles/settings.scss +++ b/src/app/styles/settings.scss @@ -230,6 +230,10 @@ display: flex; flex-direction: column; + h3 { + margin-bottom: 10px; + } + .drag-drop-zone { border: 2px dashed #6366f1; border-radius: .75rem; diff --git a/src/app/ui/settings/component/verification-upload-section.tsx b/src/app/ui/settings/component/verification-upload-section.tsx index ebd174a..f301db0 100644 --- a/src/app/ui/settings/component/verification-upload-section.tsx +++ b/src/app/ui/settings/component/verification-upload-section.tsx @@ -5,7 +5,7 @@ import { fileUpload, cancelUpload, chunkUpload, checkChunkStatus, checkOperation import { useTranslations } from 'next-intl'; import { useNavigationBlocker } from '@/app/hooks/useNavigationBlocker'; import { useQueryClient } from '@tanstack/react-query'; -import {useUserProfile} from '@/app/hooks/react-query/useUserDataInfo'; +import { useUserProfile } from '@/app/hooks/react-query/useUserDataInfo'; export interface SelectedFile { file: File; @@ -48,9 +48,9 @@ export default function VerificationUploadSection({ const [isDragging, setIsDragging] = useState(false); const [selectedFiles, setSelectedFiles] = useState([]); const [error, setError] = useState(null); - const [activeUploads, setActiveUploads] = useState>(new Set()); // ID активных загрузок + const [activeUploads, setActiveUploads] = useState>(new Set()); const queryClient = useQueryClient(); - const isCancelledRef = useRef>(new Map()); // Для отслеживания отмен по файлам + const isCancelledRef = useRef>(new Map()); const selectedFilesRef = useRef(selectedFiles); const t = useTranslations('Global'); @@ -62,9 +62,9 @@ export default function VerificationUploadSection({ return allowedExtensions.map(e => `.${e}`).join(', '); }, [allowedExtensions]); - const validateFile = (file: File): { isValid: boolean; errorMessage?: string } => { + const validateFile = (file: File, extension: string | undefined): { isValid: boolean; errorMessage?: string } => { if (!allowedExtensions.includes(file.type as string)) { - const extension = file.name.split('.').pop()?.toLowerCase(); + if (!extension || !allowedExtensions.includes(extension as string)) { return { isValid: false, @@ -127,8 +127,8 @@ export default function VerificationUploadSection({ duplicateNames.push(file.name); continue; } - - const validation = validateFile(file); + const extension = file.name.split('.').pop()?.toLowerCase(); + const validation = validateFile(file, extension); if (!validation.isValid) { setError(prev => prev ? `${prev}, ${validation.errorMessage}` : validation.errorMessage || t('unknown-validation-error')); @@ -139,7 +139,8 @@ export default function VerificationUploadSection({ width: number, height: number, } | undefined = undefined; - if (fileType === "image") { + + if (fileType === "image" && extension !== 'pdf') { try { dimensions = await getImageDimensions(file) as { width: number, height: number }; if (dimensions?.width < 100 || dimensions?.height < 100 || @@ -224,7 +225,6 @@ export default function VerificationUploadSection({ f.uploadId !== fileId && f.name !== fileId )); } else { - console.log('clear all') selectedFiles.forEach(file => { if (file.preview) { URL.revokeObjectURL(file.preview); @@ -247,17 +247,16 @@ export default function VerificationUploadSection({ const uploadSingleFile = async (fileInfo: SelectedFile, uploadType: 'single' | 'multi', isLastFIle: boolean): Promise => { const fileId = `${fileInfo.name}-${Date.now()}`; isCancelledRef.current.set(fileId, false); + setError(null); - if (uploadType === 'single') { - setError(null); + /* if (uploadType === 'single') { const priceCheck = await checkOperationPrice('checkTokensForProtect', 1, fileType); - if (!priceCheck.success) { const errorMessage = `${t('there-are-not-enough-funds-to-protect-file', { count: priceCheck?.tokens_count })}`; setError(errorMessage); return; } - } + } */ try { setSelectedFiles(prev => prev.map(f => @@ -267,7 +266,7 @@ export default function VerificationUploadSection({ const extension = fileInfo.file.name.split('.').pop() || ''; const initMessageBody = { file_name: fileInfo.file.name, - file_type: fileType, + file_type: extension === 'pdf' ? 'document' : fileType, extension: extension, file_size: fileInfo.file.size }; @@ -353,21 +352,15 @@ export default function VerificationUploadSection({ if (selectedFilesRef.current.length === 0) { return; } - const priceCheck = await checkOperationPrice('checkTokensForProtect', selectedFilesRef.current.length, fileType); - if (priceCheck.success) { - const files = selectedFilesRef.current; - const totalFiles = files.length; + const files = selectedFilesRef.current; + const totalFiles = files.length; - for (let i = 0; i < totalFiles; i++) { - const file = files[i]; - const isLastFile = i === totalFiles - 1; + for (let i = 0; i < totalFiles; i++) { + const file = files[i]; + const isLastFile = i === totalFiles - 1; - await uploadSingleFile(file, 'multi', isLastFile); - } - } else { - const errorMessage = `${t('there-are-not-enough-funds-to-protect-files', { count: priceCheck?.tokens_count })}`; - setError(errorMessage); + await uploadSingleFile(file, 'multi', isLastFile); } }, [maxParallelUploads]); @@ -404,7 +397,7 @@ export default function VerificationUploadSection({ return (

- Загрузка изображений удостоверения личности + {t('uploading-id-images')}

< div @@ -413,10 +406,6 @@ export default function VerificationUploadSection({ onDragLeave={handleDragLeave} onDrop={handleDrop} > - {/*

- {t('drag-the-file-here')} -

*/} - { fileType === "image" && (

@@ -427,18 +416,15 @@ export default function VerificationUploadSection({

{t('file-format')}: {acceptString}

- {/* < p className="description" > - {t('file-size')}: {t('to')} {(maxFileSize / 1024 / 1024)} {t('mb')} -

*/} < input ref={fileInputRef} type="file" - accept={acceptString} + accept={`${acceptString}`} style={{ display: 'none' }} onChange={handleFileInputChange} aria-label="Выбор файла для защиты" - multiple // Добавляем multiple для выбора нескольких файлов + multiple /> { @@ -453,22 +439,6 @@ export default function VerificationUploadSection({ selectedFiles.length > 0 && (
- {/*
-

- {t('total-files')}: {selectedFiles.length} - {t('uploading')}: {uploadingCount} - {t('completed')}: {completedCount} -

-
-
-
-
-
*/} -
- - {/* - {file.progress} % - */}
- {/* { - file.status === 'pending' && ( - - ) - } */} - < button className="btn btn-cancel" onClick={() => handleClearFile(file.uploadId || file.name)} @@ -582,7 +508,7 @@ export default function VerificationUploadSection({ type="button" disabled={uploadingCount > maxParallelUploads} > - выберете документ(ы) для загрузки + {t('select-document-to-upload')}
); diff --git a/src/app/ui/settings/setting-user-verification.tsx b/src/app/ui/settings/setting-user-verification.tsx index 7ec7e37..0803db5 100644 --- a/src/app/ui/settings/setting-user-verification.tsx +++ b/src/app/ui/settings/setting-user-verification.tsx @@ -40,7 +40,7 @@ export default function SettingUserVerification() { {userData?.verifiedStatus === 'NOT_VERIFIED' || userData?.verifiedStatus === null ? ( ) : ( diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index a337878..f51df41 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -446,7 +446,9 @@ "claims": "Claims", "complaints": "Complaints", "recent-cases": "Recent cases", - "select-at-least-one-filter": "Select at least one filter" + "select-at-least-one-filter": "Select at least one filter", + "select-document-to-upload": "Select document(s) to upload", + "uploading-id-images": "Uploading ID images" }, "Login-register-form": { "and": "and", diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index f453ea5..b7161f3 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -446,7 +446,9 @@ "claims": "Претензии", "complaints": "Жалобы", "recent-cases": "Недавние дела", - "select-at-least-one-filter": "Выберите хотя бы один фильтр" + "select-at-least-one-filter": "Выберите хотя бы один фильтр", + "select-document-to-upload": "Выберите документ(ы) для загрузки", + "uploading-id-images": "Загрузка изображений удостоверения личности" }, "Login-register-form": { "and": "и",