From 080f9bde6e72218837b43820a1314f6de4989341 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 17 May 2023 16:26:18 +0000 Subject: [PATCH] Users: replacing table with dataGrid && --- src/kitUI/Cart/Cart.tsx | 7 +--- .../dashboard/Content/Support/Chat/Chat.tsx | 40 ++++++++++--------- .../Content/Tariffs/CreateTariff.tsx | 6 +-- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/kitUI/Cart/Cart.tsx b/src/kitUI/Cart/Cart.tsx index 6e00f2e..19835a2 100644 --- a/src/kitUI/Cart/Cart.tsx +++ b/src/kitUI/Cart/Cart.tsx @@ -91,12 +91,9 @@ export default function Cart({ selectedTariffs }: Props) { const cartTariffs = tariffs.filter(tariff => selectedTariffs.includes(tariff.id)); const cartItems = cartTariffs.map(tariff => createCartItem(tariff)); - const loyaltyValue = parseInt(loyaltyField); + let loyaltyValue = parseInt(loyaltyField); - if (!isFinite(loyaltyValue)) { - setErrorMessage("Лояльность не число"); - return; - } + if (!isFinite(loyaltyValue)) loyaltyValue = 0; const cartData = calcCartData({ user: testUser, diff --git a/src/pages/dashboard/Content/Support/Chat/Chat.tsx b/src/pages/dashboard/Content/Support/Chat/Chat.tsx index 7c54da3..8689102 100644 --- a/src/pages/dashboard/Content/Support/Chat/Chat.tsx +++ b/src/pages/dashboard/Content/Support/Chat/Chat.tsx @@ -62,25 +62,29 @@ export default function Chat() { }, [messageApiPage, messagesPerPage, ticketId]); useEffect(function subscribeToMessages() { - if (!ticketId || !token) return; +==== BASE ==== + if (!ticketId) return; - const unsubscribe = subscribeToTicketMessages({ - ticketId, - accessToken: token, - onMessage(event) { - try { - const newMessage = JSON.parse(event.data) as TicketMessage; - console.log("SSE: parsed newMessage:", newMessage); - addOrUpdateMessages([newMessage]); - } catch (error) { - console.log("SSE: couldn't parse:", event.data); - console.log("Error parsing message SSE", error); - } - }, - onError(event) { - console.log("SSE Error:", event); - }, - }); + if (!token) return; + + const unsubscribe = subscribeToTicketMessages({ + ticketId, + accessToken: token, + onMessage(event) { + try { + const newMessage = JSON.parse(event.data) as TicketMessage; + console.log("SSE: parsed newMessage:", newMessage); + addOrUpdateMessages([newMessage]); + } catch (error) { + console.log("SSE: couldn't parse:", event.data); + console.log("Error parsing message SSE", error); + } + }, + onError(event) { + console.log("SSE Error:", event); + }, + }); +==== BASE ==== return () => { unsubscribe(); diff --git a/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx b/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx index 805b03f..18de89d 100644 --- a/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx +++ b/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx @@ -19,7 +19,7 @@ export default function CreateTariff() { function handleCreateTariffClick() { const amount = Number(amountField); - const customPricePerUnit = Number(customPriceField); + const customPrice = Number(customPriceField); if (isNaN(amount) || !privilege) return; @@ -28,7 +28,7 @@ export default function CreateTariff() { name: nameField, amount, privilege, - customPricePerUnit: customPricePerUnit ? customPricePerUnit : undefined, + customPricePerUnit: customPrice ? customPrice / amount : undefined, }; addTariffs([newTariff]); @@ -117,7 +117,7 @@ export default function CreateTariff() { /> setCustomPriceField(e.target.value)} type="number"