UNPKG

@accounter/client

Version:
1 lines 4.01 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{_n as r,es as i,r as a,t as o}from"./error-handling-Bgq5bXpB.js";import{_ as s,c,t as l}from"./routes-Cawu7UJi.js";import{n as u}from"./auth0-react.esm-mnUP2_nu.js";import{t as d}from"./loader-circle-CfW9jOIr.js";import{t as f}from"./button-DUNsVBiu.js";import{t as p}from"./use-viewer-DA1RSVBb.js";import{t as m}from"./use-logout-Be3xHiy2.js";import{n as h,r as g,t as _}from"./alert-55QsYEfR.js";var v=e(n(),1),y=`claimInvitation`,b=()=>{let[{fetching:e,error:t},n]=i(r);return{fetching:e,error:t,claimInvitation:(0,v.useCallback)(async e=>{let t=`Error joining business`,r=y;a.loading(`Joining business`,{id:r});try{let i=await n({invitationId:e}),s=o(i,t,r);if(s)return a.success(`Success`,{id:r,description:`Invitation accepted successfully`}),s.claimInvitation}catch(e){console.error(t,e),a.error(`Error`,{id:r,description:t,duration:1e4,closeButton:!0})}},[n])}},x=t();function S(){let{isAuthenticated:e,isLoading:t}=u(),{fetching:n,error:r,viewer:i,refreshViewer:a}=p({pause:t||!e}),{fetching:o,claimInvitation:y}=b(),S=m(),C=s();if((0,v.useEffect)(()=>{i?.status===`ACTIVE`&&C(l.HOME,{replace:!0})},[i?.status,C]),t||n)return(0,x.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,x.jsx)(d,{className:`h-10 w-10 animate-spin`})});if(!e)return(0,x.jsx)(c,{to:l.LOGIN,replace:!0});if(r)return(0,x.jsx)(`div`,{className:`flex items-center justify-center h-screen px-4`,children:(0,x.jsxs)(`div`,{className:`max-w-md space-y-6`,children:[(0,x.jsxs)(_,{variant:`destructive`,children:[(0,x.jsx)(g,{children:`Could not check your account`}),(0,x.jsx)(h,{children:`We could not reach the server to see which businesses you belong to. Check your connection and try again.`})]}),(0,x.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,x.jsx)(f,{onClick:()=>window.location.reload(),children:`Try again`}),(0,x.jsx)(f,{variant:`outline`,onClick:S,children:`Sign out`})]})]})});let w=i?.status===`EMAIL_UNVERIFIED`,T=i?.pendingInvitations??[],E=async e=>{(await y(e))?.success&&(a(),C(l.HOME,{replace:!0}))};return(0,x.jsx)(`div`,{className:`flex items-center justify-center h-screen px-4`,children:(0,x.jsxs)(`div`,{className:`text-center max-w-md space-y-6`,children:[(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(`h1`,{className:`text-3xl font-bold`,children:w?`Verify your email`:T.length>0?`You've been invited`:`No workspace yet`}),i?.email?(0,x.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Signed in as `,i.email]}):null]}),w?(0,x.jsx)(`p`,{className:`text-muted-foreground`,children:`We sent a verification link to your email address. Open it, then reload this page to continue.`}):T.length>0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`p`,{className:`text-muted-foreground`,children:T.length===1?`An invitation is waiting for your email address. Accept it to get started.`:`These invitations are waiting for your email address. Accept one to get started.`}),(0,x.jsx)(`ul`,{className:`space-y-2`,children:T.map(e=>(0,x.jsxs)(`li`,{className:`flex items-center justify-between gap-4 rounded-md border p-3 text-left`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`font-medium`,children:e.businessName??`Unnamed business`}),(0,x.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`as `,e.roleId]})]}),(0,x.jsx)(f,{onClick:()=>void E(e.id),disabled:o,className:`shrink-0`,children:`Accept`})]},e.id))})]}):(0,x.jsx)(`p`,{className:`text-muted-foreground`,children:`Accounter is invitation-only. Your account is not linked to any business yet — ask an administrator of the business you should belong to for an invitation, then open the link they send you.`}),(0,x.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,x.jsx)(f,{variant:T.length>0?`outline`:`default`,onClick:a,children:`Check again`}),(0,x.jsx)(f,{variant:`outline`,onClick:S,children:`Sign out`})]})]})})}export{S as WelcomePage};