diff --git a/src/pages/OrdersPage.tsx b/src/pages/OrdersPage.tsx index 2d344f0..a0d6488 100644 --- a/src/pages/OrdersPage.tsx +++ b/src/pages/OrdersPage.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useCallback } from 'react' import { Box, Table, Title, Text, Paper, Stack, Button, Group, - NumberInput, Select, Textarea, Badge, LoadingOverlay, Card, Divider + Select, Textarea, Badge, LoadingOverlay, Card, Divider } from '@mantine/core' import { useMediaQuery } from '@mantine/hooks' import { notifications } from '@mantine/notifications' @@ -67,7 +67,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { loadData(false) }, []) - // Оптимизированный хендлер изменения количества с useCallback const handleQuantityChange = useCallback((clientName: string, nomName: string, nomType: string, qty: number | null) => { setEditableOrders(prev => { const currentOrder = prev[clientName] || { client_name: clientName, items: [] } @@ -224,7 +223,7 @@ export default function OrdersPage({ onError }: OrdersPageProps) { ) } -// 🚀 Мемоизированная строка таблицы для устранения лагов при вводе +// 🚀 Мемоизированная строка с ультрабыстрыми нативными инпутами interface MemoizedTableRowProps { nom: NomenclatureItem; clients: any[]; @@ -243,22 +242,32 @@ const MemoizedTableRow = React.memo(({ nom, clients, editableOrders, isLocked, h const clientName = c.google_data.name const order = editableOrders[clientName] const item = order?.items?.find(i => i.nomenclature_name === nom.name) - const qty = item ? item.quantity : '' + const qty = item && item.quantity !== null ? item.quantity : '' return ( - handleQuantityChange( - clientName, - nom.name, - nom.type, - val === '' ? null : Number(val) - )} + value={qty} min={0} - size="xs" - styles={{ input: { textAlign: 'center' } }} + onChange={(e) => { + const val = e.target.value; + handleQuantityChange( + clientName, + nom.name, + nom.type, + val === '' ? null : Number(val) + ); + }} + style={{ + width: '70px', + textAlign: 'center', + padding: '4px', + borderRadius: '4px', + border: '1px solid #ced4da', + backgroundColor: isLocked ? '#f1f3f5' : '#fff' + }} /> ) @@ -352,7 +361,7 @@ function ClientCardView({ clientName, nomenclatures, editableOrders, setEditable {nomenclatures.map((nom) => { const item = order?.items?.find((i) => i.nomenclature_name === nom.name) - const qty = item ? item.quantity : '' + const qty = item && item.quantity !== null ? item.quantity : '' return ( @@ -360,19 +369,28 @@ function ClientCardView({ clientName, nomenclatures, editableOrders, setEditable {nom.name} {nom.type} - handleQuantityChange( - clientName, - nom.name, - nom.type, - val === '' ? null : Number(val) - )} + value={qty} min={0} - size="sm" - style={{ width: 100 }} - styles={{ input: { textAlign: 'center' } }} + onChange={(e) => { + const val = e.target.value; + handleQuantityChange( + clientName, + nom.name, + nom.type, + val === '' ? null : Number(val) + ); + }} + style={{ + width: '80px', + textAlign: 'center', + padding: '6px', + borderRadius: '4px', + border: '1px solid #ced4da', + backgroundColor: isLocked ? '#f1f3f5' : '#fff' + }} /> )