var f=Object.defineProperty;var p=(i,e,t)=>e in i?f(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>(p(i,typeof e!="symbol"?e+"":e,t),t);import{C as b}from"./CrudView.5ea4f8e5.js";import{r as l,c as g,eo as w,d as y,ea as I,e5 as v,k as z,a as M,u as d,o as k}from"./jwt-decode.esm.febfd28e.js";import{j as h}from"./router.f4c1fe8c.js";import{M as C}from"./member.a8b95371.js";import"./tables.5938d0d9.js";import{F as E}from"./folder.010ea7a1.js";import{a as u}from"./ant-design.2cc25b54.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.70530128.js";import"./constants.48af5f1d.js";import"./url.092f6baf.js";import"./PhDotsThreeVertical.vue.7bdc070f.js";import"./index.0e1a642f.js";import"./index.ab72d4ab.js";import"./record.a977dda7.js";import"./string.f661edcd.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[e]="388e14ba-5c44-4ec9-a6cd-9b30814dbeda",i._sentryDebugIdIdentifier="sentry-dbid-388e14ba-5c44-4ec9-a6cd-9b30814dbeda")}catch{}})();class _{constructor({authorEmail:e,organizationId:t,api:o,handlers:r}){a(this,"members",l([]));a(this,"selectedMember",l(null));a(this,"draftMember",l(null));a(this,"table",g(()=>this.makeCrudViewTable()));a(this,"loading",l(!1));a(this,"creationFields",l(null));a(this,"authorEmail");a(this,"organizationId");a(this,"api");a(this,"handlers");a(this,"currentMember",l(null));a(this,"confirmAddMember",async e=>{var r;const t=await this.api.member.create({organizationId:this.organizationId,email:e.email.trim(),teams:e.teams}),o=await this.api.folder.list(this.organizationId);for(const n of o)e.folders.includes(n.id)&&await this.api.folder.update(this.organizationId,{id:n.id,name:n.name,memberIds:((r=n.memberIds)!=null?r:[]).concat(t.id),organizationId:this.organizationId});await this.fetchState()});this.authorEmail=e,this.organizationId=t,this.api=o,this.handlers=r}async fetchState(){this.loading.value=!0,await this.fetchMembers(),await this.fetchCreationFields(),this.setCurrentMember(),this.loading.value=!1}setCurrentMember(){var e;this.currentMember.value=(e=this.members.value.find(t=>t.email===this.authorEmail))!=null?e:null}async fetchMembers(){this.members.value=await this.api.member.list(this.organizationId)}async fetchCreationFields(){const e=await this.api.folder.list(this.organizationId),t=[{key:"email",label:"Email",type:"text"},{key:"folders",label:"Folders",type:"select",mode:"multiple",tooltip:"Select folders this member can access",options:e.map(o=>({label:o.name,value:o.id}))}];this.creationFields.value=t}async removeMember(e){var o;if(((o=h.getAuthor())==null?void 0:o.claims.email)===e.email){await u("Removing your own access will block you from this organization. Are you sure?",{okText:"Remove",cancelText:"Cancel"})&&(await this.api.member.delete({organizationId:this.organizationId,authorId:e.authorId}),this.handlers.onSelfRemove());return}await u(`Are you sure you want to remove ${e.email} access?`,{okText:"Remove",cancelText:"Cancel"})&&(await this.api.member.delete({organizationId:this.organizationId,authorId:e.authorId}),await this.fetchMembers())}makeCrudViewTable(){return{columns:[{title:"Email",align:"center"},{title:"",align:"right"}],rows:this.members.value.map(e=>({key:e.email,cells:[{type:"text",text:e.email},{type:"actions",actions:[{icon:w,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const L=y({__name:"EditorsView",setup(i){var c;const e=I(),t=v(),o=e.params.organizationId,r=new C,n=new E,m=(c=h.getAuthor())==null?void 0:c.claims.email;if(!m)throw new Error("Author email is not available");const s=new _({organizationId:o,api:{member:r,folder:n},authorEmail:m,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return z(async()=>{await s.fetchState()}),s.fetchState(),(A,x)=>(k(),M(b,{"entity-name":"editor",loading:d(s).loading.value,title:"Editors",description:"Manage people who can edit projects within your organization","empty-title":"No editors yet",table:d(s).table.value,"create-button-text":"Invite Editor",fields:d(s).creationFields.value||void 0,create:d(s).confirmAddMember},null,8,["loading","table","fields","create"]))}});export{L as default};
//# sourceMappingURL=EditorsView.4092cca1.js.map
