Skip to content

Commit d521a95

Browse files
committed
fix(chat): keep the draft when the plan gate refuses a send
1 parent 791f6c7 commit d521a95

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { InputToolbar } from '@/app/workspace/[workspaceId]/home/components/user
3535
import type { ModelSelectorOptions } from '@/app/workspace/[workspaceId]/home/components/user-input/components/model-selector'
3636
import { usePromptHistory } from '@/app/workspace/[workspaceId]/home/components/user-input/hooks/use-prompt-history'
3737
import { handleMothershipAddContextEvent } from '@/app/workspace/[workspaceId]/home/components/user-input/mothership-context-event'
38+
import { useChatPlanGate } from '@/app/workspace/[workspaceId]/home/hooks/use-chat-plan-gate'
3839
import type {
3940
ChatMessage,
4041
FileAttachmentForApi,
@@ -507,6 +508,9 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
507508
textareaRef.current?.focus()
508509
}
509510

511+
/** Refuses a send the workspace plan excludes here, before `onSubmit`, so the draft survives. */
512+
const stopSendWithoutChatPlan = useChatPlanGate()
513+
510514
/** Empties the text, chips, attachments, transcript, and the saved draft in one step. */
511515
const clearComposer = useCallback(() => {
512516
history.reset()
@@ -527,6 +531,7 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
527531
}, [resetTranscript, history.reset])
528532

529533
const handleSubmit = useCallback(() => {
534+
if (stopSendWithoutChatPlan()) return
530535
const currentFiles = filesRef.current
531536
const currentEditor = editorRef.current
532537

@@ -552,7 +557,7 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
552557
)
553558
if (accepted === false) return
554559
clearComposer()
555-
}, [onSubmit, clearComposer])
560+
}, [stopSendWithoutChatPlan, onSubmit, clearComposer])
556561

557562
/**
558563
* Enter policy for the editor: mirror canSubmit's uploading guard (Enter

‎apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat-plan-gate.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

33
import { useCallback } from 'react'
4-
import { useToast } from '@sim/emcn'
4+
import { toast } from '@sim/emcn'
55
import { useRouter } from 'next/navigation'
66
import { useSession } from '@/lib/auth/client'
77
import { CHAT_PLAN_REQUIRED_MESSAGE } from '@/lib/billing/chat-plan'
@@ -25,7 +25,6 @@ export function useChatPlanGate(): () => boolean {
2525
const { data: session } = useSession()
2626
const viewerId = session?.user?.id
2727
const router = useRouter()
28-
const { toast } = useToast()
2928

3029
return useCallback(() => {
3130
if (!hostContext || hostContext.features?.chat !== false) return false
@@ -40,5 +39,5 @@ export function useChatPlanGate(): () => boolean {
4039
)
4140
}
4241
return true
43-
}, [hostContext, viewerId, router, toast])
42+
}, [hostContext, viewerId, router])
4443
}

0 commit comments

Comments
 (0)