1var $=Object.defineProperty,z=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var A=(n,a,t)=>a in n?$(n,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[a]=t,p=(n,a)=>{for(var t in a||(a={}))M.call(a,t)&&A(n,t,a[t]);if(P)for(var t of P(a))O.call(a,t)&&A(n,t,a[t]);return n},f=(n,a)=>z(n,H(a));import{j as e}from"./vendor-query-DFysnBx4.js";import{i as V,f as X,r as u,m as G}from"./vendor-react-BGQaF37-.js";import{n as J,s as h,C as _,a as F,b as S,c as T,d as K,L as g,I as x,B as Q}from"./index-CdX7G71Q.js";import{L as D}from"./loader-circle-DwsGBtQj.js";import{C as W}from"./circle-x-BnCOPyWn.js";import{C as Z}from"./circle-check-big-BK-DS4FA.js";import"./vendor-supabase-D03-Pc4v.js";import"./vendor-ui-CTkhEEOW.js";import"./vendor-charts-B_8AYdV8.js";function de(){console.log("[AcceptInvitation] Component mounted at:",new Date().toISOString());const[n]=V(),a=X(),{toast:t}=J(),[b,w]=u.useState(!0),[o,L]=u.useState(null),[k,N]=u.useState(!1),[s,v]=u.useState({fullName:"",password:"",confirmPassword:""}),j=G(),q=n.get("token"),Y=j==null?void 0:j.token,r=q||Y,l=n.get("accept-token");u.useEffect(()=>{console.log("[AcceptInvitation] Effect 1 - token:",r,"legacyToken:",l),!r&&l&&(console.log("[AcceptInvitation] Found accept-token in URL, normalizing to ?token=",l),a(`/accept-invitation?token=${encodeURIComponent(l)}`,{replace:!0}))},[l,r,a]),u.useEffect(()=>{console.log("[AcceptInvitation] Effect 2 - mounted with token:",r,"legacyToken:",l),r?(console.log("[AcceptInvitation] Calling validateInvitation with token:",r),R()):l||(console.log("[AcceptInvitation] No token found, setting loading false"),w(!1))},[r,l]);const R=async()=>{try{w(!0),console.log("[AcceptInvitation] Calling validate-invitation with token:",r);const{data:i,error:m}=await h.functions.invoke("validate-invitation",{body:{token:r}});console.log("[AcceptInvitation] validate-invitation response:",i,"error:",m);const c=i==null?void 0:i.invitation;if(m||!c){t({title:"Invalid Invitation",description:"This invitation link is invalid or has expired.",variant:"destructive"});return}if(new Date(c.expires_at)<new Date){t({title:"Invitation Expired",description:"This invitation has expired. Please request a new one.",variant:"destructive"});return}if(c.accepted_at){t({title:"Invitation Already Used",description:"This invitation has already been accepted.",variant:"destructive"});return}L(c),c.full_name&&v(d=>f(p({},d),{fullName:c.full_name}))}catch(i){console.error("Error validating invitation:",i),t({title:"Error",description:"Failed to validate invitation. Please try again.",variant:"destructive"})}finally{w(!1)}},U=async i=>{var m,c;if(i.preventDefault(),!s.fullName||!s.password||!s.confirmPassword){t({title:"Error",description:"Please fill in all fields",variant:"destructive"});return}if(s.password!==s.confirmPassword){t({title:"Error",description:"Passwords do not match",variant:"destructive"});return}if(s.password.length<6){t({title:"Error",description:"Password must be at least 6 characters long",variant:"destructive"});return}N(!0);try{const{data:d,error:C}=await h.auth.signUp({email:o.email,password:s.password,options:{data:{full_name:s.fullName}}});if(C)throw C;const{error:I}=await h.functions.invoke("mark-invitation-accepted",{body:{token:r,userId:(m=d.user)==null?void 0:m.id}});if(I)throw I;if(d.user){const{error:E}=await h.from("profiles").update({role:o.role}).eq("user_id",d.user.id);E&&console.warn("Failed to update profile role:",E)}const y=((c=o.pre_assigned_courses)==null?void 0:c.length)||0,B=y>0?`Your account has been created successfully and ${y} course${y>1?"s have":" has"} been assigned to you. You can now sign in.`:"Your account has been created successfully. You can now sign in.";t({title:"Account Created!",description:B,variant:"default"}),a("/",{replace:!0})}catch(d){console.error("Error accepting invitation:",d),t({title:"Error",description:d.message||"Failed to create account. Please try again.",variant:"destructive"})}finally{N(!1)}};return console.log("[AcceptInvitation] Rendering - loading:",b,"token:",r,"
1invitation:",!!o),b?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center",children:[e.jsx(D,{className:"h-8 w-8 animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Validating invitation..."})]})}):!r||!o?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(_,{className:"max-w-md w-full",children:e.jsxs(F,{className:"text-center",children:[e.jsx(W,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx(S,{children:"Invalid Invitation"}),e.jsx(T,{children:"This invitation link is invalid or has expired."})]})})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(_,{className:"max-w-md w-full",children:[e.jsxs(F,{className:"text-center",children:[e.jsx(Z,{className:"h-12 w-12 text-success mx-auto mb-4"}),e.jsx(S,{children:"Accept Invitation"}),e.jsxs(T,{children:["You've been invited to join as a ",e.jsx("strong",{children:o.role}),".",o.pre_assigned_courses&&o.pre_assigned_courses.length>0&&e.jsxs("span",{className:"block mt-1 text-sm",children:["ð ",o.pre_assigned_courses.length," course",o.pre_assigned_courses.length>1?"s":""," will be automatically assigned to you."]}),"Complete your account setup below."]})]}),e.jsx(K,{children:e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"email",children:"Email Address"}),e.jsx(x,{id:"email",type:"email",value:o.email,disabled:!0,className:"bg-muted"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"fullName",children:"Full Name *"}),e.jsx(x,{id:"fullName",type:"text",placeholder:"Enter your full name",value:s.fullName,onChange:i=>v(f(p({},s),{fullName:i.target.value})),required:!0})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"password",children:"Password *"}),e.jsx(x,{id:"password",type:"password",placeholder:"Create a password (min. 6 characters)",value:s.password,onChange:i=>v(f(p({},s),{password:i.target.value})),required:!0,minLength:6})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"confirmPassword",children:"Confirm Password *"}),e.jsx(x,{id:"confirmPassword",type:"password",placeholder:"Confirm your password",value:s.confirmPassword,onChange:i=>v(f(p({}
1,s),{confirmPassword:i.target.value})),required:!0})]}),e.jsx(Q,{type:"submit",className:"w-full",disabled:k,children:k?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating Account..."]}):"Create Account"})]})})]})})}export{de 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.