1import{j as e}from"./ui-DfEcg0Vu.js";import{r as t}from"./vendor--fUMgQTJ.js";import{u as R,r as V,v as q,w as H,x as J,y as $,L as i,I as b,F,H as E,J as I,K as _,M as l,_ as k,g as C,h as B,i as m}from"./index-BZGD9K13.js";function G({open:A,onOpenChange:n,organisations:h,defaultOrgId:o,defaultRole:x="user",onSuccess:T}){const[p,j]=t.useState(!1),[c,g]=t.useState(""),[d,v]=t.useState(""),[f,S]=t.useState(x),[u,w]=t.useState(o||""),{toast:y}=R(),U=async s=>{s.preventDefault(),j(!0);try{const{data:a,error:r}=await m.auth.signUp({email:c,password:L(),options:{emailRedirectTo:`${window.location.origin}/`,data:{full_name:d}}});if(r)throw r;if(a.user){const{error:N}=await m.from("profiles").update({full_name:d,organisation_id:u||null}).eq("id",a.user.id);if(N)throw N;const{error:D}=await m.from("user_roles").insert({user_id:a.user.id,role:f,organisation_id:u||null});if(D)throw D;y({title:"User invited",description:`An invitation has been sent to ${c}.`}),T(),n(!1),M()}}catch(a){y({title:"Error inviting user",description:a.message,variant:"destructive"})}finally{j(!1)}},L=()=>{const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%";let a="";for(let r=0;r<16;r++)a+=s.charAt(Math.floor(Math.random()*s.length));return a},M=()=>{g(""),v(""),S(x),w(o||"")};return e.jsx(V,{open:A,onOpenChange:n,children:e.jsxs(q,{className:"sm:max-w-[450px]",children:[e.jsxs(H,{
1children:[e.jsx(J,{children:"Invite User"}),e.jsx($,{children:"Send an invitation to add a new user to your organisation."})]}),e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"email",children:"Email Address"}),e.jsx(b,{id:"email",type:"email",value:c,onChange:s=>g(s.target.value),placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"fullName",children:"Full Name"}),e.jsx(b,{id:"fullName",value:d,onChange:s=>v(s.target.value),placeholder:"John Doe"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"role",children:"Role"}),e.jsxs(F,{value:f,onValueChange:s=>S(s),children:[e.jsx(E,{children:e.jsx(I,{placeholder:"Select a role"})}),e.jsxs(_,{children:[e.jsx(l,{value:"user",children:"User"}),e.jsx(l,{value:"org_admin",children:"Org Admin"}),e.jsx(l,{value:"super_admin",children:"Super Admin"})]})]})]}),h.length>0&&!o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"organisation",children:"Organisation"}),e.jsxs(F,{value:u,onValueChange:w,children:[e.jsx(E,{children:e.jsx(I,{placeholder:"Select an organisation"})}),e.jsx(_,{children:h.map(s=>e.jsx(l,{value:s.id,children:s.name},s.id))})]})]}),e.jsxs(k,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(C,{type:"submit",disabled:p,children:[p&&e.jsx(B,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Invitation"]})]})]})]})})}export{G as I};
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.