UNPKG

@coko/client

Version:

Client side common code for coko apps

35 lines (34 loc) 1.21 kB
import { CREATE_OAUTH_IDENTITY as e } from "./ProviderConnection.queries.js"; import t from "../ui/authentication/ProviderConnection.js"; import { useState as n } from "react"; import { useNavigate as r, useParams as i } from "react-router"; import { useMutation as a } from "@apollo/client/react"; import { jsx as o } from "react/jsx-runtime"; //#region src/pages/ProviderConnection.page.tsx var s = (s) => { let { closeOnSuccess: c = !1, delayOnSuccess: l = 1e3, loadingMinimumTime: u = 1e3, redirectOnSuccess: d = !1, redirectUrlLabel: f } = s, { provider: p } = i(), m = r(), [h, g] = n(!1), [_, v] = n(!0), { session_state: y, code: b, next: x } = Object.fromEntries(new URLSearchParams(window.location.search)), [S, { called: C }] = a(e, { variables: { provider: p, sessionState: y, code: b }, onCompleted: () => { setTimeout(() => { v(!1), g(!0), setTimeout(() => { c && window.close(), !c && d && x && m(x); }, l); }, u); }, onError: (e) => { e && console.error(e), v(!1), g(!1); } }); return C || S(), /* @__PURE__ */ o(t, { closeOnSuccess: c, connecting: _, redirectUrlLabel: f, successfullyConnected: h }); }; //#endregion export { s as default };