This commit is contained in:
dev.daminik00 2025-09-19 01:07:22 +02:00
parent f3872e7ce1
commit f6117d8b91
4 changed files with 57 additions and 10 deletions

View File

@ -20,3 +20,18 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.sendButtonWrapper {
position: relative;
width: 40px;
height: 40px;
}
.disabledOverlay {
position: absolute;
inset: 0;
border-radius: 50%;
z-index: 1;
background: transparent;
cursor: pointer;
}

View File

@ -10,11 +10,13 @@ import styles from "./MessageInput.module.scss";
interface MessageInputProps { interface MessageInputProps {
onSend: (message: string) => void; onSend: (message: string) => void;
disabled?: boolean; disabled?: boolean;
onDisabledClick?: () => void;
} }
export default function MessageInput({ export default function MessageInput({
onSend, onSend,
disabled = false, disabled = false,
onDisabledClick,
}: MessageInputProps) { }: MessageInputProps) {
const t = useTranslations("Chat"); const t = useTranslations("Chat");
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
@ -28,6 +30,12 @@ export default function MessageInput({
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter") { if (e.key === "Enter") {
// If disabled (e.g., zero balance), open refill modal instead of sending
if (!e.ctrlKey && disabled) {
e.preventDefault();
onDisabledClick?.();
return;
}
if (e.ctrlKey) { if (e.ctrlKey) {
// Ctrl + Enter - добавляем перенос строки // Ctrl + Enter - добавляем перенос строки
e.preventDefault(); e.preventDefault();
@ -59,14 +67,24 @@ export default function MessageInput({
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
maxRows={5} maxRows={5}
/> />
<Button <div className={styles.sendButtonWrapper}>
onClick={handleSend} {/* Capture clicks when disabled to open refill modal */}
disabled={!message.trim() || disabled} {disabled && typeof onDisabledClick === "function" && (
aria-label="Send" <div
className={styles.sendButton} className={styles.disabledOverlay}
> onClick={onDisabledClick}
<Icon name={IconName.PaperAirplane} size={{ height: 14, width: 14 }} /> aria-hidden
</Button> />
)}
<Button
onClick={handleSend}
disabled={!message.trim() || disabled}
aria-label="Send"
className={styles.sendButton}
>
<Icon name={IconName.PaperAirplane} size={{ height: 14, width: 14 }} />
</Button>
</div>
</div> </div>
); );
} }

View File

@ -1,5 +1,6 @@
"use client"; "use client";
import { useShowRefillModal } from "@/hooks/refill/useShowRefillModal";
import { useChat } from "@/providers/chat-provider"; import { useChat } from "@/providers/chat-provider";
import { MessageInput } from ".."; import { MessageInput } from "..";
@ -7,15 +8,26 @@ import { MessageInput } from "..";
import styles from "./MessageInputWrapper.module.scss"; import styles from "./MessageInputWrapper.module.scss";
export default function MessageInputWrapper() { export default function MessageInputWrapper() {
const { send, balance } = useChat(); const { send, balance, chatId } = useChat();
const { showRefillModal } = useShowRefillModal();
// Блокируем отправку сообщений при нулевом или отрицательном балансе // Блокируем отправку сообщений при нулевом или отрицательном балансе
const disabled = (balance?.balance ?? 0) <= 0; const disabled = (balance?.balance ?? 0) <= 0;
const handleDisabledClick = () => {
if (disabled && chatId) {
showRefillModal(chatId);
}
};
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div className={styles.inputWrapper}> <div className={styles.inputWrapper}>
<MessageInput onSend={send} disabled={disabled} /> <MessageInput
onSend={send}
disabled={disabled}
onDisabledClick={handleDisabledClick}
/>
</div> </div>
</div> </div>
); );

View File

@ -345,6 +345,7 @@ export const useChatSocket = (
return useMemo( return useMemo(
() => ({ () => ({
chatId,
messages, messages,
balance, balance,
session, session,
@ -368,6 +369,7 @@ export const useChatSocket = (
hasMoreOlderMessages, hasMoreOlderMessages,
}), }),
[ [
chatId,
messages, messages,
balance, balance,
session, session,