1import{d as I,c as L,u as b,r as n,j as e,L as z,ae as C,z as x}from"./index.Dc0yJpGJ.js";import{o as j}from"./orgs.service.DBsakEbE.js";const r="pendingOrgInviteToken",Y=()=>{const w=I(),g=L(),{isAuthenticated:i,loading:S}=b(),t=(()=>{const v=new URLSearchParams(w.search).get("token");return v||(typeof window<"u"?window.sessionStorage.getItem(r):null)})(),[s,y]=n.useState(null),[l,o]=n.useState(null),[a,f]=n.useState(!1),[d,A]=n.useState(!1),[N,p]=n.useState(!1),[h,u]=n.useState(!1);n.useEffect(()=>{if(!t){o("Missing invite token.");return}j.previewInvite(t).then(y).catch(c=>o(c.message))},[t]);const m=async()=>{if(t){f(!0),o(null);try{await j.acceptInvite(t),A(!0),typeof window<"u"&&window.sessionStorage.removeItem(r)}catch(c){o(c.message)}finally{f(!1)}}};n.useEffect(()=>{h&&i&&!d&&!a&&t&&(u(!1),m())},[h,i,d,a,t]);const k=async()=>{if(t){if(!i){typeof window<"u"&&window.sessionStorage.setItem(r,t),u(!0),g.push(x("/portal/orgs/accept"));return}await m()}},E=()=>{t&&(typeof window<"u"&&window.sessionStorage.setItem(r,t),u(!0),p(!0))};return S?e.jsx("div",{className:"orgs-accept-page",children:e.jsx("p",{children:"Loadingâ¦"})}):d&&s?e.jsxs("div",{className:"orgs-accept-page",children:[e.jsx("h1",{children:"You're in."}),e.jsxs("p",{children:["You've joined ",e.jsx("strong",{children:s.organization.name})," as ",e.jsx("strong",{children:s.invite.role}),"."]}),e.jsx(z,{to:"/portal#orgs",className:"orgs-accept-cta",children:"Go to your organizations"})]}):e.jsxs("div",{className:"orgs-accept-page",children:[e.jsx("h1",{children:"Join an organization"}),l&&e.jsx("div",{className:"orgs-accept-error",children:l}),!l&&!s&&e.jsx("p",{children:"Loading inviteâ¦"}),s&&e.jsxs("div",{className:"orgs-accept-invite",children:[e.jsxs("p",{children:["You've been invited to join ",e.jsx("strong",{children:s.organization.name})," ","as ",e.jsx("strong",{children:s.invite.role}),"."]}),e.jsxs("p",{className:"orgs-accept-meta",children:["Invite sent to ",e.jsx("code",{children:s.invite.email}),". Expires ",new Date(s.invite.expires_at).toLocaleDateString(),"."]}),e.jsxs("div",{className:"orgs-accept-actions",children:[e.jsx("button",{type:"button",onClick:k,disabled:a,className:"orgs-accept-cta",children:a?"Acceptingâ¦":i?"Accept invite":"Sign in to accept"}),!i&&e.jsx("button",{type:"button",onClick:E,disabled:a,className:"orgs-accept-secondary",children:"Don't have an account? Sign up"})]})]}),s&&e.jsx(C,{isOpen:N,onClose:()=>p(!1),onSwitchToLogin:()=>{p(!1),g.push(x("/portal/orgs/accept"))},prefillEmail:s.invite.email,lockEmail:!0})]})};export{Y as default};
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.