1import{p as D,j as e,u as c,t as x,ar as g,as as j,T as l,r as u,ak as U,A as R,c as E,cw as f,B as I,f6 as T,I as L,G as w,J as B,K as A,i as F,l as M,bo as P,L as k,dE as N}from"./index-7xGZQarM.js";import{D as $}from"./DefaultPageLayout-bbCS046_.js";import{u as z}from"./useCurrentTenantRole-B7MqlWdv.js";import{D as G}from"./DeleteConfirmationDialog-D-pSYy0G.js";import{U as q,a as K}from"./UserRoleSelect-DtDxVv2v.js";import{u as p}from"./useUserMutation-DwVlgic1.js";import{C as S}from"./CardActions-CZ549AJS.js";import{t as O}from"./zod-CERegKzJ.js";import{L as W}from"./LoadingButton-yCAXRQtY.js";import{u as H}from"./index.esm-DOD_RurM.js";import{G as o}from"./Grid2-CqkvP9PW.js";import{U as Q}from"./user-management-DxT4LDyP.js";import"./ArrowBack-Dfl3xaIh.js";import"./Fab-CQzwzmnA.js";import"./FormControlLabel-DqMfjOHn.js";import"./Checkbox-DkzlDVTd.js";import"./SwitchBase-CKLZN_1j.js";import"./Circle-CZnTILfN.js";import"./optimistic-updater-CujVR4j9.js";import"./createGrid-ZBMOdsSe.js";const Y=D(e.jsx("path",{d:"M3 17.46v3.04c0 .28.22.5.5.5h3.04c.13 0 .26-.05.35-.15L17.81 9.94l-3.75-3.75L3.15 17.1q-.15.15-.15.36M20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75z"}),"EditRounded"),J=({user:s})=>{const{t}=c("user-management"),{impersonatedTenantId:r}=x(),{changeUserRole:n}=p(r),a=s.role==="admin"?"admins":"users";return e.jsxs(g,{variant:"outlined",sx:{height:"100%",overflow:"visible"},children:[e.jsxs(j,{children:[e.jsx(l,{gutterBottom:!0,variant:"h6",children:t("user_details.manage_role.title")}),e.jsx(l,{gutterBottom:!0,variant:"caption",children:t("user_details.manage_role.description")})]}),e.jsx(S,{sx:{px:2,gap:1,marginTop:"auto"},children:e.jsx(q,{size:"small",hiddenLabel:!0,defaultRole:a,onRoleChange:d=>n({user_id:s.user_id,role:d==="admins"?"admin":"user"})})})]})},V=({user:s})=>{const{t}=c("user-management"),{impersonatedTenantId:r}=x(),{enableUser:n,disableUser:i}=p(r);return e.jsxs(g,{variant:"outlined",sx:{height:"100%",overflow:"visible"},children:[e.jsxs(j,{children:[e.jsx(l,{gutterBottom:!0,variant:"h6",children:t("user_details.manage_status.title")}),e.jsx(l,{gutterBottom:!0,variant:"caption",children:t("user_details.manage_status.description")})]}),e.jsx(S,{sx:{px:2,gap:1,marginTop:"auto"},children:e.jsx(K,{hiddenLabel:!0,size:"small",defaultEnabled:s.enabled,onEnableUser:()=>n({user_id:s.user_id}),onDisableUser:()=>i({user_id:s.user_id})})})]})},X=f.object({first_name:f.string().optional(),last_name:f.string().optional()}),Z=({onCancel:s,user:t})=>{const{t:r}=c("user-management"),{impersonatedTenantId:n}=x(),i=u.useId(),a=u.useId(),{updateUserName:d}=p(n),{handleSubmit:_,register:m,setError:h,formState:b}=H({resolver:O(X),defaultValues:{first_name:t.first_name||"",last_name:t.last_name||""}}),C=_(async y=>{try{await d({user_id:t.user_id,first_name:y.first_name,last_name:y.last_name}),s()}catch{h("root",{message:r("api.failed_to_update_user_details")})}}),v=b.errors.root;return e.jsxs(o,{container:!0,component:"form",onSubmit:C,sx:{alignItems:"center",rowGap:2},children:[e.jsx(o,{size:{xs:12,sm:6},children:e.jsxs(l,{htmlFor:i,component:"label",children:[r("user_details.personal_data.first_name"),":"]})}),e.jsx(o,{size:{xs:12,sm:6},sx:{p:1},children:e.jsx(U,{id:i,size:"small",fullWidth:!0,slotProps:{htmlInput:m("first_name")}})}),e.jsx(o,{size:{xs:12,sm:6},children:e.jsxs(l,{htmlFor:a,component:"label",children:[r("user_details.personal_data.last_name"),":"]})}),e.jsx(o,{size:{xs:12,sm:6},sx:{p:1},children:e.jsx(U,{id:a,size:"small",fullWidth:!0,slotProps:{htmlInput:m("last_name")}})}),v&&e.jsx(o,{size:{xs:12},children:e.jsx(R,{severity:"error",sx:{mb:2},children:v.message})}),e.jsxs(o,{size:{xs:12},sx:{display:"flex",gap:1},children:[e.jsx(E,{color:"inherit",onClick:()=>s(),sx:{marginLeft:"auto"},children:r("user_details.personal_data.cancel")}),e.jsx(W,{type:"submit",label:r("user_details.personal_data.save"),variant:"contained",color:"primary",loading:b.isSubmitting})]})]})},ee=({user:s})=>{const{t}=c("user-management"),{isAdmin:r}=z(),[n,i]=u.useState(!1),a=s.first_name&&s.last_name?`${s.first_name} ${s.last_name}`:void 0;return e.jsx(g,{variant:"outlined",sx:{mb:2},children:e.jsxs(j,{children:[e.jsxs(I,{sx:{display:"flex",alignItems:"center",gap:2,marginBottom:1},children:[e.jsx(T,{size:"2.75rem",email:s.username,name:a}),e.jsxs(I,{sx:{flexGrow:1},children:[e.jsx(l,{variant:"h6",children:a||s.username}),e.jsx(l,{variant:"body2",color:"text.secondary",children:s.email})]}),r&&!n&&e.jsx(L,{"aria-label":t("user_details.personal_data.edit"),onClick:()=>i(!0),edge:"end",sx:{flex:"none"},children:e.jsx(Y,{fontSize:"inherit"})})]}),n&&e.jsx(Z,{user:s,onCancel:()=>i(!1)})]})})},se=A.ledger_url,te=(s,t)=>{const{fetchPrivate:r}=w();return B({queryKey:Q.detail(t||"",s),queryFn:async()=>
1{if(!s)throw new Error("Tenant ID is required");if(!t)throw new Error("User ID is required");return await r({endpoint:`api/tenants/${s}/users/${t}/`,base_url:se})},enabled:!!s&&!!t})},Ue=()=>{const{userId:s}=F(),{t}=c("user-management"),r=M(),{impersonatedTenantId:n}=x(),{deleteUser:i}=p(n),{data:a}=te(n,s),{isAdmin:d}=z(),[_,m]=u.useState(!1);if(!a)return e.jsx(P,{children:e.jsx(k,{})});const h=a.first_name&&a.last_name?`${a.first_name} ${a.last_name}`:a.username;return e.jsxs($,{backHref:"/my_team",backAriaLabel:t("back_to_all_users"),title:e.jsxs(e.Fragment,{children:[t("user_details.title"),e.jsx("span",{style:N,children:h})]}),children:[e.jsx(ee,{user:a}),d&&e.jsxs(o,{container:!0,spacing:2,sx:{mb:2},children:[e.jsx(o,{size:{xs:12,sm:6},children:e.jsx(V,{user:a})}),e.jsx(o,{size:{xs:12,sm:6},children:e.jsx(J,{user:a})})]}),d&&e.jsx(E,{color:"error",variant:"outlined",onClick:()=>m(!0),sx:{width:"max-content"},children:t("user_details.delete_user")}),e.jsx(G,{title:t("user_details.delete_dialog.title"),description:t("user_details.delete_dialog.description"),isOpen:_,handleClose:()=>m(!1),onDelete:()=>i({user_id:a.user_id}).then(()=>r("/my_team"))})]})};export{Ue 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.