PageSourceSearch

https://mindgolf.ai/assets/OrgActivate-ByfgiTaW.js

js mindgolf.ai collected 2026-10-05 14:53:34 UTC 9,171 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/coachApplicationPrefill--HGMamxh.js","assets/index-DXi0I5ak.js","assets/vendor-ahVw9cdH.js","assets/radix--pSzM2y8.js","assets/supabase-DYrB2Yg5.js","assets/charts-CSweoJhv.js","assets/query-CeIq2NOR.js","assets/forms-Cc1FL3tT.js","assets/index-BxWLd995.css"])))=>i.map(i=>d[i]);
2import{aG as X,O as r,R as F,a5 as j,aW as b,bd as N,bp as z,a6 as k,V as A,ev as K,eu as Q,bJ as O,bC as I,ew as Z}from"./index-DXi0I5ak.js";import{m as ee,n as ae,r as m,j as e}from"./vendor-ahVw9cdH.js";import{C as B}from"./circle-x-gCUm4_Za.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./query-CeIq2NOR.js";import"./forms-Cc1FL3tT.js";const de=()=>{const[$]=ee(),g=ae(),{toast:h}=X(),P=$.get("token"),[x,l]=m.useState("loading"),[i,U]=m.useState(null),[p,V]=m.useState(""),[q,W]=m.useState(""),[E,S]=m.useState(!1);m.useEffect(()=>{if(!P){l("error");return}G()},[P]);const G=async()=>{try{const{data:c,error:_}=await r.rpc("validate_activation_token",{p_token:P});if(_||!c){l("error");return}const s=c;if(s.status==="converted"){l("used");return}if(s.token_expires_at&&new Date(s.token_expires_at)<new Date){l("expired");return}U({id:s.id,organization_name:s.organization_name,organization_type:s.organization_type,contact_name:s.contact_name,contact_email:s.contact_email,requested_tier:s.requested_tier}),l("valid")}catch{l("error")}},R=async c=>{var _,s,D,L,T;if(c.preventDefault(),p!==q){h({title:"Passwords don't match",description:"Please ensure both passwords are identical.",variant:"destructive"});return}if(p.length<8){h({title:"Password too short",description:"Password must be at least 8 characters.",variant:"destructive"});return}if(i){S(!0);try{let n;const{data:w,error:v}=await r.auth.signUp({email:i.contact_email,password:p,options:{data:{name:i.contact_name,account_type:"coach",org_application_id:i.id}}});if(v)if(v.message.includes("already registered")||v.message.includes("already been registered")){const{data:a,error:t}=await r.auth.signInWithPassword({email:i.contact_email,password:p});if(t)throw new Error("Account exists but password is incorrect. Please use the password you set previously.");if(!a.user)throw new Error("Failed to sign in");n=a.user.id}else throw v;else{if(!w.user)throw new Error("Failed to create user");n=w.user.id}const Y=i.organization_name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),H={coach:1,academy:200,federation:1e4};let o=null;const{data:C}=await r.from("organization_applications").select("status").eq("id",i.id).maybeSingle();if((C==null?void 0:C.status)==="converted"){const{data:a}=await r.from("organizations").select("slug").eq("type",i.organization_type).in("id",((_=(await r.from("organization_members").select("organization_id").eq("user_id",n).eq("role","owner")).data)==null?void 0:_.map(t=>t.organization_id))??[]).order("created_at",{ascending:!1}).limit(1).maybeSingle();o=(a==null?void 0:a.slug)??null}if(!o){const{data:a,error:t}=await r.rpc("register_organization",{p_name:i.organization_name,p_type:i.organization_type,p_slug:`${Y}-${Date.now().toString(36)}`,p_user_id:n,p_tier:i.requested_tier,p_player_limit:H[i.requested_tier]||15});if(t)throw t;o=a}if(o)try{const{data:a}=await r.from("organization_applications").select("application_details").eq("id",i.id).single(),{data:t}=await r.from("organizations").select("id, name, website, country_id, town_id").eq("slug",o).single(),d=(a==null?void 0:a.application_details)??null;if(d&&t){const{buildPrefillPatch:f,applyPrefillPatch:u}=await Z(async()=>{const{buildPrefillPatch:J,applyPrefillPatch:M}=await import("./coachApplicationPrefill--HGMamxh.js");return{buildPrefillPatch:J,applyPrefillPatch:M}},__vite__mapDeps([0,1,2,3,4,5,6,7,8])),y=await f(d,{name:t.name,website:t.website,country_id:t.country_id,town_id:t.town_id,years_experience:null,certifications:null,specialties:null,player_levels:null});await u(t.id,y)}}catch(a){console.warn("[OrgActivate] Auto-prefill failed:",a)}try{const{data:a}=await r.from("organization_applications").select("application_details").eq("id",i.id).single(),t=a==null?void 0:a.application_details;if(t&&o){const{data:d}=await r.from("organizations").select("id").eq("slug",o).single();if(d){const f=[];((s=t.federationAffiliation)==null?void 0:s.type)==="existing"&&((D=t.federationAffiliation)!=null&&D.id)&&f.push({parentOrgId:t.federationAffiliation.id,childOrgId:d.id}),((L=t.academyAffiliation)==null?void 0:L.type)==="existing"&&((T=t.academyAffiliation)!=null&&T.id)&&f.push({parentOrgId:t.academyAffiliation.id,childOrgId:d.id});for(const u of f){const{error:y}=await r.from("organization_affiliations").insert({parent_org_id:u.parentOrgId,child_org_id:u.childOrgId,status:"pending"});y?console.error("[OrgActivate] Affiliation insert error:",y):r.functions.invoke("notify-affiliation-request",{body:{parentOrgId:u.parentOrgId,childOrgId:u.childOrgId}}).catch(console.error)}}}}catch(a){console.error("[OrgActivate] Auto-affiliation error:",a)}await r.from("organization_applications").update({status:"converted"}).eq("id",i.id);try{const{data:a}=await r.from("organizations").select("id").eq("slug",o).single();a!=null&&a.id&&await r.rpc("link_coach_referral_to_org",{p_application_id:i.id,p_org_id:a.id})}catch(a){console.warn("[OrgActivate] link_coach_referral_to_org failed:",a)}h({title:"Account activated!",description:"Let's finish setting up your coaching hub…"}),setTimeout(()=>{g(`/org/${o}/onboarding`)},1500)}catch(n){const w=n&&typeof n=="object"&&"message"in n&&n.message||(typeof n=="string"?n:"Failed to activate account");console.error("[OrgActivate] activation failed:",n),h({title:"Activation failed",description:String(w),variant:"destructive"})}finally{S(!1)}}};return x==="loading"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(F,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:"Validating your invitation..."})]})}):x==="expired"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(j,{className:"max-w-md w-full",children:[e.jsxs(b,{className:"text-center",children:[e.jsx(B,{className:"h-12 w-12 text-destructive mx-auto mb-2"}),e.jsx(N,{children:"Invitation Expired"}),e.jsx(z,{children:"This activation link has expired. Please contact support to request a new invitation."})]}),e.jsx(k,{children:e.jsx(A,{onClick:()=>g("/for-coaches"),className:"w-full",variant:"outline",children:"Back to Organizations"})})]})}):x==="used"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(j,{className:"max-w-md w-full",children:[e.jsxs(b,{className:"text-center",children:[e.jsx(K,{className:"h-12 w-12 text-green-500 mx-auto mb-2"}),e.jsx(N,{children:"Already Activated"}),e.jsx(z,{children:"This invitation has already been used. You can log in to your account."})]}),e.jsx(k,{children:e.jsx(A,{onClick:()=>g("/auth"),className:"w-full",children:"Go to Login"})})]})}):x==="error"||!i?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(j,{className:"max-w-md w-full",children:[e.jsxs(b,{className:"text-center",children:[e.jsx(B,{className:"h-12 w-12 text-destructive mx-auto mb-2"}),e.jsx(N,{children:"Invalid Invitation"}
2),e.jsx(z,{children:"This activation link is invalid or has been revoked."})]}),e.jsx(k,{children:e.jsx(A,{onClick:()=>g("/for-coaches"),className:"w-full",variant:"outline",children:"Back to Organizations"})})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(j,{className:"max-w-md w-full",children:[e.jsxs(b,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Q,{className:"h-6 w-6 text-primary"})}),e.jsx(N,{children:"Activate Your Organization"}),e.jsxs(z,{children:["Welcome, ",i.contact_name,"! Set up your password to activate"," ",e.jsx("strong",{children:i.organization_name}),"."]})]}),e.jsx(k,{children:e.jsxs("form",{onSubmit:R,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Email"}),e.jsx(I,{type:"email",value:i.contact_email,disabled:!0,className:"bg-muted"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"password",children:"Password"}),e.jsx(I,{id:"password",type:"password",value:p,onChange:c=>V(c.target.value),placeholder:"Create a password",required:!0,minLength:8})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"confirmPassword",children:"Confirm Password"}),e.jsx(I,{id:"confirmPassword",type:"password",value:q,onChange:c=>W(c.target.value),placeholder:"Confirm your password",required:!0})]}),e.jsx(A,{type:"submit",className:"w-full",disabled:E,children:E?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Activating..."]}):"Activate & Continue"})]})})]})})};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.