Keep unavailable channel connect buttons clickable

This commit is contained in:
taohe
2026-06-11 11:28:56 +08:00
parent 89da9b70db
commit 0e939bfe23
3 changed files with 91 additions and 18 deletions
@@ -34,10 +34,13 @@ function providerCanConnect(provider: ChannelProvider): boolean {
);
}
function getProviderDisabledReason(
function getProviderUnavailableReason(
provider: ChannelProvider,
t: ReturnType<typeof useI18n>["t"],
): string | undefined {
if (provider.unavailable_reason) {
return provider.unavailable_reason;
}
if (!provider.enabled) {
return t.channels.disabled;
}
@@ -84,6 +87,7 @@ export function WorkspaceChannelsList() {
connectMutation.isPending &&
connectMutation.variables === provider.provider;
const canConnect = providerCanConnect(provider);
const unavailableReason = getProviderUnavailableReason(provider, t);
return (
<SidebarMenuItem key={provider.provider}>
@@ -103,9 +107,14 @@ export function WorkspaceChannelsList() {
"h-8 w-24 px-2 text-xs",
isConnected && "gap-1",
)}
disabled={!canConnect || isPending}
title={getProviderDisabledReason(provider, t)}
disabled={isConnected || isPending}
title={unavailableReason}
onClick={() => {
if (!canConnect) {
toast.error(unavailableReason ?? t.channels.unavailable);
return;
}
const connectWindow =
provider.auth_mode === "deep_link"
? prepareConnectWindow()
@@ -81,10 +81,13 @@ function getStatusLabel(
return t.channels.notConnected;
}
function getProviderDisabledReason(
function getProviderUnavailableReason(
provider: ChannelProvider,
t: ReturnType<typeof useI18n>["t"],
): string | undefined {
if (provider.unavailable_reason) {
return provider.unavailable_reason;
}
if (!provider.enabled) {
return t.channels.disabled;
}
@@ -116,7 +119,7 @@ function ChannelProviderItem({
disconnectMutation.variables === connection?.id;
const connectionLabel = connection ? getConnectionLabel(connection) : null;
const statusLabel = getStatusLabel(provider, connection, t);
const unavailableReason = getProviderDisabledReason(provider, t);
const unavailableReason = getProviderUnavailableReason(provider, t);
return (
<Item variant="outline" className="w-full items-start">
@@ -162,9 +165,14 @@ function ChannelProviderItem({
<Button
type="button"
size="sm"
disabled={!canConnect || isConnecting}
disabled={isConnecting}
title={unavailableReason}
onClick={() => {
if (!canConnect) {
toast.error(unavailableReason ?? t.channels.unavailable);
return;
}
const connectWindow =
provider.auth_mode === "deep_link"
? prepareConnectWindow()