Skip to content

Commit 37cd395

Browse files
committed
fix(chat-deploy): fix stale AuthSelector state, stabilize refetch ref, clean up copy timeout
1 parent 4baf944 commit 37cd395

File tree

2 files changed

+19
-8
lines changed
  • apps/sim
    • app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat
    • hooks/queries

2 files changed

+19
-8
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat/chat.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export function ChatDeploy({
121121
const [formData, setFormData] = useState<ChatFormData>(initialFormData)
122122
const [errors, setErrors] = useState<FormErrors>({})
123123
const formRef = useRef<HTMLFormElement>(null)
124+
const [formInitCounter, setFormInitCounter] = useState(0)
124125

125126
const createChatMutation = useCreateChat()
126127
const updateChatMutation = useUpdateChat()
@@ -272,6 +273,7 @@ export function ChatDeploy({
272273

273274
await onRefetchChat()
274275
setHasInitializedForm(false)
276+
setFormInitCounter((c) => c + 1)
275277
} catch (error: any) {
276278
newTab?.close()
277279
if (error.message?.includes('identifier')) {
@@ -295,6 +297,7 @@ export function ChatDeploy({
295297

296298
setImageUrl(null)
297299
setHasInitializedForm(false)
300+
setFormInitCounter((c) => c + 1)
298301
await onRefetchChat()
299302

300303
onDeploymentComplete?.()
@@ -370,7 +373,7 @@ export function ChatDeploy({
370373
</div>
371374

372375
<AuthSelector
373-
key={existingChat?.id ?? 'new'}
376+
key={`${existingChat?.id ?? 'new'}-${formInitCounter}`}
374377
authType={formData.authType}
375378
password={formData.password}
376379
emails={formData.emails}
@@ -631,6 +634,12 @@ function AuthSelector({
631634
emails.map((email) => ({ value: email, isValid: true }))
632635
)
633636

637+
useEffect(() => {
638+
if (!copySuccess) return
639+
const timer = setTimeout(() => setCopySuccess(false), 2000)
640+
return () => clearTimeout(timer)
641+
}, [copySuccess])
642+
634643
const handleGeneratePassword = () => {
635644
const newPassword = generatePassword(24)
636645
onPasswordChange(newPassword)
@@ -639,7 +648,6 @@ function AuthSelector({
639648
const copyToClipboard = (text: string) => {
640649
navigator.clipboard.writeText(text)
641650
setCopySuccess(true)
642-
setTimeout(() => setCopySuccess(false), 2000)
643651
}
644652

645653
const addEmail = (email: string): boolean => {

apps/sim/hooks/queries/deployments.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useCallback } from 'react'
12
import { createLogger } from '@sim/logger'
23
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
34
import type { WorkflowDeploymentVersionResponse } from '@/lib/workflows/persistence/utils'
@@ -209,19 +210,21 @@ export function useChatDeploymentInfo(workflowId: string | null, options?: { ena
209210
enabled: Boolean(chatId) && statusQuery.isSuccess && (options?.enabled ?? true),
210211
})
211212

213+
const refetch = useCallback(async () => {
214+
const statusResult = await statusQuery.refetch()
215+
if (statusResult.data?.deployment?.id) {
216+
await detailQuery.refetch()
217+
}
218+
}, [statusQuery.refetch, detailQuery.refetch])
219+
212220
return {
213221
isLoading:
214222
statusQuery.isLoading || Boolean(statusQuery.data?.isDeployed && detailQuery.isLoading),
215223
isError: statusQuery.isError || detailQuery.isError,
216224
error: statusQuery.error ?? detailQuery.error,
217225
chatExists: statusQuery.data?.isDeployed ?? false,
218226
existingChat: detailQuery.data ?? null,
219-
refetch: async () => {
220-
const statusResult = await statusQuery.refetch()
221-
if (statusResult.data?.deployment?.id) {
222-
await detailQuery.refetch()
223-
}
224-
},
227+
refetch,
225228
}
226229
}
227230

0 commit comments

Comments
 (0)