renamed operator, added subtitle with working hours, added greeting message to the chat, fixted scroll
This commit is contained in:
parent
681969d9fc
commit
c8882ef5bd
@ -12,43 +12,47 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import makeRequest from "@api/makeRequest"
|
import makeRequest from "@api/makeRequest"
|
||||||
import {
|
import {
|
||||||
TicketMessage,
|
|
||||||
useTicketsFetcher,
|
|
||||||
useTicketMessages,
|
|
||||||
getMessageFromFetchError,
|
|
||||||
useSSESubscription,
|
|
||||||
createTicket,
|
createTicket,
|
||||||
|
getMessageFromFetchError,
|
||||||
|
throttle,
|
||||||
|
TicketMessage,
|
||||||
|
useSSESubscription,
|
||||||
|
useTicketMessages,
|
||||||
|
useTicketsFetcher,
|
||||||
} from "@frontend/kitui";
|
} from "@frontend/kitui";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import {enqueueSnackbar} from "notistack";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import type {TouchEvent, WheelEvent} from "react";
|
||||||
|
import {useCallback, useEffect, useMemo, useRef, useState} from "react";
|
||||||
import ChatMessage from "../ChatMessage";
|
import ChatMessage from "../ChatMessage";
|
||||||
import SendIcon from "../icons/SendIcon";
|
import SendIcon from "../icons/SendIcon";
|
||||||
import ArrowLeft from "@root/assets/Icons/arrowLeft";
|
import ArrowLeft from "@root/assets/Icons/arrowLeft";
|
||||||
import UserCircleIcon from "./UserCircleIcon";
|
import UserCircleIcon from "./UserCircleIcon";
|
||||||
import { throttle } from "@frontend/kitui";
|
import {sendTicketMessage, shownMessage} from "@root/api/ticket";
|
||||||
import { sendTicketMessage, shownMessage } from "@root/api/ticket";
|
import {useSSETab} from "@root/utils/hooks/useSSETab";
|
||||||
import { useSSETab } from "@root/utils/hooks/useSSETab";
|
|
||||||
import {
|
import {
|
||||||
|
ACCEPT_SEND_MEDIA_TYPES_MAP,
|
||||||
checkAcceptableMediaType,
|
checkAcceptableMediaType,
|
||||||
MAX_FILE_SIZE,
|
MAX_FILE_SIZE,
|
||||||
ACCEPT_SEND_MEDIA_TYPES_MAP,
|
|
||||||
} from "@utils/checkAcceptableMediaType";
|
} from "@utils/checkAcceptableMediaType";
|
||||||
import {
|
import {
|
||||||
useTicketStore,
|
|
||||||
setTicketData,
|
|
||||||
addOrUpdateUnauthMessages,
|
addOrUpdateUnauthMessages,
|
||||||
setUnauthTicketMessageFetchState,
|
|
||||||
setUnauthIsPreventAutoscroll,
|
|
||||||
incrementUnauthMessage,
|
incrementUnauthMessage,
|
||||||
setIsMessageSending,
|
setIsMessageSending,
|
||||||
|
setTicketData,
|
||||||
|
setUnauthIsPreventAutoscroll,
|
||||||
|
setUnauthTicketMessageFetchState,
|
||||||
|
useTicketStore,
|
||||||
} from "@root/stores/tickets";
|
} from "@root/stores/tickets";
|
||||||
import { useUserStore } from "@root/stores/user";
|
import {useUserStore} from "@root/stores/user";
|
||||||
import AttachFileIcon from "@mui/icons-material/AttachFile";
|
import AttachFileIcon from "@mui/icons-material/AttachFile";
|
||||||
import ChatDocument from "./ChatDocument";
|
import ChatDocument from "./ChatDocument";
|
||||||
import ChatImage from "./ChatImage";
|
import ChatImage from "./ChatImage";
|
||||||
import ChatVideo from "./ChatVideo";
|
import ChatVideo from "./ChatVideo";
|
||||||
|
|
||||||
import type { WheelEvent, TouchEvent } from "react";
|
const workingHoursMessage =
|
||||||
|
"Здравствуйте, задайте ваш вопрос и наш оператор вам ответит в течение 10 минут";
|
||||||
|
const offHoursMessage =
|
||||||
|
"Здравствуйте, к сожалению, сейчас операторы не работают. Задайте ваш вопрос, и вам ответят в 10:00 по московскому времени";
|
||||||
|
|
||||||
type ModalWarningType =
|
type ModalWarningType =
|
||||||
| "errorType"
|
| "errorType"
|
||||||
@ -178,6 +182,35 @@ export default function Chat({ open = false, onclickArrow, sx }: Props) {
|
|||||||
[fetchState]
|
[fetchState]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const date = new Date();
|
||||||
|
const currentHourUTC = date.getUTCHours();
|
||||||
|
const MscTime = 3; // Москва UTC+3;
|
||||||
|
const moscowHour = (currentHourUTC + MscTime) % 24;
|
||||||
|
const greetingMessage =
|
||||||
|
moscowHour >= 10 && moscowHour < 15
|
||||||
|
? workingHoursMessage
|
||||||
|
: offHoursMessage;
|
||||||
|
|
||||||
|
const greetingMessageObj = {
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
files: [],
|
||||||
|
id: "111ck2tepkvc9g6irk3fugg",
|
||||||
|
message: greetingMessage,
|
||||||
|
request_screenshot: "",
|
||||||
|
session_id: "111",
|
||||||
|
shown: { me: 1 },
|
||||||
|
ticket_id: "111",
|
||||||
|
user_id: "111",
|
||||||
|
};
|
||||||
|
|
||||||
|
addOrUpdateUnauthMessages([greetingMessageObj]);
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function scrollOnNewMessage() {
|
function scrollOnNewMessage() {
|
||||||
if (!chatBoxRef.current) return;
|
if (!chatBoxRef.current) return;
|
||||||
@ -369,7 +402,7 @@ export default function Chat({ open = false, onclickArrow, sx }: Props) {
|
|||||||
gap: "3px",
|
gap: "3px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography>Мария</Typography>
|
<Typography>Данила</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: "16px",
|
fontSize: "16px",
|
||||||
@ -378,6 +411,14 @@ export default function Chat({ open = false, onclickArrow, sx }: Props) {
|
|||||||
>
|
>
|
||||||
онлайн-консультант
|
онлайн-консультант
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "16px",
|
||||||
|
lineHeight: "19px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
время работы 10:00-3:00 по мск
|
||||||
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
|
Loading…
Reference in New Issue
Block a user