edit errors message

This commit is contained in:
smanylov
2025-12-25 17:24:59 +07:00
parent e82d96a44c
commit 49088e5e5f
5 changed files with 57 additions and 22 deletions
-1
View File
@@ -66,7 +66,6 @@ export async function fileUpload(messageBody: initMessageBody) {
export async function cancelUpload(udloadId: string) {
try {
console.log('cancelUpload start');
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
method: 'POST',
body: JSON.stringify({
+19 -19
View File
@@ -100,7 +100,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
if (!extension || !ALLOWED_EXTENSIONS.includes(extension as string)) {
return {
isValid: false,
errorMessage: 'Неподдерживаемый формат файла.'
errorMessage: t('unsupported-file-format')
};
}
}
@@ -110,7 +110,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
if (file.size > MAX_SIZE) {
return {
isValid: false,
errorMessage: 'Файл слишком большой. Максимальный размер: 1000MB'
errorMessage: t('the-file-is-too-large')
};
}
@@ -133,7 +133,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
img.onerror = () => {
URL.revokeObjectURL(objectUrl);
reject(new Error('Не удалось загрузить фаил'));
reject(new Error(t('error-uploading-file')));
};
img.src = objectUrl;
@@ -151,7 +151,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
const validation = validateFile(file);
if (!validation.isValid) {
setError(validation.errorMessage || 'Неизвестная ошибка валидации');
setError(validation.errorMessage || t('unknown-validation-error'));
return;
}
@@ -163,7 +163,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
dimensions = await getImageDimensions(file) as { width: number, height: number };
if (dimensions.width < 150 || dimensions.height < 150 ||
dimensions.width > 10000 || dimensions.height > 10000) {
setError(`Размер изображения: ${dimensions.width}x${dimensions.height}. Допустимый диапазон: 150x150 - 10000x10000 пикселей.`);
setError(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 150x150 - 10000x10000 ${t('pixels')}.`);
return;
}
@@ -188,7 +188,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
});
} catch (err) {
setError(err instanceof Error ? err.message : 'Ошибка при обработке файла');
setError(t('error-processing-file'));
}
}, []);
@@ -276,7 +276,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
const chunkResponse = await chunkUpload(formData);
if (chunkResponse.message_desc !== 'Chunk uploaded successfully') {
throw 'Er1'
throw 'Er1: response error'
}
if (chunkIndex === totalChunks - 1) {
@@ -285,7 +285,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
setUploadId(null);
setIsFileUploaded(true);
} else {
throw 'Er2'
throw 'Er2: not all chunks was uploaded'
}
}
@@ -298,12 +298,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
);
}
} catch (error) {
setError('Chunk uploaded error ' + error);
setError(t('error-uploading-file'));
console.error('Chunk upload error:', error);
}
} else {
console.log(response);
setError('file uploaded error');
console.error(response);
setError(t('error-uploading-file'));
}
}
@@ -391,14 +391,14 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{fileType === "image" && (
<p className="description">
Разрешение изображение: 100x100 - 10000x10000
{t('image-resolution')}: 100x100 - 10000x10000
</p>
)}
<p className="description">
Размер файла: до {(maxFileSize / 1024 / 1024)} МБ
{t('file-size')}: {t('to')} {(maxFileSize / 1024 / 1024)} {t('mb')}
</p>
<p className="description">
Формат файла: {ALLOWED_EXTENSIONS.join(', ')}
{t('file-format')}: {ALLOWED_EXTENSIONS.join(', ')}
</p>
{error && (
@@ -409,7 +409,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{selectedFile && (
<div
className="selected-file"
className={`selected-file ${isFileUploaded ? 'done' : ''}`}
>
<div className="selected-file-file-info">
<div>
@@ -424,10 +424,10 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
</span> {selectedFile.size}
</p>
<p className="text-gray-700">
<span className="font-medium">Стоимость защиты:</span> 0
<span className="font-medium">{t('cost-of-protection')}:</span> 0
</p>
<p className="text-gray-700">
<span className="font-medium">Текущий баланс:</span> 0
<span className="font-medium">{t('current-balance')}:</span> 0
</p>
</div>
<div>
@@ -457,12 +457,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{isFileUploaded ? t('close') : t('cancel')}
</button>
<button
className={`btn btn-confirm ${error ? 'disabled' : ''}`}
className={`btn btn-confirm ${error || isFileUploaded ? 'disabled' : ''}`}
onClick={() => {
handlerFileUpload(selectedFile);
}}
type="button"
disabled={error ? true : false}
disabled={error || isFileUploaded ? true : false}
>
{t('upload-file')}
</button>
+6
View File
@@ -489,6 +489,12 @@
border-radius: 15px;
background: #fff;
padding: 10px;
border: 2px solid transparent;
transition: all 0.3s ease-in;
&.done {
border-color: #00a63e;
}
&-file-info {
text-align: left;
+16 -1
View File
@@ -129,7 +129,22 @@
"upload-for-protection": "Upload {fileType} for protection",
"image": "image",
"file-has-no-extension": "File has no extension",
"have-unsaved-changes": "You have unsaved changes. Are you sure you want to delete this page?"
"have-unsaved-changes": "You have unsaved changes. Are you sure you want to delete this page?",
"image-size": "Image size",
"acceptable-range": "Acceptable range",
"pixels": "pixels",
"error-processing-file": "Error processing file",
"error-uploading-file": "Error uploading file",
"unknown-validation-error": "Unknown validation error",
"unsupported-file-format": "Unsupported file format.",
"the-file-is-too-large": "The file is too large",
"cost-of-protection": "Cost of protection",
"current-balance": "Current balance",
"image-resolution": "Image resolution",
"file-size": "File size",
"file-format": "File format",
"mb": "MB",
"to": "to"
},
"Login-register-form": {
"and": "and",
+16 -1
View File
@@ -129,7 +129,22 @@
"upload-for-protection": "Загрузить {fileType} для защиты",
"image": "изображений",
"file-has-no-extension": "Файл не имеет расширения",
"have-unsaved-changes": "У вас есть несохраненные изменения. Вы уверены, что хотите покинуть страницу?"
"have-unsaved-changes": "У вас есть несохраненные изменения. Вы уверены, что хотите покинуть страницу?",
"image-size": "Размер изображения",
"acceptable-range": "Допустимый диапазон",
"pixels": "пикселей",
"error-processing-file": "Ошибка при обработке файла",
"error-uploading-file": "Ошибка при загрузке файла",
"unknown-validation-error": "Неизвестная ошибка валидации",
"unsupported-file-format": "Неподдерживаемый формат файла.",
"the-file-is-too-large": "Файл слишком большой",
"cost-of-protection": "Стоимость защиты",
"current-balance": "Текущий баланс",
"image-resolution": "Разрешение изображение",
"file-size": "Размер файла",
"file-format": "Формат файла",
"mb": "МБ",
"to": "до"
},
"Login-register-form": {
"and": "и",