fix(qq): clarify QR binding states and setup actions (#6340)

* fix(qq): clarify QR binding states and setup actions

* fix(qq): confirm rebinding instead of showing a persistent warning

* fix(qq): make rebind credential warning conditional

* docs(qq): align rebind guide with conditional warning
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 01:55:20 +08:00
1 parent 51a0fc83a2
commit 130f4edefe
27 files changed
+634 -168

No files matched your search

@@ -79,7 +79,7 @@ export function ChannelFieldGroups({
if (!sectionFields?.length) return null;
return (
<fieldset key={section} className="min-w-0">
<legend className={groups.size === 1 ? "sr-only" : "mb-2 text-[12px] font-medium text-muted-foreground"}>
<legend className={groups.size === 1 ? "sr-only" : "mb-2 text-ui-label text-muted-foreground"}>
{channelFieldSectionLabel(section, tx, sectionLabels)}
</legend>
<div>
@@ -66,7 +66,10 @@ export function ChannelQrConnectFlow({
const pageVisible = usePageVisibility();
const [connect, setConnect] = useState<ChannelConnectPayload | null>(null);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [error, setError] = useState<{
action: NonNullable<ChannelQrConnectFlowViewProps["errorAction"]>;
message: string;
} | null>(null);
const handledRequestId = useRef(0);
const autoStarted = useRef(false);
const pollInFlight = useRef(false);
@@ -103,11 +106,10 @@ export function ChannelQrConnectFlow({
if (payload.nanobot_features) {
onFeaturesUpdate(payload.nanobot_features);
}
if (payload.status !== "pending") {
setError(null);
}
setError((current) => payload.status !== "pending" || current?.action === "poll" ? null : current);
} catch (err) {
if (!cancelled) setError((err as Error).message);
if (!cancelled) setError((current) => current?.action === "cancel"
? current : { action: "poll", message: (err as Error).message });
} finally {
pollInFlight.current = false;
}
@@ -146,7 +148,7 @@ export function ChannelQrConnectFlow({
onFeaturesUpdate(payload.nanobot_features);
}
} catch (err) {
setError((err as Error).message);
setError({ action: "start", message: (err as Error).message });
} finally {
setBusy(false);
}
@@ -173,8 +175,9 @@ export function ChannelQrConnectFlow({
connect.session_id,
);
setConnect(payload);
setError(null);
} catch (err) {
setError((err as Error).message);
setError({ action: "cancel", message: (err as Error).message });
} finally {
setBusy(false);
}
@@ -206,7 +209,7 @@ export function ChannelQrConnectFlow({
}
return payload;
} catch (err) {
setError((err as Error).message);
setError({ action: "poll", message: (err as Error).message });
return null;
} finally {
setBusy(false);
@@ -216,7 +219,8 @@ export function ChannelQrConnectFlow({
const viewProps: ChannelQrConnectFlowViewProps = {
connect,
busy,
error,
error: error?.message ?? null,
errorAction: error?.action,
onStart: () => void start(forceOnRepeat && !pending && (connected || connect?.status === "succeeded")),
onCancel: () => void cancel(),
onPoll: submitPoll,
@@ -1,6 +1,6 @@
import { useEffect, useState, type ReactNode } from "react";
import QRCode from "qrcode";
import { Check, Loader2, RotateCcw } from "lucide-react";
import { Check, CircleAlert, Clock, Loader2, RotateCcw, X } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
@@ -31,6 +31,7 @@ export type ChannelQrConnectFlowViewProps = {
connect: ChannelConnectPayload | null;
busy: boolean;
error: string | null;
errorAction?: "start" | "poll" | "cancel";
onStart: () => void;
onCancel: () => void;
onPoll: ChannelQrConnectPendingContext["poll"];
@@ -70,6 +71,7 @@ export function ChannelQrConnectFlowView({
const pending = connect?.status === "pending";
const succeeded = !pending && (connected || connect?.status === "succeeded");
const canStart = !pending && !busy;
const TerminalIcon = connect?.status === "expired" ? Clock : connect?.status === "failed" ? CircleAlert : X;
const displayMessage = connect
? resolveMessage?.(connect) ?? (connect.message ? channelValidationMessage(connect.message, t) : undefined)
: undefined;
@@ -103,9 +105,9 @@ export function ChannelQrConnectFlowView({
return (
<div className="mt-3 space-y-3">
{autoStart && busy && !connect ? (
<div role="status" className="grid min-h-[228px] place-items-center">
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" aria-hidden />
<span className="sr-only">{labels.connecting}</span>
<div role="status" className="flex min-h-[228px] flex-col items-center justify-center gap-3 text-muted-foreground">
<Loader2 className="h-5 w-5 animate-spin motion-reduce:animate-none" aria-hidden />
<span className="text-caption">{labels.connecting}</span>
</div>
) : null}
{pending && minimalPending && showQrCode ? (
@@ -124,7 +126,7 @@ export function ChannelQrConnectFlowView({
{renderPending?.({ connect, busy, poll: onPoll })}
</div>
) : pending ? (
<div className={`grid gap-4 rounded-control border border-border/70 p-4 ${showQrCode ? "sm:grid-cols-[auto_minmax(0,1fr)]" : ""}`}>
<div className={`grid items-center gap-4 py-2 ${showQrCode ? "sm:grid-cols-[auto_minmax(0,1fr)]" : ""}`}>
{showQrCode ? <div className="grid h-[196px] w-[196px] place-items-center rounded-control border border-border/60 bg-background">
{qrDataUrl ? (
<img
@@ -137,15 +139,15 @@ export function ChannelQrConnectFlowView({
)}
</div> : null}
<div className="flex min-w-0 flex-col justify-center">
<div className="text-[13px] font-semibold text-foreground">
<div className="text-ui-heading text-foreground">
{labels.scanTitle}
</div>
<p className="mt-1 text-[12.5px] leading-5 text-muted-foreground">
{!showQrCode || qrDataUrl ? labels.scanDescription : null}
</p>
{labels.scanDescription && (!showQrCode || qrDataUrl) ? (
<p className="mt-1 text-caption text-muted-foreground">{labels.scanDescription}</p>
) : null}
{renderPending?.({ connect, busy, poll: onPoll }) ?? (
<div className="mt-3 flex items-center gap-2 text-[12px] text-muted-foreground">
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
<div role="status" className="mt-3 flex items-center gap-2 text-caption text-muted-foreground">
<Loader2 className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" aria-hidden />
{!showQrCode || qrDataUrl ? labels.waiting : labels.connecting}
</div>
)}
@@ -154,7 +156,6 @@ export function ChannelQrConnectFlowView({
type="button"
size="sm"
variant="outline"
className="h-8 rounded-full px-3 text-[12px] font-semibold"
onClick={() => onCancel()}
disabled={busy}
>
@@ -166,7 +167,7 @@ export function ChannelQrConnectFlowView({
) : null}
{succeeded && !suppressSucceeded ? (
<div className="flex items-center gap-2 rounded-control border border-emerald-500/20 px-3 py-2 text-[12px] font-medium text-emerald-700 dark:text-emerald-200">
<div role="status" className="flex items-center gap-2 text-caption text-emerald-700 dark:text-emerald-200">
<Check className="h-3.5 w-3.5" aria-hidden />
{displayMessage ?? labels.connected}
</div>
@@ -174,13 +175,15 @@ export function ChannelQrConnectFlowView({
{connect && ["expired", "failed", "cancelled"].includes(connect.status)
&& !(connected && connect.status === "cancelled") ? (
<div className="rounded-control border border-border/60 px-3 py-2 text-[12px] leading-5 text-muted-foreground">
<div role="status" className="flex items-center gap-2 text-caption text-muted-foreground">
<TerminalIcon className="h-3.5 w-3.5 shrink-0" aria-hidden />
{displayMessage || labels.stopped}
</div>
) : null}
{error ? (
<div className="rounded-control border border-destructive/20 px-3 py-2 text-[12px] leading-5 text-destructive">
<div role="alert" className="flex items-center gap-2 text-caption text-destructive">
<CircleAlert className="h-3.5 w-3.5 shrink-0" aria-hidden />
{error}
</div>
) : null}
@@ -190,7 +193,6 @@ export function ChannelQrConnectFlowView({
type="button"
size="sm"
variant="outline"
className="h-8 rounded-full border-border/65 bg-background/80 px-3 text-[12px] font-semibold settings-hover"
onClick={() => onStart()}
disabled={!canStart}
>
@@ -121,7 +121,7 @@ export function ChannelSetupPanel({
const header = (
<div className="flex min-w-0 items-center gap-3">
<ChannelLogo feature={feature} showBrandLogos={showBrandLogos} />
<h3 className="sr-only">{displayName}</h3>
<h3 className="text-ui-heading">{displayName}</h3>
{missingSupport && feature.install_supported ? (
<Button
type="button"
@@ -508,7 +508,8 @@ function ChannelSetupSurface({
connectFlow={mode === "connect" && ConnectFlow ? <Suspense fallback={<ChannelPluginLoading compact />}>
<ConnectFlow token={token} feature={feature}
idleLabel={setup.primaryActionLabel ?? tx("settings.channels.connect", "Connect")}
connectRequestId={connectRequestId} onFeaturesUpdate={onFeaturesUpdate} />
connectRequestId={connectRequestId} onOpenAdvanced={() => setAdvancedOpen(true)}
onFeaturesUpdate={onFeaturesUpdate} />
</Suspense> : undefined}
/>;
}
@@ -64,6 +64,19 @@ export function ChannelSetupSurfaceView({
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
const mode = setup.mode ?? "credentials";
const hasAdvanced = advancedFields.length > 0 || savedSecretFields.length > 0 || availablePresets.length > 0;
const advancedFormProps = {
fields: advancedFields,
values: fieldValues,
configuredFields,
visibleSecrets,
onChange: setFieldValue,
onFieldBlur: saveSecretOnBlur,
onToggleSecret: toggleSecret,
errors: fieldErrors,
clearedSecrets,
onClearSecret: setSecretCleared,
disabled: actionPending,
};
const inlineActions = mode === "credentials" && primaryFields.length === 1
&& !advancedOpen && !setup.presets?.length && !setup.actions?.length;
const credentialActions = mode === "credentials" ? (
@@ -243,20 +256,11 @@ export function ChannelSetupSurfaceView({
</div>
{advancedFields.length ? (
<div onBlur={() => void saveConnectionSettings()}>
<CredentialForm
fields={advancedFields}
values={fieldValues}
configuredFields={configuredFields}
visibleSecrets={visibleSecrets}
onChange={setFieldValue}
onFieldBlur={saveSecretOnBlur}
onToggleSecret={toggleSecret}
errors={fieldErrors}
clearedSecrets={clearedSecrets}
onClearSecret={setSecretCleared}
compact
disabled={actionPending}
/>
{mode === "connect" ? (
<ChannelFieldGroups {...advancedFormProps} requirements={[]} sectionLabels={setup.sectionLabels} />
) : (
<CredentialForm {...advancedFormProps} compact />
)}
</div>
) : null}
</div>