"use client"; /** * Linked products (§8, §9): the church's other sites as the Hub lists them. Accounts is how * people sign in here (the Website links to it by itself). With Cross Events (and later the App), * events flow either way: "Show events from" brings its events here, read-only and linking back * for registering; "Publish my events" offers this site's simple events to them. */ import { api, canEdit } from "@/admin/api"; import { Btn, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui"; type Product = { installId: string; product: string; url: string; connected: boolean; listed: boolean; showEvents: boolean | null; events: number; lastSyncAt: string | null; lastSyncError: string | null }; const NAMES: Record = { accounts: "Accounts (sign-in)", events: "Cross Events", app: "Church App", website: "Website" }; export default function Linked() { const me = useAdmin<{ user: { role: string } }>("/me"); const { data, error, reload } = useAdmin<{ publishMyEvents: boolean; products: Product[] }>("/links"); const { busy, message, run } = useAction(); if (!data || !me.data) return ; const editor = canEdit(me.data.user.role); const manager = ["owner", "admin"].includes(me.data.user.role); return ( <> Linked products {message &&
{message.text}
}
{data.products.length === 0 && No other sites yet. When your church has Cross Events or the App, they show here within 15 minutes.} {data.products.map((p) => (

{NAMES[p.product] ?? p.product}

{p.url}

{p.connected ? Connected : Not connected}

{manager && !p.connected && p.listed && run(async () => { await api(`/links/${p.installId}/connect`, { body: {} }); await reload(); }, "Connected.")}>Connect} {manager && p.connected && p.product !== "accounts" && run(async () => { await api(`/links/${p.installId}`, { method: "DELETE" }); await reload(); }, "Disconnected: its events are gone from here.")}>Disconnect}
{p.product === "accounts" && p.connected &&

People sign in to this website's admin through it. This link stays.

} {p.connected && p.product !== "accounts" && (
{p.showEvents && (

{p.events} {p.events === 1 ? "event" : "events"} from it{p.lastSyncAt && `, last checked ${when(p.lastSyncAt)}`}.{" "} {editor && run(async () => { await api(`/links/${p.installId}/sync`, { body: {} }); await reload(); }, "Checked.")}>Check now}

)} {p.lastSyncError && Last time: {p.lastSyncError}. The events from before keep showing.}
)}
))}
); }