From e968e5c7ee286ceae1ca5e3c107d3ec049bf078a Mon Sep 17 00:00:00 2001 From: Tamara Date: Sun, 10 Mar 2024 01:05:54 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B8=D0=BF=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82?= =?UTF-8?q?=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui_kit/FloatingSupportChat/Chat.tsx | 72 +++++++++++------ .../FloatingSupportChat/SwithChatMassage.tsx | 81 ------------------- 2 files changed, 48 insertions(+), 105 deletions(-) delete mode 100644 src/ui_kit/FloatingSupportChat/SwithChatMassage.tsx diff --git a/src/ui_kit/FloatingSupportChat/Chat.tsx b/src/ui_kit/FloatingSupportChat/Chat.tsx index cb41347d..9d09ee21 100644 --- a/src/ui_kit/FloatingSupportChat/Chat.tsx +++ b/src/ui_kit/FloatingSupportChat/Chat.tsx @@ -27,7 +27,8 @@ import ArrowLeft from "@icons/questionsPage/arrowLeft"; import { useUserStore } from "@root/user"; import AttachFileIcon from "@mui/icons-material/AttachFile"; import ChatImage from "./ChatImage"; -import SwitchChatMassage from "@ui_kit/FloatingSupportChat/SwithChatMassage"; +import ChatDocument from "@ui_kit/FloatingSupportChat/ChatDocument"; +import * as React from "react"; interface Props { open: boolean; @@ -37,6 +38,12 @@ interface Props { sendFile: (a: File | undefined) => Promise; } +const fileTypes = { + picture: [".jpg", ".png"], + video: [".mp4"], + document: [".doc", ".docx", ".pdf", ".txt", ".xlsx", ".csv"], +}; + export default function Chat({ open = false, sx, @@ -205,30 +212,47 @@ export default function Chat({ > {ticket.sessionData?.ticketId && messages.map((message) => { - // if (message.files !== null && message.files.length > 0) { - // return - // } else { - // return - // } - return ( - { + if (message.files.name) { + fileTypes.picture.some((fileType) => + message.files.name.toLowerCase().endsWith(fileType), + ); + } + }; + const isFileDocument = () => { + if (message.files.name) { + fileTypes.document.some((fileType) => + message.files.name.toLowerCase().endsWith(fileType), + ); + } + }; + console.log(message) + if (message.files.length > 0 && isFileImage) { + return - ); + } + if (message.files.length > 0 && isFileDocument) { + return + } else { + return + } })} diff --git a/src/ui_kit/FloatingSupportChat/SwithChatMassage.tsx b/src/ui_kit/FloatingSupportChat/SwithChatMassage.tsx deleted file mode 100644 index 8840441a..00000000 --- a/src/ui_kit/FloatingSupportChat/SwithChatMassage.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { Typography } from "@mui/material"; -import * as React from "react"; -import { useState } from "react"; -import ChatImage from "@ui_kit/FloatingSupportChat/ChatImage"; -import ChatMessage from "@ui_kit/FloatingSupportChat/ChatMessage"; -import ChatDocument from "@ui_kit/FloatingSupportChat/ChatDocument"; - -interface Props { - message: any; - ticket: any; - user: string | undefined; -} - -const fileTypes = { - picture: [".jpg", ".png"], - video: [".mp4"], - document: [".doc", ".docx", ".pdf", ".txt", ".xlsx", ".csv"], -}; - -export default function SwitchChatMassage({ message, ticket, user }: Props) { - const [typeMassage, setTypeMassage] = useState(""); - const isFileImage = () => { - if (message.files.name) { - fileTypes.picture.some((fileType) => - message.files.name.toLowerCase().endsWith(fileType), - ); - } - }; - const isFileDocument = () => { - if (message.files.name) { - fileTypes.document.some((fileType) => - message.files.name.toLowerCase().endsWith(fileType), - ); - } - }; - - if (message.files === null) { - setTypeMassage("massage"); - } - if (message.files !== null && isFileImage && message.files.length !== 0) { - setTypeMassage("image"); - } - if (message.files !== null && isFileDocument && message.files.length !== 0) { - setTypeMassage("document"); - } - console.log("working?", typeMassage); - switch (typeMassage) { - case "image": - return ( - - ); - case "massage": - return ( - - ); - case "document": - return ( - - ); - default: - return <>; - } -}