Skip to content

An open-source, faster Devin alternative

TypeScript

fix(web): pace credential-create steps with a guaranteed minimum + green finish

Igor Zalutskid5b087f5644a
diff --git a/web/src/components/step-progress.tsx b/web/src/components/step-progress.tsx
index 93c87add..89d57bb5 100644
--- a/web/src/components/step-progress.tsx
+++ b/web/src/components/step-progress.tsx
@@ -27,7 +27,7 @@ export function StepProgress({
<span
className={cn(
'h-px flex-1 transition-colors duration-300',
- i <= current ? 'bg-primary' : 'bg-border',
+ i <= current ? 'bg-status-running' : 'bg-border',
)}
/>
) : null}
@@ -35,7 +35,7 @@ export function StepProgress({
className={cn(
'flex size-7 shrink-0 items-center justify-center rounded-full border text-xs font-medium transition-colors duration-300',
done || active
- ? 'border-primary text-primary'
+ ? 'border-status-running text-status-running'
: 'border-border text-muted-foreground/50',
)}
>
@@ -53,9 +53,9 @@ export function StepProgress({
</div>
<div className="flex items-center gap-2 text-sm">
{allDone ? (
- <Check className="text-primary size-4 shrink-0" />
+ <Check className="text-status-running size-4 shrink-0" />
) : (
- <Loader2 className="text-muted-foreground size-4 shrink-0 animate-spin" />
+ <Loader2 className="text-status-running size-4 shrink-0 animate-spin" />
)}
<span className="text-foreground">
{allDone ? 'Done' : steps[current]}
diff --git a/web/src/pages/Credentials.tsx b/web/src/pages/Credentials.tsx
index c44b92aa..92643bad 100644
--- a/web/src/pages/Credentials.tsx
+++ b/web/src/pages/Credentials.tsx
@@ -1,6 +1,6 @@
-import { useRef, useState } from 'react'
+import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
-import { CircleCheck, KeySquare, Plus } from 'lucide-react'
+import { KeySquare, Plus } from 'lucide-react'
import { notifyError } from '@/lib/errors'
import {
createCredential,
@@ -47,6 +47,10 @@ const CREATE_STEPS = [
'Finalizing credential',
]
const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
+// Guaranteed minimum visible time per step (so the sequence has a steady rhythm
+// even when the backend is fast) + a beat to rest on the final green state.
+const STEP_MIN_MS = 550
+const DONE_PAUSE_MS = 800
export default function Credentials() {
const queryClient = useQueryClient()
@@ -87,45 +91,49 @@ export default function Credentials() {
const [phase, setPhase] = useState<'form' | 'running'>('form')
const [step, setStep] = useState(0)
const [createError, setCreateError] = useState<string | null>(null)
- const provisionTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
- const createMutation = useMutation({
- mutationFn: () =>
- createCredential({
- key: key.trim(),
- provider,
- name: name.trim() || undefined,
- is_default: makeDefault,
- }),
- onMutate: () => {
- setCreateError(null)
- setPhase('running')
- setStep(0) // "Securing your key"
- // The reserve is fast; the write to the secret store is the long pole — hold
- // the active spinner on it until the request actually resolves.
- provisionTimer.current = setTimeout(() => setStep(1), 450)
- },
- onSuccess: async () => {
- if (provisionTimer.current) clearTimeout(provisionTimer.current)
- setStep(2) // "Finalizing credential"
- await wait(300)
- setStep(CREATE_STEPS.length) // all done
- await queryClient.invalidateQueries({ queryKey: CREDS_KEY })
- await wait(550) // let the completed checklist register before closing
- setShowCreate(false)
- setPhase('form')
- setStep(0)
- resetForm()
- },
- onError: (e) => {
- if (provisionTimer.current) clearTimeout(provisionTimer.current)
- // Back to the form with inputs intact + an inline error, so they can retry.
+ // Drive the steps on a guaranteed minimum cadence so they read as a steady job,
+ // while the real request runs underneath. The provision step also absorbs the
+ // actual store-write latency (it holds until the request settles AND its minimum
+ // elapses). On failure we fall back to the form with the inputs + an inline error.
+ const runCreate = async () => {
+ setCreateError(null)
+ setPhase('running')
+ setStep(0) // Securing your key
+ // Tagged so it never rejects unhandled while we dwell on the early steps.
+ const settledP = createCredential({
+ key: key.trim(),
+ provider,
+ name: name.trim() || undefined,
+ is_default: makeDefault,
+ }).then(
+ (cred) => ({ ok: true as const, cred }),
+ (err: unknown) => ({ ok: false as const, err }),
+ )
+
+ await wait(STEP_MIN_MS)
+ setStep(1) // Provisioning in secure secret store (the long pole)
+ const [settled] = await Promise.all([settledP, wait(STEP_MIN_MS)])
+ if (!settled.ok) {
setPhase('form')
setCreateError(
- e instanceof Error ? e.message : "Couldn't add the credential.",
+ settled.err instanceof Error
+ ? settled.err.message
+ : "Couldn't add the credential.",
)
- },
- })
+ return
+ }
+
+ setStep(2) // Finalizing credential
+ await wait(STEP_MIN_MS)
+ setStep(CREATE_STEPS.length) // all done → the steps turn green
+ void queryClient.invalidateQueries({ queryKey: CREDS_KEY })
+ await wait(DONE_PAUSE_MS) // rest on the completed green state
+ setShowCreate(false)
+ setPhase('form')
+ setStep(0)
+ resetForm()
+ }
const defaultMutation = useMutation({
mutationFn: (id: string) => setDefaultCredential(id),
@@ -317,17 +325,7 @@ export default function Credentials() {
: 'Encrypting and provisioning it in your dedicated secret store.'}
</DialogDescription>
</DialogHeader>
- {step >= CREATE_STEPS.length ? (
- <div className="flex items-center gap-3 text-sm">
- <CircleCheck className="text-status-running size-5 shrink-0" />
- <span className="text-foreground">
- {name.trim() || 'Credential'} added
- {makeDefault ? ' · set as default' : ''}.
- </span>
- </div>
- ) : (
- <StepProgress steps={CREATE_STEPS} current={step} />
- )}
+ <StepProgress steps={CREATE_STEPS} current={step} />
</div>
) : (
<>
@@ -342,7 +340,7 @@ export default function Credentials() {
className="flex flex-1 flex-col space-y-4"
onSubmit={(e) => {
e.preventDefault()
- if (canCreate) createMutation.mutate()
+ if (canCreate) void runCreate()
}}
>
{createError ? (