var p=Object.defineProperty;var b=(i,e,t)=>e in i?p(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>(b(i,typeof e!="symbol"?e+"":e,t),t);import{C as g}from"./CrudView.c0824225.js";import{r as n,c as w,L as m,em as y,d as I,eb as v,e5 as M,J as z,a as C,u as l,o as k}from"./jwt-decode.esm.d4517a10.js";import{l as f}from"./router.424f7da9.js";import{M as E}from"./member.48d6f2cd.js";import"./tables.1f68ec62.js";import{F as _}from"./folder.d8e23009.js";import{a as u}from"./ant-design.a865486e.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.3668aee4.js";import"./constants.7d38ec8b.js";import"./url.e8732f77.js";import"./PhDotsThreeVertical.vue.ab4580a5.js";import"./index.fb182bd1.js";import"./index.4176fe88.js";import"./record.7f43486c.js";import"./string.0acf5572.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]="bf9de62f-6a9c-4d6f-a2e6-e3c35a2f610d",i._sentryDebugIdIdentifier="sentry-dbid-bf9de62f-6a9c-4d6f-a2e6-e3c35a2f610d")}catch{}})();class A{constructor({authorEmail:e,organizationId:t,api:o,handlers:s}){a(this,"members",n([]));a(this,"selectedMember",n(null));a(this,"draftMember",n(null));a(this,"table",w(()=>this.makeCrudViewTable()));a(this,"loading",n(!1));a(this,"creationFields",n(null));a(this,"authorEmail");a(this,"organizationId");a(this,"api");a(this,"handlers");a(this,"currentMember",n(null));a(this,"confirmAddMember",async e=>{const t=m.object({email:m.string().email(),folders:m.string().array().optional()}).parse(e);await this.api.member.create({organizationId:this.organizationId,email:t.email.trim(),folderIds:t.folders}),await this.fetchState()});this.authorEmail=e,this.organizationId=t,this.api=o,this.handlers=s}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=f.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:y,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const O=I({__name:"EditorsView",setup(i){var c;const e=v(),t=M(),o=e.params.organizationId,s=new E,h=new _,d=(c=f.getAuthor())==null?void 0:c.claims.email;if(!d)throw new Error("Author email is not available");const r=new A({organizationId:o,api:{member:s,folder:h},authorEmail:d,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return z(async()=>{await r.fetchState()}),r.fetchState(),(x,F)=>(k(),C(g,{"entity-name":"editor",loading:l(r).loading.value,title:"Editors",description:"Manage people who can edit projects within your organization","empty-title":"No editors yet",table:l(r).table.value,"create-button-text":"Invite Editor",fields:l(r).creationFields.value||void 0,create:l(r).confirmAddMember},null,8,["loading","table","fields","create"]))}});export{O as default};
//# sourceMappingURL=EditorsView.e72621fa.js.map
