import{C as u}from"./CrudView-wZnp03a2.js";import{r as n,e as h,an as f,d as p,S as b,T as g,X as w,B as y,m as I,D as s}from"./jwt-decode.esm-Dca5fHH5.js";import{b as m}from"./router-D5wfdag3.js";import{M as v}from"./member-BNIMJ1hR.js";import"./tables-BsqTY_wE.js";import{F as z}from"./folder-CMrXs2lc.js";import{a as d}from"./ant-design-12Ybi1Rk.js";import"./DocsButton.vue_vue_type_script_setup_true_lang-BnwqPwfA.js";import"./constants-B1LrRAnj.js";import"./url-CoyBb3Dp.js";import"./PhDotsThreeVertical.vue-B1x6I4wD.js";import"./index-ZQBk4l6i.js";import"./index-Cyx2lZTa.js";import"./record-BZIfMWML.js";import"./string-BYR4BIXr.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[e]="c2709ca6-7c09-4106-962d-dcc4b8e4d15b",o._sentryDebugIdIdentifier="sentry-dbid-c2709ca6-7c09-4106-962d-dcc4b8e4d15b")}catch{}})();class M{members=n([]);selectedMember=n(null);draftMember=n(null);table=h(()=>this.makeCrudViewTable());loading=n(!1);creationFields=n(null);authorEmail;organizationId;api;handlers;currentMember=n(null);constructor({authorEmail:e,organizationId:t,api:a,handlers:i}){this.authorEmail=e,this.organizationId=t,this.api=a,this.handlers=i}async fetchState(){this.loading.value=!0,await this.fetchMembers(),await this.fetchCreationFields(),this.setCurrentMember(),this.loading.value=!1}setCurrentMember(){this.currentMember.value=this.members.value.find(e=>e.email===this.authorEmail)??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(a=>({label:a.name,value:a.id}))}];this.creationFields.value=t}confirmAddMember=async e=>{const t=await this.api.member.create({organizationId:this.organizationId,email:e.email.trim(),teams:e.teams}),a=await this.api.folder.list(this.organizationId);for(const i of a)e.folders.includes(i.id)&&await this.api.folder.update(this.organizationId,{id:i.id,name:i.name,memberIds:(i.memberIds??[]).concat(t.id),organizationId:this.organizationId});await this.fetchState()};async removeMember(e){if(m.getAuthor()?.claims.email===e.email){await d("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 d(`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:f,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const X=p({__name:"EditorsView",setup(o){const e=b(),t=g(),a=e.params.organizationId,i=new v,c=new z,l=m.getAuthor()?.claims.email;if(!l)throw new Error("Author email is not available");const r=new M({organizationId:a,api:{member:i,folder:c},authorEmail:l,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return w(async()=>{await r.fetchState()}),r.fetchState(),(C,k)=>(I(),y(u,{"entity-name":"editor",loading:s(r).loading.value,title:"Editors",description:"Manage people who can edit projects within your organization","empty-title":"No editors yet",table:s(r).table.value,"create-button-text":"Invite Editor",fields:s(r).creationFields.value||void 0,create:s(r).confirmAddMember},null,8,["loading","table","fields","create"]))}});export{X as default};
//# sourceMappingURL=EditorsView-BALXdstS.js.map
