PageSourceSearch

https://klarva.ai/assets/js/AdminUsers-CIDrexhP.js

js klarva.ai collected 2026-10-05 15:23:07 UTC 29,910 bytes, 1 lines download raw bytes

1import{f as B,h as E,p as Q,bR as xe,bS as We,bT as De,bU as Ie,e as o,j as e,bV as se,S as y,v as Y,T as h,B as J,bv as ie,bW as le,n as A,bX as ce,aM as I,C as re,m as ae,G as P,b3 as Ae,P as Re,aG as $e,aH as he,aI as b,aJ as Pe,aQ as pe,aF as Le,aE as Te,r as m,aN as Ue,bY as ze,I as ne,F as Oe}from"./index-CjQJPRqD.js";import{A as Me,a as Be,h as Ee}from"./AdminOperationsCommon-DvxSBlwe.js";import{L as Ne}from"./List-CPpnwh4_.js";import{L as je}from"./ListItem-DMcvCKqF.js";import{L as oe}from"./ListItemText-BglZ9yQH.js";import{L as _e}from"./LinearProgress-BrRJlrXm.js";import{C as Fe}from"./CheckCircleRounded-Dynn8prG.js";import{H as He}from"./HourglassEmptyRounded-DvK3nNWQ.js";import{R as Qe}from"./RadioButtonUncheckedRounded-5CTffU6J.js";import{R as Ge}from"./RemoveCircleOutlineRounded-CMxZtqed.js";import{C as Ve,B as qe,S as Ke}from"./SearchRounded-DaUFPe9J.js";import{C as de}from"./Chip-BKvigHDQ.js";import{C as M}from"./Checkbox-ChKoHHjB.js";import{I as Xe}from"./InputAdornment-CsmJyou6.js";import{T as Ye}from"./TextField-BRLh5yx7.js";import{F as G,S as V}from"./Select-D2xqGQS3.js";import{I as q}from"./InputLabel-Ek6kTcvO.js";import{M as L}from"./MenuItem-EV21XWGG.js";import{u as Je}from"./useAdminOperationsQuery-CR1NVQ1o.js";import"./vendor-aws-iozXVvN_.js";import"./vendor-analytics-DC_KdMy5.js";import"./ListContext-DO4IdC2V.js";import"./listItemButtonClasses-RAoCi5Qn.js";import"./listItemTextClasses-BNf-9oc9.js";import"./SwitchBase-ywwgQR_H.js";import"./useFormControl-CR8YKYKY.js";import"./formControlState-Dq1zat_P.js";import"./Menu-B_54lrUe.js";import"./Popover-nGhCnikH.js";import"./listItemIconClasses-Czto3nIq.js";const T=B(E.jsx("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zm3.17-6.41a.996.996 0 0 1 0-1.41c.39-.39 1.02-.39 1.41 0L12 12.59l1.41-1.41c.39-.39 1.02-.39 1.41 0s.39 1.02 0 1.41L13.41 14l1.41 1.41c.39.39.39 1.02 0 1.41s-1.02.39-1.41 0L12 15.41l-1.41 1.41c-.39.39-1.02.39-1.41 0a.996.996 0 0 1 0-1.41L10.59 14zM18 4h-2.5l-.71-.71c-.18-.18-.44-.29-.7-.29H9.91c-.26 0-.52.11-.7.29L8.5 4H6c-.55 0-1 .45-1 1s.45 1 1 1h12c.55 0 1-.45 1-1s-.45-1-1-1"})),K=t=>t.data.data,ge=t=>{if(t!=null&&t.length)return[...new Set(t)].sort().join(",")},z={async listUsers({limit:t=25,cursor:n,search:s,sortBy:u,sortOrder:g,onboardingStatuses:p,recommenderStatuses:a}={}){const c=ge(p),f=ge(a),k=await Q.get(Ie(),{params:{limit:t,...n?{cursor:n}:{},...s?{search:s}:{},...u?{sort_by:u,sort_order:g??"desc"}:{},...c?{onboarding_statuses:c}:{},...f?{recommender_statuses:f}:{}}});return K(k)},async deleteMember(t){const n=await Q.delete(De(t));return K(n)},async startWorkspaceDeletion(t,n,s){const u=await Q.post(We(t),{confirmation:n},{headers:{"Idempotency-Key":s}});return K(u)},async getWorkspaceDeletionStatus(t){const n=await Q.get(xe(t));return K(n)}},Ze=5,Se=t=>{const n=new Map;for(const s of t){if(!s.brand_profile_id||!s.workspace_deletion_allowed)continue;const u=n.get(s.brand_profile_id)??[];u.push(s),n.set(s.brand_profile_id,u)}return Array.from(n,([s,u])=>({brandProfileId:s,users:u}))};async function et(t,n,s){if(t.length===0)return[];const u=new Array(t.length);let g=0;const p=async()=>{for(;;){const a=g++;if(a>=t.length)return;try{u[a]={status:"fulfilled",value:await s(t[a])}}catch(c){u[a]={status:"rejected",reason:c}}}};return await Promise.all(Array.from({length:Math.min(Math.max(n,1),t.length)},p)),u}const tt=t=>t.email||t.name||t.username;function nt({users:t,busy:n,progress:s,onClose:u,onConfirm:g}){const p=Se(t),a=()=>{n||u()},c=async()=>{await g()};return o(ce,{open:t.length>0,onClose:n?void 0:a,fullWidth:!0,maxWidth:"sm",children:[e(se,{children:"Delete selected workspaces?"}),e(ie,{children:o(y,{gap:2,children:[e(Y,{severity:"error",icon:e(T,{}),children:"This permanently deletes each selected workspace, all linked Cognito accounts, recommendations, internal billing data, schedules and discard vectors."}),o(h,{children:[t.length," user",t.length===1?"":"s"," selected across ",p.length," ","workspace",p.length===1?"":"s",". A workspace shared by multiple selected users is deleted only once."]}),e(Ne,{dense:!0,disablePadding:!0,sx:{maxHeight:240,overflowY:"auto"},children:p.map(f=>e(je,{disableGutters:!0,children:e(oe,{primary:f.users.map(tt).join(", "),secondary:`Workspace ${f.brandProfileId}`})},f.brandProfileId))}),e(Y,{severity:"warning",children:"Up to 5 workspaces are processed concurrently, and the next workspace starts as 
1soon as a slot becomes available. If one fails, the other results remain independent and the failed workspace will be listed with its error."}),n?o(J,{children:[e(_e,{variant:"determinate",value:s.total?s.completed/s.total*100:0,"aria-label":"Bulk workspace deletion progress"}),o(h,{variant:"caption",color:"text.secondary",children:["Completed ",s.completed," of ",s.total," workspaces"]})]}):null]})}),o(le,{children:[e(A,{onClick:a,disabled:n,children:"Cancel"}),e(A,{color:"error",variant:"contained",startIcon:e(T,{}),onClick:()=>void c(),disabled:n,children:n?"Deleting workspaces…":"Delete selected workspaces"})]})]})}const ue=B(E.jsx("path",{d:"M14 8c0-2.21-1.79-4-4-4S6 5.79 6 8s1.79 4 4 4 4-1.79 4-4M2 18v1c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-1c0-2.66-5.33-4-8-4s-8 1.34-8 4m16-8h4c.55 0 1 .45 1 1s-.45 1-1 1h-4c-.55 0-1-.45-1-1s.45-1 1-1"}));function rt({user:t,busy:n,onClose:s,onConfirm:u}){return o(ce,{open:!!t,onClose:n?void 0:s,fullWidth:!0,maxWidth:"sm",children:[e(se,{children:"Delete member account?"}),e(ie,{children:o(y,{gap:2,children:[o(h,{children:["This removes only the Cognito account for"," ",e("strong",{children:(t==null?void 0:t.email)||(t==null?void 0:t.username)}),". Workspace data, recommendations, billing records and other members remain."]}),e(Y,{severity:"warning",children:"This account will not be able to sign in again."})]})}),o(le,{children:[e(A,{onClick:s,disabled:n,children:"Cancel"}),e(A,{color:"warning",variant:"contained",startIcon:e(ue,{}),onClick:u,disabled:n,children:n?"Deleting…":"Delete member"})]})]})}const at=B(E.jsx("path",{d:"M12 6v1.79c0 .45.54.67.85.35l2.79-2.79c.2-.2.2-.51 0-.71l-2.79-2.79c-.31-.31-.85-.09-.85.36V4c-4.42 0-8 3.58-8 8 0 1.04.2 2.04.57 2.95.27.67 1.13.85 1.64.34.27-.27.38-.68.23-1.04C6.15 13.56 6 12.79 6 12c0-3.31 2.69-6 6-6m5.79 2.71c-.27.27-.38.69-.23 1.04.28.7.44 1.46.44 2.25 0 3.31-2.69 6-6 6v-1.79c0-.45-.54-.67-.85-.35l-2.79 2.79c-.2.2-.2.51 0 .71l2.79 2.79c.31.31.85.09.85-.35V20c4.42 0 8-3.58 8-8 0-1.04-.2-2.04-.57-2.95-.27-.67-1.13-.85-1.64-.34"})),ot=B(E.jsx("path",{d:"M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1m-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8m1-3h-2v-2h2z"})),st=B(E.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8m-1-4h2v2h-2zm1.61-9.96c-2.06-.3-3.88.97-4.43 2.79-.18.58.26 1.17.87 1.17h.2c.41 0 .74-.29.88-.67.32-.89 1.27-1.5 2.3-1.28.95.2 1.65 1.13 1.57 2.1-.1 1.34-1.62 1.63-2.45 2.88 0 .01-.01.01-.01.02-.01.02-.02.03-.03.05-.09.15-.18.32-.25.5-.01.03-.03.05-.04.08-.01.02-.01.04-.02.07-.12.34-.2.75-.2 1.25h2c0-.42.11-.77.28-1.07.02-.03.03-.06.05-.09.08-.14.18-.27.28-.39.01-.01.02-.03.03-.04.1-.12.21-.23.33-.34.96-.91 2.26-1.65 1.99-3.56-.24-1.74-1.61-3.21-3.35-3.47"})),it=t=>t.trim().toLowerCase().replace(/[\s-]+/g,"_"),Z=({status:t,label:n="Onboarding"})=>{const s=t?it(t):"";return["successful","success","succeeded"].includes(s)?e(I,{title:`Successful ${n.toLowerCase()}`,children:e(Fe,{"aria-label":`${n} status: Successful`,color:"success",fontSize:"small",titleAccess:`Successful ${n.toLowerCase()}`})}):["failed","failure","error"].includes(s)?e(I,{title:`Failed ${n.toLowerCase()}`,children:e(ot,{"aria-label":`${n} status: Failed`,color:"error",fontSize:"small",titleAccess:`Failed ${n.toLowerCase()}`})}):["skipped","skip"].includes(s)?e(I,{title:`Skipped ${n.toLowerCase()}`,children:e(Ge,{"aria-label":`${n} status: Skipped`,color:"disabled",fontSize:"small",titleAccess:`Skipped ${n.toLowerCase()}`})}):["running","in_progress","processing"].includes(s)?e(I,{title:`${n} is running`,children:e(at,{"aria-label":`${n} status: Running`,color:"info",fontSize:"small",titleAccess:`${n} is running`})}):["queued","pending"].includes(s)?e(I,{title:`${n} is pending`,children:e(He,{"aria-label":`${n} status: Pending`,color:"warning",fontSize:"small",titleAccess:`${n} is pending`})}):s==="not_started"||!t?e(I,{title:`No ${n.toLowerCase()} run`,children:e(Qe,{"aria-label":`${n} status: Not started`,color:"disabled",fontSize:"small",titleAccess:`No ${n.toLowerCase()} run`})}):e(I,{title:`${n} status: ${t}`,children:e(st,{"aria-label":`${n} status: Unknown`,color:"disabled",fontSize:"small",titleAccess:`${n} status: ${t}`})})},ye=({status:t})=>t==="active"?e(I,{title:"Active",children:e(Ve,{"aria-label":"Active",color:"success",fontSize:"small",titleAccess:"Active"})}):t==="disabled"?e(I,{title:"Deactivated",children:e(qe,{"aria-label":"Deactivated",color:"disabled",fontSize:"small",titleAccess:"Deactivated"})}):e(de,{size:"small",label:t,variant:"outlined"}),fe=t=>{if(!t)return"—";const n=new Date(t);
1return Number.isNaN(n.getTime())?"—":n.toLocaleString()};function lt({users:t,onDeleteMember:n,onDeleteWorkspace:s,selectedUserIds:u,onToggleUser:g,selectionDisabled:p=!1}){return e(y,{gap:1.5,sx:{display:{xs:"flex",md:"none"}},children:t.map(a=>{const c=a.workspace_stats;return e(re,{variant:"outlined",children:e(ae,{children:o(y,{gap:1.5,children:[o(y,{direction:"row",justifyContent:"space-between",gap:1,children:[o(y,{direction:"row",gap:.5,minWidth:0,alignItems:"flex-start",children:[e(M,{size:"small",checked:u.has(a.user_id),onChange:()=>g(a.user_id),disabled:p||!a.workspace_deletion_allowed,inputProps:{"aria-label":`Select workspace user ${a.email||a.username}`}}),o(J,{minWidth:0,children:[e(h,{variant:"caption",color:"text.secondary",children:"User name"}),e(h,{fontWeight:700,noWrap:!0,children:a.name||a.username||"—"})]})]}),o(y,{alignItems:"flex-end",gap:.25,children:[e(h,{variant:"caption",color:"text.secondary",children:"Status"}),e(ye,{status:a.status})]})]}),o(P,{container:!0,spacing:1,children:[o(P,{size:{xs:12},children:[e(h,{variant:"caption",color:"text.secondary",children:"Email"}),e(h,{variant:"body2",noWrap:!0,children:a.email||"—"})]}),o(P,{size:{xs:7},children:[e(h,{variant:"caption",color:"text.secondary",children:"Brand"}),e(h,{variant:"body2",noWrap:!0,title:a.brand_name||void 0,children:a.brand_name||"—"})]}),o(P,{size:{xs:5},children:[e(h,{variant:"caption",color:"text.secondary",children:"Role"}),e(h,{variant:"body2",noWrap:!0,children:a.role||"—"})]}),o(P,{size:{xs:12},children:[e(h,{variant:"caption",color:"text.secondary",children:"Group"}),a.access_group==="platform_admin"?e(de,{size:"small",label:"platform_admin",color:"warning",variant:"outlined"}):e(h,{variant:"body2",color:"text.secondary",children:"—"})]})]}),e(P,{container:!0,spacing:1,children:[["Total",c==null?void 0:c.total_recommendations],["Used",c==null?void 0:c.used_recommendations],["Unused",c==null?void 0:c.unused_recommendations],["Discarded",c==null?void 0:c.discarded_recommendations]].map(([f,k])=>o(P,{size:{xs:6},children:[o(h,{variant:"caption",color:"text.secondary",children:["Workspace ",f]}),e(h,{fontWeight:700,children:k??"—"})]},f))}),e(Ae,{}),o(y,{direction:"row",gap:.75,alignItems:"center",flexWrap:"wrap",children:[o(h,{variant:"body2",children:["Latest onboarding: ",fe(c==null?void 0:c.onboarding_last_run_at)]}),e(Z,{status:c==null?void 0:c.onboarding_status})]}),o(y,{direction:"row",gap:.75,alignItems:"center",flexWrap:"wrap",children:[o(h,{variant:"body2",children:["Latest recommender: ",fe(c==null?void 0:c.recommender_last_run_at)]}),e(Z,{status:c==null?void 0:c.recommender_status,label:"Recommender"})]}),o(y,{direction:{xs:"column",sm:"row"},gap:1,children:[e(A,{fullWidth:!0,variant:"outlined",color:"warning",startIcon:e(ue,{}),disabled:a.access_group==="platform_admin",onClick:()=>n(a),children:"Delete member"}),e(A,{fullWidth:!0,variant:"contained",color:"error",startIcon:e(T,{}),disabled:!a.workspace_deletion_allowed,onClick:()=>s(a),children:"Delete workspace"})]}),a.brand_profile_id?a.workspace_deletion_allowed?null:e(h,{variant:"caption",color:"text.secondary",children:"Workspace deletion is unavailable because it contains a platform-admin user."}):e(h,{variant:"caption",color:"text.secondary",children:"No workspace linked; workspace deletion is unavailable."})]})})},a.user_id)})})}const X=t=>t??"—",be=t=>{if(!t)return"—";const n=new Date(t);return Number.isNaN(n.getTime())?"—":n.toLocaleString()};function ct({users:t,onDeleteMember:n,onDeleteWorkspace:s,selectedUserIds:u,onToggleAll:g,onToggleUser:p,selectionDisabled:a=!1}){const c=t.filter(l=>!!(l.brand_profile_id&&l.workspace_deletion_allowed)),f=c.filter(l=>u.has(l.user_id)).length,k=c.length>0&&f===c.length;return e(Te,{component:Re,sx:{display:{xs:"none",md:"block"},overflowX:"auto"},children:o(Le,{size:"small","aria-label":"Admin users",children:[e($e,{children:o(he,{children:[e(b,{padding:"checkbox",children:e(M,{checked:k,indeterminate:f>0&&!k,onChange:l=>g(l.target.checked),disabled:a||c.length===0,inputProps:{"aria-label":"Select all workspace users on this page"}})}),e(b,{sx:{minWidth:180},children:"User name"}),e(b,{sx:{minWidth:220},children:"Email"}),e(b,{sx:{minWidth:180},children:"Brand"}),e(b,{sx:{minWidth:120},children:"Role"}),e(b,{sx:{minWidth:132},children:"Status"}),e(b,{sx:{minWidth:150},children:"Group"}
1),e(b,{align:"right",sx:{minWidth:110},children:"Workspace total"}),e(b,{align:"right",sx:{minWidth:70},children:"Used"}),e(b,{align:"right",sx:{minWidth:76},children:"Unused"}),e(b,{align:"right",sx:{minWidth:90},children:"Discarded"}),e(b,{sx:{minWidth:180},children:"Latest onboarding"}),e(b,{sx:{minWidth:180},children:"Latest recommender"}),e(b,{align:"right",sx:{minWidth:156},children:"Actions"})]})}),e(Pe,{children:t.map(l=>{const r=l.workspace_stats,d=!!(l.brand_profile_id&&l.workspace_deletion_allowed),w=l.access_group==="platform_admin",S=l.brand_profile_id?l.workspace_deletion_allowed?"Delete entire workspace":"Workspace contains a platform-admin user and cannot be deleted":"No workspace linked";return o(he,{hover:!0,children:[e(b,{padding:"checkbox",children:e(M,{checked:u.has(l.user_id),onChange:()=>p(l.user_id),disabled:a||!d,inputProps:{"aria-label":`Select workspace user ${l.email||l.username}`}})}),e(b,{children:e(h,{variant:"body2",fontWeight:700,noWrap:!0,children:l.name||l.username||"—"})}),e(b,{children:e(h,{variant:"body2",color:"text.secondary",noWrap:!0,children:l.email||"—"})}),e(b,{children:e(h,{variant:"body2",color:l.brand_name?"text.primary":"text.secondary",noWrap:!0,title:l.brand_name||void 0,children:l.brand_name||"—"})}),e(b,{children:e(h,{variant:"body2",children:l.role||"—"})}),e(b,{children:e(ye,{status:l.status})}),e(b,{children:w?e(de,{size:"small",label:"platform_admin",color:"warning",variant:"outlined"}):e(h,{variant:"body2",color:"text.secondary",children:"—"})}),e(b,{align:"right",children:X(r==null?void 0:r.total_recommendations)}),e(b,{align:"right",children:X(r==null?void 0:r.used_recommendations)}),e(b,{align:"right",children:X(r==null?void 0:r.unused_recommendations)}),e(b,{align:"right",children:X(r==null?void 0:r.discarded_recommendations)}),e(b,{children:o(y,{direction:"row",gap:.75,alignItems:"center",children:[e(h,{variant:"body2",noWrap:!0,children:be(r==null?void 0:r.onboarding_last_run_at)}),e(Z,{status:r==null?void 0:r.onboarding_status})]})}),e(b,{children:o(y,{direction:"row",gap:.75,alignItems:"center",children:[e(h,{variant:"body2",noWrap:!0,children:be(r==null?void 0:r.recommender_last_run_at)}),e(Z,{status:r==null?void 0:r.recommender_status,label:"Recommender"})]})}),e(b,{align:"right",children:o(y,{direction:"row",gap:.5,justifyContent:"flex-end",children:[e(I,{title:w?"platform_admin users cannot be deleted":"Delete member account",children:e("span",{children:e(pe,{"aria-label":`Delete member account for ${l.email||l.username}`,color:"warning",disabled:w,onClick:()=>n(l),children:e(ue,{})})})}),e(I,{title:S,children:e("span",{children:e(pe,{"aria-label":`Delete entire workspace for ${l.email||l.username}`,color:"error",disabled:!d,onClick:()=>s(l),children:e(T,{})})})})]})})]},l.user_id)})})]})})}const me=[{value:"successful",label:"Successful"},{value:"failed",label:"Failed"},{value:"running",label:"Running"},{value:"queued",label:"Queued"},{value:"pending",label:"Pending"},{value:"skipped",label:"Skipped"},{value:"not_started",label:"Not started"},{value:"unknown",label:"Unknown"}],dt=me.filter(t=>t.value!=="queued"),ut=me,we=t=>{var n;return((n=me.find(s=>s.value===t))==null?void 0:n.label)??t};function mt({searchQuery:t,onSearchChange:n,onboardingStatuses:s,onOnboardingStatusesChange:u,recommenderStatuses:g,onRecommenderStatusesChange:p,sortBy:a,onSortByChange:c,sortOrder:f,onSortOrderChange:k}){const l=r=>{const d=r.target.value;return Array.isArray(d)?d:d.split(",")};return o(y,{direction:{xs:"column",lg:"row"},gap:1,alignItems:{xs:"stretch",lg:"center"},sx:{width:"100%"},children:[e(Ye,{fullWidth:!0,size:"small",label:"Search brand name or email",value:t,onChange:r=>n(r.target.value),placeholder:"Search brand name, email, or username",sx:{minWidth:{lg:260},flex:1},slotProps:{input:{startAdornment:e(Xe,{position:"start",children:e(Ke,{fontSize:"small"})})}}}),o(G,{size:"small",sx:{minWidth:{xs:"100%",lg:176}},children:[e(q,{id:"admin-onboarding-status-filter-label",children:"Onboarding status"}),e(V,{labelId:"admin-onboarding-status-filter-label",multiple:!0,value:s,label:"Onboarding status",onChange:r=>u(l(r)),renderValue:r=>{const d=r;return d.length===0?"All statuses":d.length===1?we(d[0]):`${d.length} selected`},inputProps:{"aria-label":"Filter by onboarding status"},children:dt.map(r=>o(L,{value:r.value,children:[e(M,{checked:s.includes(r.value),size:"small"}),e(oe,{primary:r.label})]},r.value))})]}),o(G,{size:"small",sx:{minWidth:{xs:"100%",lg:176}},children:[e(q,{id:"admin-recommender-status-filter-label",children:"Recommender status"}),e(V,{labelId:"admin-recommender-status-filter-label",multiple:!0,value:g,label:"Recommender status",onChange:r=>p(l(r)),renderValue:r=>{const d=r;return d.length===0?"All statuses":d.length===1?we(d[0]):`${d.length} selected`},inputProps:{"aria-label":"Filter by recommender status"},children:ut.map(r=>o(L,{value:r.value,children:[e(M,{checked:g.includes(r.value),size:"small"}),e(oe,{primary:r.label})]},r.value))})]}),o(G,{size:"small",sx:{minWidth:{xs:"100%",lg:176}},children:[e(q,{id:"admin-user-sort-label",children:"Sort by"}),o(V,{labelId:"admin-user-sort-label",value:a,label:"Sort by",onChange:r=>c(r.target.value),inputProps:{"aria-label":"Sort users by"},children:[e(L,{value:"",children:"Current order"}),e(L,{value:"onboarding_time",children:"Latest onboarding"}),e(L,{value:"recommender_time",children:"Latest recommender"})]})]}),a?o(G,{size:"small",sx:{minWidth:{xs:"100%",lg:140}},children:[e(q,{id:"admin-user-sort-order-label",children:"Order"}),o(V,{labelId:"admin-user-sort-order-label",value:f,label:"Order",onChange:r=>k(r.target.value),inputProps:{"aria-label":"Sort order"},children:[e(L,{value:"desc",children:"Newest first"}),e(L,{value:"asc",children:"Oldest first"})]})]}):null]})}function ht({user:t,busy:n,onClose:s,onConfirm:u}){var a,c,f,k;const g=()=>{n||s()},p=async()=>{try{await u()}catch{}};return o(ce,{open:!!t,onClose:n?void 0:g,fullWidth:!0,maxWidth:"sm",children:[e(se,{children:"Delete entire workspace?"}),e(ie,{children:o(y,{gap:2,children:[e(Y,{severity:"error",icon:e(T,{}),children:"This permanently deletes the workspace, all linked Cognito accounts, recommendations, internal billing data, schedules and discard vectors. Logs, audit history and backups remain under retention policy."}),o(h,{children:["Target: ",e("strong",{children:(t==null?void 0:t.email)||(t==null?void 0:t.username)})]}),o(h,{variant:"body2",color:"text.secondary",children:["Workspace stats: ",((a=t==null?void 0:t.workspace_stats)==null?void 0:a.total_recommendations)??"—"," total,"," ",((c=t==null?void 0:t.workspace_stats)==null?void 0:c.used_recommendations)??"—"," used,"," ",((f=t==null?void 0:t.workspace_stats)==null?void 0:f.unused_re
1commendations)??"—"," unused,"," ",((k=t==null?void 0:t.workspace_stats)==null?void 0:k.discarded_recommendations)??"—"," discarded."]}),n?e(_e,{"aria-label":"Workspace deletion progress"}):null]})}),o(le,{children:[e(A,{onClick:g,disabled:n,children:"Cancel"}),e(A,{color:"error",variant:"contained",startIcon:e(T,{}),onClick:()=>void p(),disabled:n,children:n?"Deleting workspace…":"Delete entire workspace"})]})]})}const ke=25;function pt(){var F;const[t,n]=m.useState(),[s,u]=m.useState([]),[g,p]=m.useState(""),[a,c]=m.useState(""),[f,k]=m.useState([]),[l,r]=m.useState([]),[d,w]=m.useState(""),[S,x]=m.useState("desc"),v=m.useCallback(()=>{n(void 0),u([])},[]);m.useEffect(()=>{const _=window.setTimeout(()=>{c(g.trim()),v()},300);return()=>window.clearTimeout(_)},[v,g]);const N=m.useCallback(_=>{k([...new Set(_)].sort()),v()},[v]),U=m.useCallback(_=>{r([...new Set(_)].sort()),v()},[v]),W=m.useCallback(_=>{!d&&_&&x("desc"),w(_),v()},[v,d]),j=m.useCallback(_=>{x(_),v()},[v]),ee=m.useCallback(()=>z.listUsers({limit:ke,cursor:t,search:a||void 0,sortBy:d||void 0,sortOrder:d?S:void 0,onboardingStatuses:f,recommenderStatuses:l}),[t,f,l,a,d,S]),$=Je(ee),te=m.useCallback(async()=>{if(t!==void 0){n(void 0),u([]);return}await $.refresh()},[t,$]);return{...$,page:$.data,cursor:t,pageSize:ke,search:a,searchQuery:g,setSearchQuery:p,onboardingStatuses:f,setOnboardingStatuses:N,recommenderStatuses:l,setRecommenderStatuses:U,sortBy:d,setSortBy:W,sortOrder:S,setSortOrder:j,goNext:()=>{var O;const _=(O=$.data)==null?void 0:O.next_cursor;_&&(u(H=>[...H,t]),n(_))},goPrevious:()=>{n(s[s.length-1]),u(_=>_.slice(0,-1))},hasPrevious:s.length>0,hasNext:!!((F=$.data)!=null&&F.next_cursor),pageNumber:s.length+1,refresh:te}}const gt=3e3,ft=()=>typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`admin-bulk-delete-${Date.now()}-${Math.random().toString(16).slice(2)}`,ve=t=>t instanceof Error?t.message:"Could not delete this workspace",bt=async t=>{for(;;){const n=await z.getWorkspaceDeletionStatus(t);if(n.status==="succeeded"||n.status==="failed")return n;await new Promise(s=>window.setTimeout(s,gt))}};function wt(){const[t,n]=m.useState(!1),[s,u]=m.useState({completed:0,total:0}),[g,p]=m.useState([]),a=m.useRef(!0);m.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);const c=m.useCallback(async l=>{var d;const r=((d=l.users[0])==null?void 0:d.email)||l.brandProfileId;try{const w=await z.startWorkspaceDeletion(l.users[0].user_id,r,ft()),S=await bt(w.deletion_id);return{target:l,status:S.status,deletionId:w.deletion_id,...S.error?{error:S.error}:{}}}catch(w){return{target:l,status:"failed",error:ve(w)}}},[]),f=m.useCallback(async l=>{const r=Se(l);if(!r.length)return[];n(!0),p([]),u({completed:0,total:r.length});const w=(await et(r,Ze,async S=>{const x=await c(S);return a.current&&u(v=>({...v,completed:v.completed+1})),x})).map((S,x)=>S.status==="fulfilled"?S.value:{target:r[x],status:"failed",error:ve(S.reason)});return a.current&&(p(w),n(!1)),w},[c]),k=m.useCallback(()=>{p([]),u({completed:0,total:0})},[]);return{progress:s,reset:k,results:g,running:t,start:f}}const kt=3e3,vt=()=>typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`admin-delete-${Date.now()}-${Math.random().toString(16).slice(2)}`;function _t(){const[t,n]=m.useState(null),[s,u]=m.useState(null),[g,p]=m.useState(!1),a=m.useRef(!0);m.useEffect(()=>()=>{a.current=!1},[]);const c=m.useCallback(async l=>{try{const r=await z.getWorkspaceDeletionStatus(l);if(!a.current)return;if(n(r),r.status==="succeeded"||r.status==="failed"){p(!1),r.status==="failed"&&u(r.error??"Workspace deletion failed");return}window.setTimeout(()=>void c(l),kt)}catch(r){if(!a.current)return;p(!1),u(r instanceof Error?r.message:"Could not read deletion status")}},[]),f=m.useCallback(async(l,r)=>{p(!0),u(null);try{const d=await z.startWorkspaceDeletion(l,r,vt());return a.current&&(n(d),c(d.deletion_id)),d}catch(d){throw a.current&&(p(!1),u(d instanceof Error?d.message:"Could not start deletion")),d}},[c]),k=m.useCallback(()=>{n(null),u(null),p(!1)},[]);return{error:s,reset:k,running:g,start:f,status:t}}const St=t=>t.email||t.name||t.username;function Zt(){var O,H;const t=pt(),{notify:n}=Ue(),[s,u]=m.useState(null),[g,p]=m.useState(null),[a,c]=m.useState(!1),[f,k]=m.useState(()=>new Set),[l,r]=m.useState(!1),d=_t(),w=wt(),S=m.useRef(null),x=((O=t.page)==null?void 0:O.items)??[],v=x.filter(i=>
1f.has(i.user_id)&&i.workspace_deletion_allowed),N=new Set(v.flatMap(i=>i.brand_profile_id?[i.brand_profile_id]:[])).size,U=d.running||w.running,W=m.useCallback(()=>{k(new Set)},[]),j=m.useCallback(i=>{k(D=>{const C=new Set(D),R=x.find(Ce=>Ce.user_id===i);return R!=null&&R.workspace_deletion_allowed&&(C.has(i)?C.delete(i):C.add(i)),C})},[x]),ee=m.useCallback(i=>{k(D=>{const C=new Set(D);for(const R of x)R.workspace_deletion_allowed&&(i?C.add(R.user_id):C.delete(R.user_id));return C})},[x]);m.useEffect(()=>{var D;const i=(D=d.status)==null?void 0:D.status;!i||i!=="succeeded"&&i!=="failed"||S.current===i||(S.current=i,i==="succeeded"?(n({message:"Workspace deleted",severity:"success"}),p(null),t.refresh()):n({message:d.error??"Workspace deletion failed",severity:"error"}))},[t,d.error,(H=d.status)==null?void 0:H.status,n]);const $=async()=>{if(!(!s||a||s.access_group==="platform_admin")){c(!0);try{await z.deleteMember(s.user_id),n({message:"Member account deleted",severity:"success"}),u(null),await t.refresh()}catch(i){n({message:i instanceof Error?i.message:"Could not delete member",severity:"error"})}finally{c(!1)}}},te=async()=>{var D;if(!g||!g.workspace_deletion_allowed)return;const i=((D=g.email)==null?void 0:D.trim())||g.brand_profile_id;if(!i){n({message:"Could not identify the workspace to delete",severity:"error"});return}try{S.current=null,await d.start(g.user_id,i),n({message:"Workspace deletion queued",severity:"info"})}catch(C){throw n({message:C instanceof Error?C.message:"Could not start workspace deletion",severity:"error"}),C}},F=async()=>{if(!v.length)return;const i=await w.start(v),D=i.filter(R=>R.status==="failed"),C=i.length-D.length;W(),r(!1),await t.refresh(),D.length?n({message:`${String(C)} workspace${C===1?"":"s"} deleted; ${String(D.length)} failed. See details below.`,severity:"error"}):n({message:`${String(C)} workspace${C===1?"":"s"} deleted`,severity:"success"})},_=w.results.filter(i=>i.status==="failed");return t.loading&&!t.page?e(ze,{}):o(J,{sx:{maxWidth:1440,mx:"auto",pb:4,width:"100%"},children:[o(y,{gap:{xs:2,sm:3},children:[e(Me,{title:"User management",description:"Review Cognito users and workspace-level recommendation usage. Workspace deletion is irreversible.",onRefresh:()=>{W(),t.refresh()},refreshing:t.loading||d.running||w.running}),e(mt,{searchQuery:t.searchQuery,onSearchChange:i=>{W(),t.setSearchQuery(i)},onboardingStatuses:t.onboardingStatuses,onOnboardingStatusesChange:i=>{W(),t.setOnboardingStatuses(i)},recommenderStatuses:t.recommenderStatuses,onRecommenderStatusesChange:i=>{W(),t.setRecommenderStatuses(i)},sortBy:t.sortBy,onSortByChange:i=>{W(),t.setSortBy(i)},sortOrder:t.sortOrder,onSortOrderChange:i=>{W(),t.setSortOrder(i)}}),e(ne,{severity:"info",children:"Recommendation counts are workspace-scoped and repeat for members of the same workspace."}),v.length?e(re,{variant:"outlined",children:e(ae,{children:o(y,{direction:{xs:"column",sm:"row"},gap:1.5,alignItems:{xs:"stretch",sm:"center"},justifyContent:"space-between",children:[o(h,{children:[v.length," user",v.length===1?"":"s"," selected across"," ",N," workspace",N===1?"":"s","."]}),o(y,{direction:{xs:"column",sm:"row"},gap:1,children:[e(A,{color:"error",variant:"contained",startIcon:e(T,{}),onClick:()=>{w.reset(),r(!0)},disabled:U,children:"Delete selected workspaces"}),e(A,{onClick:W,disabled:U,children:"Clear selection"})]})]})})}):null,w.results.length?e(ne,{severity:_.length?"error":"success",children:o(y,{gap:.5,children:[o(h,{fontWeight:700,children:["Bulk workspace deletion completed:"," ",w.results.length-_.length," succeeded,"," ",_.length," failed."]}),_.length?e(J,{component:"ul",sx:{m:0,pl:2.5},children:_.map(i=>o("li",{children:[i.target.users.map(St).join(", ")," —"," ",i.error||"Workspace deletion failed"]},i.target.brandProfileId))}):null]})}):null,d.status&&d.running?o(ne,{severity:"warning",children:["Workspace deletion status: ",d.status.status.replace(/_/g," "),". Keep this page open for live progress."]}):null,t.error?e(Be,{message:t.error}):null,t.page&&!x.length?e(re,{children:e(ae,{children:e(h,{color:"text.secondary",children:"No Cognito users found."})})}):null,x.length?o(Oe,{children:[e(ct,{users:x,onDeleteMember:i=>{i.access_group!=="platform_admin"&&(W(),u(i))},onDeleteWorkspace:i=>{i.workspace_deletion_allowed&&(W(),p(i))},selectedUserIds:f,onToggleAll:ee,onToggleUser:j,selectionDisabled:U}),e(lt,{users:x,onDeleteMember:i=>{i.access_group!=="platform_admin"&&(W(),u(i))},onDeleteWorkspace:i=>{i.workspace_deletion_allowed&&(W(),p(i))},selectedUserIds:f,onToggleUser:j,selectionDisabled:U}),e(Ee,{page:t.pageNumber,hasPrevious:t.hasPrevious,hasNext:t.hasNext,loading:t.loading,onPrevious:()=>{W(),t.goPrevious()},onNext:()=>{W(),t.goNext()}})]}):null,t.page?o(h,{variant:"caption",color:"text.secondary",children:["Showing ",x.length," of ",t.page.total," users."]}):null]}),e(rt,{user:s,busy:a,onClose:()=>u(null),onConfirm:()=>void $()}),e(nt,{users:l?v:[],busy:w.running,progress:w.progress,onClose:()=>{r(!1),W()},onConfirm:F}),e(ht,{user:g,busy:d.running,onClose:()=>{d.reset(),p(null)},onConfirm:te})]})}
1export{Zt 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.