refactor: simplify telegram settings to single connect action
This commit is contained in:
@@ -595,7 +595,6 @@ type TelegramConnectionSummary = {
|
|||||||
const telegramConnectStatus = ref<TelegramConnectStatus>("not_connected");
|
const telegramConnectStatus = ref<TelegramConnectStatus>("not_connected");
|
||||||
const telegramConnectStatusLoading = ref(false);
|
const telegramConnectStatusLoading = ref(false);
|
||||||
const telegramConnectBusy = ref(false);
|
const telegramConnectBusy = ref(false);
|
||||||
const telegramRefreshBusy = ref(false);
|
|
||||||
const telegramConnectUrl = ref("");
|
const telegramConnectUrl = ref("");
|
||||||
const telegramConnections = ref<TelegramConnectionSummary[]>([]);
|
const telegramConnections = ref<TelegramConnectionSummary[]>([]);
|
||||||
const telegramConnectNotice = ref("");
|
const telegramConnectNotice = ref("");
|
||||||
@@ -617,10 +616,6 @@ const telegramStatusBadgeClass = computed(() => {
|
|||||||
return "badge-ghost";
|
return "badge-ghost";
|
||||||
});
|
});
|
||||||
|
|
||||||
const primaryTelegramBusinessConnectionId = computed(
|
|
||||||
() => telegramConnections.value.find((item) => (item.businessConnectionId ?? "").trim())?.businessConnectionId ?? "",
|
|
||||||
);
|
|
||||||
|
|
||||||
async function loadTelegramConnectStatus() {
|
async function loadTelegramConnectStatus() {
|
||||||
if (!authMe.value) {
|
if (!authMe.value) {
|
||||||
telegramConnectStatus.value = "not_connected";
|
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) {
|
async function completeTelegramBusinessConnectFromToken(token: string) {
|
||||||
const t = String(token || "").trim();
|
const t = String(token || "").trim();
|
||||||
if (!t) return;
|
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="text-xs font-medium">Telegram Business</span>
|
||||||
<span class="badge badge-xs" :class="telegramStatusBadgeClass">{{ telegramStatusLabel }}</span>
|
<span class="badge badge-xs" :class="telegramStatusBadgeClass">{{ telegramStatusLabel }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-1.5">
|
<button
|
||||||
<button
|
class="btn btn-xs btn-primary w-full"
|
||||||
class="btn btn-xs btn-primary"
|
:disabled="telegramConnectBusy"
|
||||||
:disabled="telegramConnectBusy"
|
@click="startTelegramBusinessConnect"
|
||||||
@click="startTelegramBusinessConnect"
|
>
|
||||||
>
|
{{ telegramConnectBusy ? "Connecting..." : "Connect Telegram" }}
|
||||||
{{ telegramConnectBusy ? "Connecting..." : "Connect" }}
|
</button>
|
||||||
</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>
|
|
||||||
<p v-if="telegramConnectNotice" class="text-[11px] leading-snug text-base-content/70">
|
<p v-if="telegramConnectNotice" class="text-[11px] leading-snug text-base-content/70">
|
||||||
{{ telegramConnectNotice }}
|
{{ telegramConnectNotice }}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user