UNPKG

@accounter/client

Version:
1 lines 3.01 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{Io as r,i,r as a,t as o}from"./error-handling-Dpfd9svJ.js";import{_ as s,t as c,y as l}from"./routes-DUvpW9-n.js";import{n as u}from"./auth0-react.esm-BrucYGp4.js";import{t as d}from"./button-Dzp2INW0.js";var f=e(n(),1),p=`acceptInvitation`,m=()=>{let[{fetching:e,error:t},n]=r(i);return{fetching:e,error:t,acceptInvitation:(0,f.useCallback)(async e=>{let t=`Error accepting invitation`,r=p;a.loading(`Accepting invitation`,{id:r});try{let i=o(await n({token:e}),t,r);if(i)return a.success(`Success`,{id:r,description:`Invitation accepted successfully`}),i.acceptInvitation}catch(e){console.error(t,e),a.error(`Error`,{id:r,description:t,duration:1e4,closeButton:!0})}},[n])}},h=t();function g(){let{token:e}=l(),{isAuthenticated:t,isLoading:n,loginWithRedirect:r}=u(),i=s(),{fetching:a,error:o,acceptInvitation:f}=m();return e?n?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,h.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,h.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Loading invitation...`}),(0,h.jsx)(`p`,{className:`text-muted-foreground`,children:`Please wait while we check your authentication status.`})]})}):t?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,h.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,h.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Accept Invitation`}),o&&(0,h.jsx)(`p`,{className:`text-destructive`,children:o.graphQLErrors?.[0]?.message===`TOKEN_EXPIRED`?`This invitation link has expired. Please request a new one.`:o.graphQLErrors?.[0]?.message??`An error occurred`}),(0,h.jsx)(d,{onClick:async()=>{(await f(e))?.success&&i(c.HOME,{replace:!0})},disabled:a,children:a?`Accepting...`:`Accept Invitation`})]})}):(0,h.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,h.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,h.jsx)(`h1`,{className:`text-2xl font-bold`,children:`You've been invited!`}),(0,h.jsx)(`p`,{className:`text-muted-foreground`,children:`Please log in or create an account to accept this invitation.`}),(0,h.jsx)(d,{onClick:()=>{let t=c.ACCEPT_INVITATION(e);return sessionStorage.setItem(`auth:returnTo`,t),sessionStorage.setItem(`auth:invitationReturnTo`,t),r({authorizationParams:{audience:void 0,scope:`openid profile email offline_access`,redirect_uri:`${window.location.origin}${c.AUTH_CALLBACK}`},appState:{returnTo:t}})},children:`Login / Create Account`})]})}):(0,h.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,h.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,h.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Invalid invitation link`}),(0,h.jsx)(`p`,{className:`text-muted-foreground`,children:`This invitation link is incomplete. Please use the full link from your email.`})]})})}export{g as AcceptInvitationPage};