PageSourceSearch

https://keepreap.com/assets/AdminUsers-CUYpAHjV.js

js keepreap.com collected 2026-09-24 14:46:32 UTC 19,591 bytes, 11 lines download raw bytes

1import{aL as D,u as S,r as i,j as e,o as P,B as _,aM as Q,aN as F,aO as $,L as G,d as v,H,aP as Z,i as K,aQ as Y}from"./index.js";import{A as J,w as V,B as W,C as X,r as ee}from"./adminApi-ChUnuVlD.js";import{e as ae}from"./admin-error-bA98pF4E.js";import{u as se}from"./useDebounce-Pg4z2umB.js";/**
2 * @license lucide-react v0.460.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const te=D("Coins",[["circle",{cx:"8",cy:"8",r:"6",key:"3yglwk"}],["path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18",key:"t5s6rm"}],["path",{d:"M7 6h1v4",key:"1obek4"}],["path",{d:"m16.71 13.88.7.71-2.82 2.82",key:"1rbuyh"}]]);/**
7 * @license lucide-react v0.460.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const re=D("Crown",[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]]);function ne({open:a,onClose:l,target:t}){const{t:s}=S(),[n,h]=i.useState(""),[x,d]=i.useState(""),[f,N]=J(),[u,b]=i.useState(null);i.useEffect(()=>{a&&(h(""),d(""),b(null))},[a,t==null?void 0:t.id]);const p=Number.parseInt(n,10),j=Number.isInteger(p)&&p!==0,w=j&&p<0,y=async()=>{if(!(!t||!j)){b(null);try{const c=await f({targetUserId:t.id,creditsAmount:p,reason:x.trim()?x.trim():void 0}).unwrap();b({kind:"success",creditsAdded:c.creditsAdded}),h(""),d("")}catch(c){const m=c instanceof Error?c.message:"Grant failed";b({kind:"error",message:m})}}};return e.jsx(P,{open:a,onClose:l,title:s("admin.credits.grant_modal_title"),footer:e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:l,children:s("admin.credits.grant_modal_close")}),e.jsx(_,{variant:"primary",size:"sm",onClick:y,disabled:!j||!t,loading:N.isLoading,children:s("admin.credits.grant_modal_submit")})]}),children:t?e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"border-brand-border bg-brand-surface rounded-2xl border p-3",children:[e.jsx("p",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.credits.grant_modal_target_label")}),e.jsx("p",{className:"text-brand-text-1 mt-1 font-medium",children:t.name??t.email}),e.jsx("p",{className:"text-brand-text-3 text-xs",children:t.email}),e.jsx("p",{className:"text-brand-text-3 mt-1 truncate font-mono text-[10px]",children:t.id})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.credits.grant_modal_amount_label")}),e.jsx("input",{type:"number",inputMode:"numeric",step:"1",value:n,onChange:c=>h(c.target.value),placeholder:"500",className:"border-brand-border bg-brand-bg text-brand-text-1 focus:border-brand-primary mt-1 w-full rounded-2xl border px-3 py-2 font-mono text-sm outline-none"}),w?e.jsx("p",{className:"text-brand-warning mt-1 text-xs",children:s("admin.credits.grant_modal_negative_note")}):null]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.credits.grant_modal_reason_label")}),e.jsx("textarea",{value:x,onChange:c=>d(c.target.value),placeholder:s("admin.credits.grant_modal_reason_placeholder"),rows:2,className:"border-brand-border bg-brand-bg text-brand-text-1 focus:border-brand-primary mt-1 w-full rounded-2xl border px-3 py-2 text-sm outline-none"})]}),(u==null?void 0:u.kind)==="success"?e.jsx("p",{className:"text-brand-success text-sm",children:s("admin.credits.grant_modal_success",{credits:u.creditsAdded})}):null,(u==null?void 0:u.kind)==="error"?e.jsx("p",{className:"text-brand-danger text-sm",children:u.message}):null]}):e.jsx("p",{className:"text-brand-text-3 text-sm",children:s("admin.credits.grant_modal_no_target")})})}const le=F.options;function de(a){if(!a)return"";const l=new Date(a);return Number.isNaN(l.getTime())?"":l.toISOString().slice(0,10)}function ie(a){if(!a)return null;const l=new Date(`${a}T23:59:59.999Z`);return Number.isNaN(l.getTime())?null:l.toISOString()}function ce({open:a,onClose:l,target:t}){const{t:s}=S(),{data:n,isLoading:h}=V({userId:(t==null?void 0:t.id)??""},{skip:!a||!t}),[x,d]=W(),[f,N]=i.useState("free"),[u,b]=i.useState(""),[p,j]=i.useState(!1),[w,y]=i.useState(""),[c,m]=i.useState(null),[C,A]=i.useState(null);i.useEffect(()=>{a&&(y(""),m(null))},[a,t==null?void 0:t.id]),i.useEffect(()=>{a||A(null)},[a]),i.useEffect(()=>{!a||!n||C===n.userId||(N(n.plan),b(de(n.currentPeriodEndsAt)),j(n.unlimitedCredits),A(n.userId))},[a,n,C]);const k=$(f),L=async()=>
11{if(t){m(null);try{await x({userId:t.id,plan:f,currentPeriodEndsAt:k?ie(u):null,unlimitedCredits:p,reason:w.trim()?w.trim():void 0}).unwrap(),m({kind:"success",plan:f})}catch(o){const g=ae(o);m({kind:"error",message:g??(o instanceof Error?o.message:s("admin.plan.set_modal_error"))})}}};return e.jsx(P,{open:a,onClose:l,title:s("admin.plan.set_modal_title"),footer:e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:l,children:s("admin.plan.set_modal_close")}),e.jsx(_,{variant:"primary",size:"sm",onClick:()=>void L(),disabled:!t||h,loading:d.isLoading,children:s("admin.plan.set_modal_submit")})]}),children:t?e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"border-brand-border bg-brand-surface rounded-2xl border p-3",children:[e.jsx("p",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.plan.set_modal_target_label")}),e.jsx("p",{className:"text-brand-text-1 mt-1 font-medium",children:t.name??t.email}),e.jsx("p",{className:"text-brand-text-3 text-xs",children:t.email}),e.jsx("p",{className:"text-brand-text-3 mt-1 truncate font-mono text-[10px]",children:t.id})]}),n!=null&&n.hasActiveSubscription?e.jsxs("div",{className:"border-brand-warning/40 bg-brand-warning/10 flex gap-2 rounded-2xl border p-3",children:[e.jsx(Q,{className:"text-brand-warning mt-0.5 h-4 w-4 shrink-0"}),e.jsx("p",{className:"text-brand-text-2 text-xs",children:s("admin.plan.set_modal_stripe_warning")})]}):null,e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.plan.set_modal_plan_label")}),e.jsx("select",{value:f,onChange:o=>N(o.target.value),className:"border-brand-border bg-brand-bg text-brand-text-1 focus:border-brand-primary mt-1 w-full rounded-2xl border px-3 py-2 text-sm outline-none","aria-label":s("admin.plan.set_modal_plan_label"),children:le.map(o=>e.jsx("option",{value:o,children:s(`admin.users.plan_${o}`)},o))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.plan.set_modal_expires_label")}),e.jsx("input",{type:"date",value:k?u:"",onChange:o=>b(o.target.value),disabled:!k,className:"border-brand-border bg-brand-bg text-brand-text-1 focus:border-brand-primary mt-1 w-full rounded-2xl border px-3 py-2 font-mono text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50","aria-label":s("admin.plan.set_modal_expires_label")}),e.jsx("p",{className:"text-brand-text-3 mt-1 text-xs",children:s(k?"admin.plan.set_modal_expires_hint":"admin.plan.set_modal_expires_never_hint")})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:o=>j(o.target.checked),className:"accent-brand-primary mt-0.5 h-4 w-4","aria-label":s("admin.plan.set_modal_unlimited_label")}),e.jsxs("span",{children:[e.jsx("span",{className:"text-brand-text-1 text-sm",children:s("admin.plan.set_modal_unlimited_label")}),e.jsx("span",{className:"text-brand-text-3 block text-xs",children:s("admin.plan.set_modal_unlimited_hint")})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.plan.set_modal_reason_label")}),e.jsx("textarea",{value:w,onChange:o=>y(o.target.value),placeholder:s("admin.plan.set_modal_reason_placeholder"),rows:2,maxLength:500,className:"border-brand-border bg-brand-bg text-brand-text-1 focus:border-brand-primary mt-1 w-full rounded-2xl border px-3 py-2 text-sm outline-none"})]}),(c==null?void 0:c.kind)==="success"?e.jsx("p",{className:"text-brand-success text-sm",children:s("admin.plan.set_modal_success",{plan:s(`admin.users.plan_${c.plan}`)})}):null,(c==null?void 0:c.kind)==="error"?e.jsx("p",{className:"text-brand-danger text-sm",children:s("admin.plan.set_modal_error_detail",{code:c.message})}):null]}):e.jsx("p",{className:"text-brand-text-3 text-sm",children:s("admin.plan.set_modal_no_target")})})}const oe={pending:"admin.referrals.status_pending",qualified:"admin.referrals.status_qualified",rewarded:"admin.referrals.status_rewarded",rejected_abuse:"admin.referrals.status_rejected_abuse"};
11function me(a){return a?new Date(a).toLocaleDateString():"—"}function xe({open:a,onClose:l,target:t}){const{t:s}=S(),{data:n,error:h,isLoading:x}=X({userId:(t==null?void 0:t.id)??""},{skip:!a||!t});return e.jsx(P,{open:a,onClose:l,title:s("admin.referrals.modal_title"),className:"max-w-2xl",footer:e.jsx(_,{variant:"outline",size:"sm",onClick:l,children:s("admin.referrals.modal_close")}),children:t?e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"border-brand-border bg-brand-surface rounded-2xl border p-3",children:[e.jsx("p",{className:"text-brand-text-2 text-xs uppercase tracking-wide",children:s("admin.referrals.modal_target_label")}),e.jsx("p",{className:"text-brand-text-1 mt-1 font-medium",children:t.name??t.email}),e.jsx("p",{className:"text-brand-text-3 text-xs",children:t.email}),e.jsx("p",{className:"text-brand-text-3 mt-1 truncate font-mono text-[10px]",children:t.id})]}),x?e.jsx(G,{scope:"inline",label:s("common.loading")}):null,h?e.jsx("p",{className:"text-brand-danger text-sm",children:s("admin.referrals.load_error")}):null,n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-2",children:[e.jsx(E,{label:s("settings.referrals.invited"),value:n.stats.invited}),e.jsx(E,{label:s("settings.referrals.qualified"),value:n.stats.qualified}),e.jsx(E,{label:s("settings.referrals.earned"),value:n.stats.earned}),e.jsxs("div",{className:"ml-auto text-right",children:[e.jsx("p",{className:"text-brand-text-2 text-[10px] uppercase tracking-wide",children:s("admin.referrals.code_label")}),e.jsxs("p",{className:"text-brand-text-1 font-mono text-sm",children:[n.code??s("admin.referrals.code_none"),n.codeBanned?e.jsx("span",{className:"bg-brand-danger text-brand-on-primary ml-2 rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide",children:s("admin.referrals.code_banned")}):null]})]})]}),n.items.length===0?e.jsx("p",{className:"text-brand-text-3 text-sm",children:s("admin.referrals.empty")}):e.jsx("ul",{className:"border-brand-border divide-brand-border divide-y rounded-2xl border",children:n.items.map(d=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-brand-text-1 truncate text-sm font-medium",children:d.refereeName??d.refereeEmail.split("@")[0]}),e.jsx("p",{className:"text-brand-text-3 truncate text-xs",children:d.refereeEmail}),d.rejectionReason?e.jsx("p",{className:"text-brand-text-3 mt-0.5 font-mono text-[10px]",children:d.rejectionReason}):null]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx(ue,{status:d.status}),e.jsx("p",{className:"text-brand-text-3 mt-1 text-[10px]",children:s("admin.referrals.signed_up_on",{date:me(d.signupAt)})}),d.rewardCreditsAmount?e.jsx("p",{className:"text-brand-text-2 text-[10px]",children:s("admin.referrals.reward_credits",{credits:d.rewardCreditsAmount})}):null]})]},d.id))})]}):null]}):e.jsx("p",{className:"text-brand-text-3 text-sm",children:s("admin.referrals.no_target")})})}function E({label:a,value:l}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-brand-text-2 text-[10px] uppercase tracking-wide",children:a}),e.jsx("p",{className:"text-brand-text-1 text-lg font-semibold tabular-nums",children:l})]})}function ue({status:a}){const{t:l}=S();return e.jsx("span",{className:v("inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide",a==="rewarded"?"bg-brand-primary text-brand-on-primary":a==="rejected_abuse"?"bg-brand-danger text-brand-on-primary":"bg-brand-surface text-brand-text-2"),children:l(oe[a])})}const M=50;function U(a,l){return a?new Date(a).toLocaleDateString():l}function be(a){var t;return(((t=a.name)==null?void 0:t.trim())||a.email.trim()||"?").charAt(0).toUpperCase()}function _e(){var T;const{t:a}=S(),[l,t]=i.useState(""),s=se(l,250),[n,h]=i.useState("created_at_desc"),[x,d]=i.useState(0),[f,N]=i.useState(null),[u,b]=i.useState(null),[p,j]=i.useState(null),y=((T=H().data)==null?void 0:T.staffRole)==="superadmin",c=i.useMemo(()=>({limit:M,offset:x,search:s.trim(),sort:n}),[x,s,n]),{data:m,error:C,isLoading:A,isFetching:k}=ee(c);function L(r){t(r),d(0)}function o(r){h(r),d(0)}const g=(m==null?void 0:m.total)??0,R=(m==null?void 0:m.items)??[],I=(m==null?void 0:m.limit)??M,z=x===0,B=x+I>=g,q=g===0?0:x+1,O=Math.min(x+I,g);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("header",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-brand-text-1 flex items-center gap-2 text-2xl font-semibold",children:[e.jsx(Z,{className:"h-6 w-6"}),a("admin.users.title")]}),e.jsx("p",{className:"text-brand-text-3 mt-1 text-sm",children:a("admin.users.subtitle")})]})}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("input",{type:"search",value:l,onCh
11ange:r=>L(r.target.value),placeholder:a("admin.users.search_placeholder"),className:v("border-brand-border bg-brand-bg text-brand-text-1 placeholder:text-brand-text-3","w-full rounded-full border px-4 py-2 text-sm sm:max-w-xs","focus:border-brand-primary focus:outline-none"),"aria-label":a("admin.users.search_placeholder")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-brand-text-3 text-xs",htmlFor:"admin-users-sort",children:a("admin.users.sort_label")}),e.jsxs("select",{id:"admin-users-sort",value:n,onChange:r=>o(r.target.value),className:v("border-brand-border bg-brand-bg text-brand-text-1","rounded-full border px-3 py-1.5 text-sm","focus:border-brand-primary focus:outline-none"),children:[e.jsx("option",{value:"created_at_desc",children:a("admin.users.sort_created_desc")}),e.jsx("option",{value:"last_login_at_desc",children:a("admin.users.sort_last_login_desc")})]})]})]}),A?e.jsx(G,{scope:"page"}):C?e.jsx("p",{className:"text-brand-text-2 text-sm",children:a("admin.users.error")}):g===0?e.jsx("p",{className:"text-brand-text-3 text-sm",children:s.trim()?a("admin.users.no_results",{query:s.trim()}):a("admin.users.empty")}):e.jsx("section",{"aria-busy":k,className:v("bg-brand-bg border-brand-border-subtle overflow-x-auto rounded-xl border"),children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"border-brand-border bg-brand-surface text-brand-text-2 border-b text-xs uppercase",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2.5",children:a("admin.users.col_user")}),e.jsx("th",{className:"px-4 py-2.5",children:a("admin.users.col_plan")}),e.jsx("th",{className:"px-4 py-2.5",children:a("admin.users.col_created")}),e.jsx("th",{className:"px-4 py-2.5",children:a("admin.users.col_last_login")}),e.jsx("th",{className:"px-4 py-2.5 text-right",children:a("admin.users.col_actions")})]})}),e.jsx("tbody",{className:"text-brand-text-1",children:R.map(r=>e.jsxs("tr",{className:"border-brand-border border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[r.pictureUrl?e.jsx("img",{src:r.pictureUrl,alt:"",className:"bg-brand-surface h-9 w-9 rounded-full object-cover",referrerPolicy:"no-referrer"}):e.jsx("div",{className:"bg-brand-surface text-brand-text-2 flex h-9 w-9 items-center justify-center rounded-full text-sm font-medium",children:be(r)}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-brand-text-1 flex items-center gap-2 truncate text-sm font-medium",children:[r.name??r.email.split("@")[0],r.isAdmin?e.jsx("span",{className:"bg-brand-primary text-brand-on-primary rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide",children:a("admin.users.admin_chip")}):null]}),e.jsx("div",{className:"text-brand-text-3 truncate text-xs",children:e.jsx(K,{to:`/admin/users/${r.id}`,className:"hover:text-brand-text-1 hover:underline",children:r.email})})]})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(pe,{plan:r.plan})}),e.jsx("td",{className:"text-brand-text-2 px-4 py-3 text-xs",children:U(r.createdAt,"—")}),e.jsx("td",{className:"text-brand-text-2 px-4 py-3 text-xs",children:U(r.lastLoginAt,a("admin.users.never"))}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[y?e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>j({id:r.id,email:r.email,name:r.name??null}),"aria-label":a("admin.referrals.open_label",{email:r.email}),children:[e.jsx(Y,{className:"h-4 w-4"}),a("admin.referrals.open")]}):null,y?e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>b({id:r.id,email:r.email,name:r.name??null}),"aria-label":a("admin.plan.set_modal_open_label",{email:r.email}),children:[e.jsx(re,{className:"h-4 w-4"}),a("admin.plan.set_modal_open")]}):null,e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>N({id:r.id,email:r.email,name:r.name??null}),"aria-label":a("admin.credits.grant_modal_open_label",{email:r.email}),children:[e.jsx(te,{className:"h-4 w-4"}),a("admin.credits.grant_modal_open")]})]})})]},r.id))})]})}),g>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-brand-text-3 text-xs",children:a("pagination.range",{from:q,to:O,total:g})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>d(r=>Math.max(0,r-I)),disabled:z,className:v("border-brand-border text-brand-text-1 hover:bg-brand-surface-strong","rounded-full border px-3 py-1.5 text-xs font-medium transition-colors","disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent"),children:a("pagination.previous")}),e.jsx("button",{type:"button",onClick:()=>d(r=>
11r+I),disabled:B,className:v("border-brand-border text-brand-text-1 hover:bg-brand-surface-strong","rounded-full border px-3 py-1.5 text-xs font-medium transition-colors","disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent"),children:a("pagination.next")})]})]}):null,e.jsx(ne,{open:f!==null,onClose:()=>N(null),target:f}),e.jsx(ce,{open:u!==null,onClose:()=>b(null),target:u}),e.jsx(xe,{open:p!==null,onClose:()=>j(null),target:p})]})}function pe({plan:a}){const{t:l}=S(),t=F.safeParse(a),s=t.success?l(`admin.users.plan_${t.data}`):a,n=t.success&&t.data!=="free";return e.jsx("span",{className:v("inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide",n?"bg-brand-primary text-brand-on-primary":"bg-brand-surface text-brand-text-2"),children:s})}export{_e as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.