1import{dr as H,fO as D,fP as $,fM as q,fk as B,g7 as J,es as m,f_ as K,eN as I,e$ as X,eB as V,e9 as e,P as b,Q as A,bc as F,S,J as Q,T as R,K as v,a4 as E,a7 as z,a6 as Z}from"./index-D2yE0WFs.js";import{U as N}from"./users-314H31wg.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ee=H("UserCheck",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]]);async function L(c){const n=c==null?void 0:c.context;if(!n||typeof n.clone!="function")return{};try{const s=await n.clone().json();return{status:n.status,code:s==null?void 0:s.code,body:s}}catch{return{status:n.status}}}function ne(){D("Invitation");const{token:c}=$(),n=q(),{user:s,loading:x,refreshProfile:P}=B(),{acceptInvitation:W}=J(),[t,r]=m.useState("loading"),[te,M]=m.useState(null),[g,l]=m.useState(""),[C,Y]=m.useState({}),[_,f]=m.useState("idle"),[T,y]=m.useState(""),[d,G]=m.useState(null),{t:i}=K();m.useEffect(()=>{var a;s==null||s.email,(a=d==null?void 0:d.workplace)==null||a.name},[c,s,x,t,d]),m.useEffect(()=>{if(!c){r("invalid"),l("Invalid invitation link");return}j()},[c]),m.useEffect(()=>{if(s==null||s.email,!x&&t==="preview"){if(!s){n(`/auth?redirect=/invite/${c}`);return}s.email,U()}},[s,x,t,c,n]);const j=async(a=0)=>{var o,w,h;if(c)try{a>0&&(await new Promise(p=>setTimeout(p,1e3*a)),a+1);const{data:u,error:k}=await I.functions.invoke("get-invitation-details",{body:{token:c}});if(k){const p=await L(k);if(p.code==="EXPIRED"||p.status===410){Y({workplaceName:((o=p.body)==null?void 0:o.workplaceName)||void 0}),r("expired");return}
6if(p.code==="NOT_FOUND"||p.status===404){r("invalid"),l("Invalid invitation link");return}if(console.error("[Invite] Error fetching invitation details:",k),a<2)return a+2,j(a+1);r("error"),l("Unable to load invitation details");return}if(u.success)u.invitation,G(u.invitation),r("preview");else throw new Error(u.error)}catch(u){if(console.error("[Invite] Error fetching invitation details:",u),a<2)return j(a+1);(w=u.message)!=null&&w.includes("expired")?r("expired"):(h=u.message)!=null&&h.includes("not found")?(r("invalid"),l("Invalid invitation link")):(r("error"),l("Unable to load invitation details"))}},O=async()=>{var a;if(!(!c||_==="sending")){f("sending");try{const{data:o,error:w}=await I.functions.invoke("request-invitation-refresh",{body:{token:c}});if(w){const h=await L(w);if(h.code==="RATE_LIMITED"){f("sent"),y(i("invite.expired.new_link_sent","New link sent to {{email}}. Check your inbox.",{email:((a=h.body)==null?void 0:a.email)||i("invite.expired.your_address","your address")}));return}if(h.code==="ALREADY_ACCEPTED"){f("error"),y(i("invite.expired.already_accepted","You've already joined. Just sign in to get back to your workplace."));return}throw new Error(h.code||"refresh_failed")}f("sent"),y(i("invite.expired.new_link_sent","New link sent to {{email}}. Check your inbox.",{email:(o==null?void 0:o.email)||i("invite.expired.your_address","your address")}))}catch(o){console.error("[Invite] Could not refresh invitation:",o),f("error"),y(i("invite.expired.request_failed","We couldn't send a new link. Ask whoever invited you to send one."))}}},U=async()=>{if(c)try{r("loading");const a=await W(c);a!=null&&a.workplaceId?(M(a.workplaceId),a.alreadyMember?(r("already_member"),l(a.workplaceName?`You're already a member of ${a.workplaceName}.`:"You're already a member of this workplace.")):r("success"),X({workplace_id:a.workplaceId}),s!=null&&s.id&&V(s.id,a.workplaceId),await P(),setTimeout(()=>{n("/workplace")},2e3)):(r("error"),l("Failed to accept invitation"))}catch(a){console.error("[Invite] Error accepting invitation:",a);const o=a.message||"";o.includes("EXPIRED:")?(r("expired"),l("This invitation has expired")):o.includes("INVALID_TOKEN:")?(r("invalid"),l("Invalid invitation link")):o.includes("ALREADY_MEMBER:")?(r("already_member"),l(o.split(": ")[1]||"You are already a member of this workplace")):o.includes("SELF_INVITATION:")?(r("self_invitation"),l("You cannot accept your own invitation")):o.includes("WRONG_EMAIL:")?(r("wrong_email"),l(o.split(": ")[1]||"This invitation was sent to a different email address")):o.includes("WORKPLACE_NOT_FOUND:")?(r("workplace_not_found"),l("The workplace no longer exists")):o.includes("NO_CHANNELS_REMAIN:")?(r("error"),l("The channels you were invited to no longer exist. Please ask the person who invited you to send a fresh invite.")):o.includes("ALREADY_ACCEPTED:")?(r("already_accepted"),l("This invitation has already been accepted")):(r("error"),l(o||"An error occurred while accepting the invitation"))}};return x||t==="loading"?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4",children:e.jsx(b,{className:"w-full max-w-md",children:e.jsx(A,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx(F,{className:"h-8 w-8 animate-spin text-[#5A60F1]"}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:i("Invite.cardcontent_div_h2.joining_workait","Joining Workaitâ¦")}),e.jsx("p",{className:"text-sm text-gray-600 text-center",children:i("Invite.cardcontent_div_p.setting_up_your_workspace_access","Setting up your workspace access.")})]})})})}):t==="preview"&&!s?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4",children:e.jsxs(b,{className:"w-full max-w-md",children:[e.jsxs(S,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(Q,{className:"h-12 w-12 text-[#5A60F1]"})}),e.jsx(R,{className:"text-xl",children:i("Invite.card_cardheader_cardtitle.you_re_invited_to_join","You're invited to join")}),e.jsx("h2",{className:"text-2xl font-bold text-[#5A60F1] mt-2",children:d==null?void 0:d.workplace.name})]}),e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-gray-600",children:[e.jsx(ee,{className:"h-4 w-4"}),e.jsxs("span",{children:[i("Invite.div_div_span.invited_by","Invited by"),d==null?void 0:d.inviter.name]})]}),(d==null?void 0:d.workplace.description)&&e.jsx("p",{className:"text-sm text-gray-600 bg-gray-50 p-3 rounded-md",children:d.workplace.description}),e.jsx("p",{className:"text-sm text-gray-500",children:i("Invite.cardcontent_div_p.log_in_or_create_an_account_to_accept_th","Log in or create an account to accept this invitation")})]}),e.jsxs(v,{onClick:()=>n(`/auth?redirect=/invite/${c}`),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:[e.jsx(N,{className:"h-4 w-4 mr-2"}),i("Invite.card_cardcontent_button.accept_invitation","Accept Invitation")]})]})]})}):e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4",children:e.jsxs(b,{className:"w-full max-w-md",children:[e.jsxs(S,{className:"text-center",children:[e.jsxs("div",{className:"flex justify-center mb-4",children:[t==="success"&&e.jsx(E,{className:"h-12 w-12 text-green-500"}),t==="already_member"&&e.jsx(E,{className:"h-12 w-12 text-blue-500"}),t==="expired"&&e.jsx(z,{className:"h-12 w-12 text-amber-500"}),(t==="error"||t==="invalid"||t==="self_invitation"||t==="wrong_email"||t==="workplace_not_found"||t==="already_accepted")&&e.jsx(Z,{className:"h-12 w-12 text-red-500"})]}),e.jsxs(R,{className:"text-xl",children:[t==="success"&&"Welcome to your new workplace!",t==="already_member"&&"Already a Member",t==="self_invitation"&&"Cannot Accept Own Invitation",t==="wrong_email"&&"Wrong Email Address",t==="workplace_not_found"&&"Workplace Not Found",t==="already_accepted"&&"Invitation Already Used",t==="error"&&"Invitation Error",t==="expired"&&i("invite.expired.title","This invitation has expired"),t==="invalid"&&"Invalid Invitation"]})]}),e.jsxs(A,{className:"space-y-4",children:[t==="success"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:i("Invite.cardcontent_div_p.you_have_successfully_joined_the_workpla","You have successfully joined the workplace! You'll be redirected to your workspace shortly.")}),e.jsxs(v,{onClick:()=>n("/workplace"),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:[e.jsx(N,{className:"h-4 w-4 mr-2"}),i("Invite.cardcontent_div_button.go_to_workplace","Go to Workplace")]})]}),t==="already_member"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:g}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(v,{onClick:()=>n("/workplace"),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:[e.jsx(N,{className:"h-4 w-4 mr-2"}),i("Invite.cardcontent_div_button.go_to_workplace","Go to Workplace")]}),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]}),t==="self_invitation"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:i("Invite.cardcontent_div_p.you_cannot_accept_an_invitation_that_you","You cannot accept an invitation that you sent to yourself. As the creator of this workplace, you already have full access.")}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(v,{onClick:()=>n("/workplace"),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:[e.jsx(N,{className:"h-4 w-4 mr-2"}),i("Invite.div_div_button.go_to_your_workplace","Go to Your Workplace")]}),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]}),t==="wrong_email"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:g}),e.jsx("p",{className:"text-sm text-gray-500",children:i("Invite.cardcontent_div_p.please_sign_in_with_the_correct_email_ad","Please sign in with the correct email address or ask the workplace owner to send a new invitation to your current email.")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{onClick:async()=>{try{await I.auth.signOut()}catch{}n(`/auth?redirect=/invite/${c}`)},className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:i("Invite.div_div_button.log_in_with_different_account","Log in with Different Account")}
6),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]}),(t==="workplace_not_found"||t==="already_accepted")&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:g}),e.jsx("p",{className:"text-sm text-gray-500",children:i("Invite.cardcontent_div_p.please_contact_the_person_who_sent_you_t","Please contact the person who sent you this invitation for assistance.")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{onClick:()=>n("/workplace"),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:i("Invite.cardcontent_div_button.go_to_workplace","Go to Workplace")}),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]}),t==="expired"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:C.workplaceName?i("invite.expired.body_with_workplace","Your invitation to join {{workplace}} has expired.",{workplace:C.workplaceName}):i("invite.expired.body_generic","This invitation link has expired.")}),e.jsxs("div",{className:"space-y-2",children:[_==="sent"?e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md bg-emerald-50 px-3 py-2.5 text-sm text-emerald-800",children:[e.jsx(E,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:T})]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{onClick:O,disabled:_==="sending",className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:_==="sending"?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"mr-2 h-4 w-4 animate-spin"}),i("invite.expired.sending","Sendingâ¦")]}):i("invite.expired.request_new_link","Send me a new invitation")}),_==="error"&&e.jsx("p",{className:"text-sm text-amber-700",children:T})]}),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]}),(t==="error"||t==="invalid")&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:g}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{onClick:()=>n("/workplace"),className:"w-full bg-[#5A60F1] hover:bg-[#4A50E1]",children:i("Invite.cardcontent_div_button.go_to_workplace","Go to Workplace")}),e.jsx(v,{variant:"outline",onClick:()=>n("/"),className:"w-full",children:i("Invite.div_div_button.go_to_home","Go to Home")})]})]})]})]})})}export{ne 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.