refactor: simplify telegram settings to single connect action

This commit is contained in:
Ruslan Bakiev
2026-02-22 09:14:48 +07:00
parent 8a14f002f8
commit 25f7f8dfb4

View File

@@ -595,7 +595,6 @@ type TelegramConnectionSummary = {
const telegramConnectStatus = ref<TelegramConnectStatus>("not_connected");
const telegramConnectStatusLoading = ref(false);
const telegramConnectBusy = ref(false);
const telegramRefreshBusy = ref(false);
const telegramConnectUrl = ref("");
const telegramConnections = ref<TelegramConnectionSummary[]>([]);
const telegramConnectNotice = ref("");
@@ -617,10 +616,6 @@ const telegramStatusBadgeClass = computed(() => {
return "badge-ghost";
});
const primaryTelegramBusinessConnectionId = computed(
() => telegramConnections.value.find((item) => (item.businessConnectionId ?? "").trim())?.businessConnectionId ?? "",
);
async function loadTelegramConnectStatus() {
if (!authMe.value) {
telegramConnectStatus.value = "not_connected";
@@ -677,27 +672,6 @@ async function startTelegramBusinessConnect() {
}
}
function openTelegramConnectUrl() {
if (!telegramConnectUrl.value || !process.client) return;
window.open(telegramConnectUrl.value, "_blank", "noopener,noreferrer");
}
async function refreshTelegramBusinessConnectionFromApi() {
const businessConnectionId = primaryTelegramBusinessConnectionId.value;
if (!businessConnectionId || telegramRefreshBusy.value) return;
telegramRefreshBusy.value = true;
try {
await $fetch<{ ok: boolean }>("/api/omni/telegram/business/connect/refresh", {
method: "POST",
body: { businessConnectionId },
});
} finally {
telegramRefreshBusy.value = false;
await loadTelegramConnectStatus();
}
}
async function completeTelegramBusinessConnectFromToken(token: string) {
const t = String(token || "").trim();
if (!t) return;
@@ -4069,36 +4043,13 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
<span class="text-xs font-medium">Telegram Business</span>
<span class="badge badge-xs" :class="telegramStatusBadgeClass">{{ telegramStatusLabel }}</span>
</div>
<div class="grid grid-cols-2 gap-1.5">
<button
class="btn btn-xs btn-primary"
:disabled="telegramConnectBusy"
@click="startTelegramBusinessConnect"
>
{{ telegramConnectBusy ? "Connecting..." : "Connect" }}
</button>
<button
class="btn btn-xs btn-ghost border border-base-300"
:disabled="telegramConnectStatusLoading"
@click="loadTelegramConnectStatus"
>
{{ telegramConnectStatusLoading ? "Refreshing..." : "Refresh status" }}
</button>
<button
class="btn btn-xs btn-ghost border border-base-300"
:disabled="!telegramConnectUrl"
@click="openTelegramConnectUrl"
>
Open link
</button>
<button
class="btn btn-xs btn-ghost border border-base-300"
:disabled="!primaryTelegramBusinessConnectionId || telegramRefreshBusy"
@click="refreshTelegramBusinessConnectionFromApi"
>
{{ telegramRefreshBusy ? "Syncing..." : "Refresh from API" }}
</button>
</div>
<button
class="btn btn-xs btn-primary w-full"
:disabled="telegramConnectBusy"
@click="startTelegramBusinessConnect"
>
{{ telegramConnectBusy ? "Connecting..." : "Connect Telegram" }}
</button>
<p v-if="telegramConnectNotice" class="text-[11px] leading-snug text-base-content/70">
{{ telegramConnectNotice }}
</p>