import React, { forwardRef } from 'react'; import { useWatch } from 'react-hook-form'; import type { TRealtimeEphemeralTokenResponse } from 'librechat-data-provider'; import type { Control } from 'react-hook-form'; import { useRealtimeEphemeralTokenMutation } from '~/data-provider'; import { TooltipAnchor, SendIcon, CallIcon } from '~/components'; import { useToastContext } from '~/Providers/ToastContext'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; type ButtonProps = { disabled: boolean; control: Control<{ text: string }>; }; const ActionButton = forwardRef( ( props: { disabled: boolean; icon: React.ReactNode; tooltip: string; testId: string; onClick?: () => void; }, ref: React.ForwardedRef, ) => { return ( {props.icon} } /> ); }, ); const SendButton = forwardRef((props: ButtonProps, ref: React.ForwardedRef) => { const localize = useLocalize(); const { showToast } = useToastContext(); const { text = '' } = useWatch({ control: props.control }); const { mutate: startCall, isLoading: isProcessing } = useRealtimeEphemeralTokenMutation({ onSuccess: async (data: TRealtimeEphemeralTokenResponse) => { showToast({ message: 'IT WORKS!!', status: 'success', }); }, onError: (error: unknown) => { showToast({ message: localize('com_nav_audio_process_error', (error as Error).message), status: 'error', }); }, }); const handleClick = () => { if (text.trim() === '') { startCall({ voice: 'verse' }); } }; const buttonProps = text.trim() !== '' ? { icon: , tooltip: localize('com_nav_send_message'), testId: 'send-button', } : { icon: , tooltip: localize('com_nav_call'), testId: 'call-button', onClick: handleClick, }; return ; }); SendButton.displayName = 'SendButton'; export default SendButton;