1import{r,j as t}from"./react-vendor-BKgfKFZH.js";import{e as D,il as P}from"./graphql-WBhJzdnw.js";import{W as U,R as E,u as W}from"./icons-BfNt_9T9.js";import{c as _}from"./pipedreamConnect-BbcT2UWm.js";import{fetchSessionIdentityId as z}from"./session-B58NCI26.js";import{v as b,P as F}from"./entry-C8wUDEw9.js";import{b as V}from"./types-Cf2awXPR.js";import"./authStep-CfHaIP7H.js";import"./types-BpdjsHyx.js";import"./types-B3nsUNRA.js";import"./hostedMcpProviders-nNFzfAVQ.js";import"./lindyTool-foG1F4ub.js";import{s as M}from"./task-Mt1dm-nP.js";import{o as h,s as e,a as Q,f as G,b as T,c as O,l as v}from"./types-BQz_GrV3.js";import"./makePostHogHeaders-DBJS6Pqp.js";import"./operations-Cnp__Iuy.js";import"./toast-DyJuw1_0.js";import"./NativeButton-BR3wnBC1.js";import"./Scrollable-65lHTgfc.js";import"./InformationCircleIcon-B7IeukFl.js";import"./pipedreamConnectFailure-BxSi90gj.js";import"./pathPrefix-C6KjWwRj.js";import"./identity-CPeTn7lB.js";import"./Identity-BmVeq4PW.js";import"./billing-BoSVWj_Q.js";import"./EvalCloneMarker-DcaKrgBx.js";import"./speechToText-BwTQh1Op.js";import"./types-C1NrGZG4.js";import"./parsePhoneNumber-6f8GhqhW.js";import"./normalizeArguments-VsWXHrBn.js";const B=h({type:v("lindyAssistantSlackThread"),appId:e(),channelId:e(),channelVariableName:e().nullish(),contextId:e(),enterpriseId:e().nullish(),ownerIdentityId:e(),ownerWorkspaceId:e(),resourceId:e(),slackUserId:e().nullish(),teamId:e().nullish(),threadTs:e()}),H=h({type:v("lindyAssistantSlackDm"),appId:e(),enterpriseId:e().nullish(),ownerIdentityId:e(),ownerWorkspaceId:e(),slackUserId:e(),teamId:e(),threadTs:e().nullish()}),J=G("type",[H,B]),K=h({provider:e(),workspaceId:e(),identityId:e(),taskId:e().nullish(),redirectContext:e().nullish(),scopes:O(e()).nullish(),actionDescription:e().nullish(),providerMethod:V.nullish(),subTaskInfo:M.nullish(),authId:e().nullish(),markLindyAssistantConnectComplete:T().nullish(),allowPreferredChannelConfirmation:T().nullish(),replyTarget:J.nullish()}),X=K.extend({createdAt:Q()}),Y=X.extend({providerDisplayName:e().nullish()}),Z=P;function k(n){return n.providerDisplayName?.trim()||n.provider.replace(/[_-]+/g," ").replace(/\b\w/g,o=>o.toUpperCase())}function $e(){const[n,o]=r.useState({status:"loading"}),[i,d]=r.useState("ready"),[R,x]=r.useState(null),[S,j]=r.useState(0),c=r.useRef(!0),u=r.useRef(null),m=r.useRef(null);r.useEffect(()=>{document.title="Connect account - Lindy";let s=!1;return b((async()=>{if(!u.current){const p=new URLSearchParams(window.location.search),w=p.get("context");if(!w){o({status:"error",message:"This connection link is invalid."});return}u.current={contextToken:w,returnTo:`${window.location.pathname}${window.location.search}${window.location.hash}`},p.delete("context");const I=p.toString();window.history.replaceState(window.history.state,"",`${window.location.pathname}${I?`?${I}`:""}${window.location.hash}`)}const{contextToken:a,returnTo:A}=u.current,L=await z();if(s)return;if(!L){window.location.assign(`/login?returnTo=${encodeURIComponent(A)}`);return}const q=await D(Z,{context:a});if(s)return;const g=Y.safeParse(q.pipedreamAuthRequestContext);if(!g.success){o({status:"error",message:"This connection link is invalid."});return}o({status:"ready",context:g.data,contextToken:a})})().catch(()=>{s||o({status:"error",message:"We could not verify this connection link."})})),()=>{s=!0}},[S]),r.useEffect(()=>(c.current=!0,()=>{c.current=!1,m.current!==null&&window.clearTimeout(m.current)}),[]);const f=r.useCallback(async()=>{if(n.status!=="ready"||i==="connecting")return;d("connecting"),x(null);const{context:s}=n;try{const a=await _({app:s.provider,authRequestContext:n.contextToken,authId:s.authId??void 0,identityId:s.identityId,replyTarget:s.replyTarget,subTaskInfo:s.subTaskInfo,workspaceId:s.workspaceId});if(!c.current)return;if(!a){d("ready");return}d("success"),m.current=window.setTimeout(()=>{c.current&&window.location.assign(`/connect/success?provider=${encodeURIComponent(s.provider)}&providerName=${encodeURIComponent(k(s))}`)},1500)}catch(a){if(!c.current)return;x(a instanceof Error?a.message:"Failed to connect account"),d("error")}},[i,n]),N=r.useCallback(()=>{o({status:"loading"}),j(s=>s+1)},[]),$=r.useCallback(()=>b(f()),[f]);if(n.status==="loading")return t.jsx(F,{});if(n.status==="error")return t.jsxs(C,{children:[t.jsx(U,{className:"size-10 text-red-10"}),t.jsx("h1",{className:"mt-5 text-2xl font-semibold text-slate-12",children:"Connection link unavailable"}),t.jsx("p",{className:"mt-2 text-sm text-slate-11",children:n.message}),t.jsx("button",{className:"mt-6 rounded-lg bg-blue-9 px-4 py-2 text-sm font-medium text-white hover:bg-blue-10",onClick:N,type:"button",children:"Try again"})]});const l=k(n.context),y=n.context.authId?"Reconnect":"Connect";return t.jsx(C,{children:i==="success"?t.jsxs(t.Fragment,{children:[t.jsx(E,{className:"size-10 text-green-10"}),t.jsx("h1",{className:"mt-5 text-2xl font-semibold text-slate-12",children:"Connected"}),t.jsxs("p",{className:"mt-2 text-sm text-slate-11",children:[l," is connected."]})]}):t.jsxs(t.Fragment,{children:[t.jsx(W,{className:"size-10 text-blue-10"}),t.jsxs("h1",{className:"mt-5 text-2xl font-semibold text-slate-12",children:[y," ",l]}),t.jsx("p",{className:"mt-2 max-w-sm text-sm text-slate-11",children:n.context.actionDescription?`Lindy needs access to ${l} to ${n.context.actionDescription}.`:`Lindy needs access to ${l} to continue.`}),i==="error"?t.jsx("p",{className:"mt-3 text-sm text-red-10",role:"alert",children:R??"Something went wrong while connecting your account."}):null,t.jsx("button",{className:"mt-6 rounded-lg bg-blue-9 px-6 py-3 text-sm font-medium text-white hover:bg-blue-10 disabled:cursor-not-allowed disabled:opacity-60",disabled:i==="connecting",onClick:$,type:"button",children:i==="connecting"?"Connectingâ¦":`${y} ${l}`})]})})}function C({children:n}){return t.jsxs("main",{className:"relative grid min-h-dvh place-items-center overflow-hidden bg-slate-1 p-6 text-center",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,#dbeafe_0,transparent_55%)] opacity-50"}),t.jsx("div",{className:"relative z-10 flex max-w-md flex-col items-center",children:n})]})}export{$e as View,k as getPipedreamProviderDisplayName};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.