From 5c3af0e007d7d2c2b258a981a03c94b7b00304c1 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Tue, 25 Aug 2026 13:42:10 +0300 Subject: [PATCH] Added znzt web app --- src/pages/OrdersPage.tsx | 104 +++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/src/pages/OrdersPage.tsx b/src/pages/OrdersPage.tsx index 18fde17..4791495 100644 --- a/src/pages/OrdersPage.tsx +++ b/src/pages/OrdersPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useMemo, useCallback } from 'react' import { Box, Table, Title, Text, Paper, Stack, Button, Group, NumberInput, Select, Textarea, Badge, LoadingOverlay, Card, Divider @@ -31,7 +31,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { const matrix = res.data setData(matrix) - // Если настройки есть, инициализируем заказы if (matrix && matrix.clients) { const initialMap: Record = {} matrix.clients.forEach((c, idx) => { @@ -68,7 +67,8 @@ export default function OrdersPage({ onError }: OrdersPageProps) { loadData(false) }, []) - const handleQuantityChange = (clientName: string, nomName: string, nomType: string, qty: number | null) => { + // Оптимизированный хендлер изменения количества с useCallback + const handleQuantityChange = useCallback((clientName: string, nomName: string, nomType: string, qty: number | null) => { setEditableOrders(prev => { const currentOrder = prev[clientName] || { client_name: clientName, items: [] } const items = [...(currentOrder.items || [])] @@ -89,7 +89,7 @@ export default function OrdersPage({ onError }: OrdersPageProps) { [clientName]: { ...currentOrder, items } } }) - } + }, []) const validateBeforeSave = (): boolean => { for (const [clientName, order] of Object.entries(editableOrders)) { @@ -132,19 +132,7 @@ export default function OrdersPage({ onError }: OrdersPageProps) { ); } - // Обработка случая, когда настройки еще не внесены аналитиком (settings === null) - if (!data) { - return ( - - - ⚠️ Ожидание настроек - - Аналитик еще не внес настройки текущего месяца. Пожалуйста, дождитесь установки дедлайна, после чего таблица станет доступна. - - - - ); - } + if (!data) return Нет данных return ( @@ -197,7 +185,7 @@ export default function OrdersPage({ onError }: OrdersPageProps) { )} ) : ( - + @@ -219,35 +207,14 @@ export default function OrdersPage({ onError }: OrdersPageProps) { {data.nomenclatures?.map(nom => ( - - - {nom.name} ({nom.type}) - - {data.clients?.map(c => { - 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 : '' - - return ( - - handleQuantityChange( - clientName, - nom.name, - nom.type, - val === '' ? null : Number(val) - )} - min={0} - size="xs" - styles={{ input: { textAlign: 'center' } }} - /> - - ) - })} - + ))}
@@ -257,6 +224,49 @@ export default function OrdersPage({ onError }: OrdersPageProps) { ) } +// 🚀 Мемоизированная строка таблицы для устранения лагов при вводе +interface MemoizedTableRowProps { + nom: NomenclatureItem; + clients: any[]; + editableOrders: Record; + isLocked: boolean; + handleQuantityChange: (clientName: string, nomName: string, nomType: string, qty: number | null) => void; +} + +const MemoizedTableRow = React.memo(({ nom, clients, editableOrders, isLocked, handleQuantityChange }: MemoizedTableRowProps) => { + return ( + + + {nom.name} ({nom.type}) + + {clients.map(c => { + 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 : '' + + return ( + + handleQuantityChange( + clientName, + nom.name, + nom.type, + val === '' ? null : Number(val) + )} + min={0} + size="xs" + styles={{ input: { textAlign: 'center' } }} + /> + + ) + })} + + ); +}); + interface BlockMetaProps { clientName: string editableOrders: Record