码桶
发现社区成员的开源项目
Members-BrwQnl87.js5.2 KB
import{u as F,c as K,r as l,b as d,j as t,S as B,T as m,o as c,C as z,aZ as W,B as C,F as H}from"./index-GWuvg2UH.js";import{B as p}from"./index-DihvOmSo.js";import{E as j}from"./index-VbOLTMR0.js";import{M as Z}from"./Modal-08QhW3n9.js";import{S as N}from"./index-BZDftoba.js";import{T as I}from"./index-mZVFvfKe.js";import{T as o}from"./index-BW_2QB9V.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./index-DIHsQVbu.js";import"./slice-B6jKCnyX.js";import"./object-DkPZvw8u.js";import"./index-BMbdBPA2.js";const h={owner:"green",editor:"blue",viewer:"amber"};function le(){const{t:e}=F(),{site:i,sites:R}=K(),[a,b]=l.useState(null),[O,k]=l.useState([]),[M,f]=l.useState(!1),[x,v]=l.useState(""),[y,$]=l.useState("viewer"),[_,T]=l.useState(!1),[S,E]=l.useState(""),u=!!i&&i.role==="owner",n=l.useCallback(async()=>{if(i){f(!0);try{const r=await d.members(i.id);b(r),E("")}catch(r){E(r.message),b(null)}finally{f(!1)}try{const r=await d.sharedWithMe();k(r.items||[])}catch{}}},[i]);l.useEffect(()=>{n()},[n]);const w=r=>({owner:e("roleOwner"),editor:e("roleEditor"),viewer:e("roleViewer")})[r]||r,A=r=>({owner:e("roleOwnerTip"),editor:e("roleEditorTip"),viewer:e("roleViewerTip")})[r]||"",L=async()=>{if(!x.trim()){o.warning(e("memberEmailPh"));return}T(!0);try{await d.addMember(i.id,{email:x.trim(),role:y}),o.success(e("memberAdded")),v(""),n()}catch(r){o.error(r.message)}finally{T(!1)}},V=async(r,s)=>{try{await d.updateMember(i.id,r.id,{role:s}),o.success(e("memberRoleSaved")),n()}catch(g){o.error(g.message)}},P=r=>{Z.confirm({title:e("delete"),content:e("memberDelConfirm"),okButtonProps:{type:"danger",theme:"solid"},onOk:async()=>{try{await d.removeMember(i.id,r.id),o.success(e("memberRemoved")),n()}catch(s){o.error(s.message)}}})},D=[{title:e("memberEmail"),dataIndex:"email",ellipsis:{showTitle:!0},render:(r,s)=>t.jsxs(B,{spacing:8,children:[t.jsx("span",{children:r}),s.nickname?t.jsx(m.Text,{type:"tertiary",style:{fontSize:12},children:s.nickname}):null]})},{title:e("memberRole"),dataIndex:"role",width:200,render:(r,s)=>s.is_owner?t.jsx(c,{color:h.owner,size:"small",children:e("roleOwner")}):u?t.jsx(z,{size:"small",value:r,style:{width:140},onChange:g=>V(s,g),optionList:[{value:"editor",label:`${e("roleEditor")} — ${e("roleEditorTip")}`},{value:"viewer",label:`${e("roleViewer")} — ${e("roleViewerTip")}`}]}):t.jsx(c,{color:h[r],size:"small",children:w(r)})},{title:e("time"),dataIndex:"created_at",width:130,render:r=>r?W(r):"-"},{title:e("actions"),dataIndex:"id",width:90,render:(r,s)=>s.is_owner||!u?t.jsx(m.Text,{type:"tertiary",style:{fontSize:12},children:"—"}):t.jsx(C,{size:"small",type:"danger",theme:"borderless",onClick:()=>P(s),children:e("delete")})}];return i?t.jsxs("div",{className:"page",children:[t.jsxs("div",{className:"toolbar",style:{justifyContent:"space-between"},children:[t.jsxs("div",{children:[t.jsx(m.Title,{heading:5,style:{margin:0},children:e("memberTitle")}),t.jsxs(m.Text,{type:"tertiary",style:{fontSize:12},children:[i.name," · ",i.domain]})]}),t.jsxs(c,{color:h[i.role],size:"small",children:[e("yourRole"),": ",w(i.role)]})]}),t.jsx(p,{type:"info",description:e("memberIntro"),style:{marginBottom:12}}),S&&t.jsx(p,{type:"danger",description:S,style:{marginBottom:12}}),a&&a.member_table===!1&&t.jsx(p,{type:"warning",description:e("memberNoTable"),style:{marginBottom:12}}),u?t.jsxs("div",{className:"card",style:{marginBottom:16},children:[t.jsx("div",{className:"card-title",children:e("memberAdd")}),t.jsxs(B,{wrap:!0,spacing:12,style:{paddingBottom:4},children:[t.jsx(H,{style:{width:280},value:x,onChange:v,placeholder:e("memberEmailPh"),showClear:!0}),t.jsx(z,{value:y,style:{width:150},onChange:$,optionList:[{value:"viewer",label:e("roleViewer")},{value:"editor",label:e("roleEditor")}]}),t.jsx(C,{theme:"solid",loading:_,onClick:L,children:e("memberAdd")}),t.jsx(m.Text,{type:"tertiary",style:{fontSize:12},children:A(y)})]})]}):t.jsx(p,{type:"warning",description:e("memberOwnerOnly"),style:{marginBottom:16}}),t.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden",marginBottom:16},children:[t.jsxs("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:[e("members"),a!=null&&a.items?` · ${a.items.length}`:""]}),M&&!a?t.jsx("div",{style:{padding:16},children:t.jsx(N,{active:!0,placeholder:t.jsx(N.Paragraph,{rows:3}),loading:!0})}):t.jsx(I,{columns:D,dataSource:(a==null?void 0:a.items)||[],rowKey:r=>String(r.id)+r.email,pagination:!1,size:"middle",empty:t.jsx(j,{description:e("memberEmpty")})})]}),t.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[t.jsx("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:e("sharedWithMe")}),t.jsx(I,{columns:[{title:e("siteName"),dataIndex:"name",ellipsis:{showTitle:!0}},{title:e("domain"),dataIndex:"domain",width:220,ellipsis:{showTitle:!0}},{title:e("sharedBy"),dataIndex:"owner_email",width:220,ellipsis:{showTitle:!0},render:(r,s)=>r||s.owner_name||"-"},{title:e("sharedRole"),dataIndex:"role",width:110,render:r=>t.jsx(c,{color:h[r],size:"small",children:w(r)})}],dataSource:O,rowKey:"id",pagination:!1,size:"small",empty:t.jsx(j,{description:`${e("memberEmpty")} · ${R.length} ${e("sites")}`})})]})]}):t.jsx("div",{className:"page",children:t.jsx(j,{style:{marginTop:60},title:e("noSiteHint")})})}export{le as default};