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.cc6aeaf0.js";import{r as n,c as w,L as d,en 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.54a1ea22.js";import{l as h}from"./router.4dfadf5d.js";import{M as E}from"./member.2260c37e.js";import"./tables.1bcb1140.js";import{F as _}from"./folder.13d3acac.js";import{a as u}from"./ant-design.42419021.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.689d8ce7.js";import"./constants.d569f33d.js";import"./url.f5664225.js";import"./PhDotsThreeVertical.vue.5e8ae2a9.js";import"./index.966ac1b9.js";import"./index.c7a996a6.js";import"./record.e83a2eb2.js";import"./string.61e11a30.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]="9e3d787f-d51e-48e0-a3d5-394b920256a1",i._sentryDebugIdIdentifier="sentry-dbid-9e3d787f-d51e-48e0-a3d5-394b920256a1")}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=d.object({email:d.string().email(),folders:d.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=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: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,f=new _,m=(c=h.getAuthor())==null?void 0:c.claims.email;if(!m)throw new Error("Author email is not available");const r=new A({organizationId:o,api:{member:s,folder:f},authorEmail:m,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.fcdf0186.js.map
