Update files input
Deploy Manager App / deploy (push) Failing after 23s Details

This commit is contained in:
romanskijdev 2026-09-25 17:06:11 +03:00
parent 3997f7dffb
commit 01142fd310
1 changed files with 65 additions and 8 deletions

View File

@ -156,6 +156,49 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
}))
}, [isReadOnly]);
// Вспомогательная функция для конвертации File в Base64
const toBase64 = (file: File) => new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result as string);
reader.onerror = error => reject(error);
});
// Обработчик мультизагрузки файлов
const handleFilesChange = async (clientName: string, event: React.ChangeEvent<HTMLInputElement>) => {
const files = event.target.files;
if (!files || files.length === 0) return;
const newFiles = [];
for (let i = 0; i < files.length; i++) {
const file = files[i];
const base64 = await toBase64(file);
// Отрезаем префикс "data:image/png;base64,", оставляя только чистый Base64 для бэкенда
const base64Data = base64.split(',')[1] || base64;
newFiles.push({ file_name: file.name, file_base64: base64Data });
}
setEditableOrders(prev => {
const currentOrder = prev[clientName] || {};
const existingFiles = currentOrder.files || [];
return {
...prev,
[clientName]: {
...currentOrder,
files: [...existingFiles, ...newFiles] // Добавляем новые к уже существующим
}
};
});
notifications.show({
title: 'Файлы добавлены',
message: `Прикреплено новых скринов: ${newFiles.length}`,
color: 'blue'
});
// Очищаем value инпута, чтобы можно было выбрать те же файлы повторно при необходимости
event.target.value = '';
};
const handleSave = async () => {
if (isReadOnly) return;
@ -430,28 +473,42 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
</Text>
<Group gap={4} wrap="nowrap">
{/* Скрытый инпут для прикрепления файла-скрина */}
{/* Скрытый инпут для мультизагрузки файлов */}
<input
type="file"
multiple
accept="image/*"
id={`file-${clientName}`}
style={{ display: 'none' }}
onChange={(e) => {
const file = e.target.files?.[0];
if (file) {
notifications.show({ title: 'Файл выбран', message: `Скрин для ${clientName}: ${file.name}`, color: 'blue' });
}
}}
disabled={inputsDisabled}
onChange={(e) => handleFilesChange(clientName, e)}
/>
<ActionIcon
variant="light"
color={order?.files && order.files.length > 0 ? "teal" : "gray"}
size="sm"
title="Прикрепить скрин подтверждения заказа"
title="Прикрепить скрин(ы) подтверждения"
disabled={inputsDisabled}
onClick={() => document.getElementById(`file-${clientName}`)?.click()}
>
<IconPaperclip size={14} />
</ActionIcon>
{/* Бейдж с количеством файлов (и возможностью их очистить по клику) */}
{order?.files && order.files.length > 0 && (
<Badge
size="sm"
color="teal"
variant="filled"
style={{ cursor: inputsDisabled ? 'default' : 'pointer' }}
title="Кликните, чтобы очистить прикрепленные файлы"
onClick={() => !inputsDisabled && updateClientMeta(clientName, 'files', null)}
>
{order.files.length}
</Badge>
)}
<ClientSettingsPopover
clientName={clientName}
order={order}