theme.keycloak.v2.admin.resources.assets.UserForm-_c-oiMDM.js Maven / Gradle / Ivy
import{jsx as t,jsxs as u,Fragment as y}from"react/jsx-runtime";import{u as I,b3 as E,c as ie,v as S,h as v,L as T,eg as ne,dW as se,bP as oe,bh as U,em as le,a as R,y as ce,b6 as de,f as ue,dt as me,F as pe,ac as f,am as x,ad as k,en as be,x as A,dP as fe,ai as he,a4 as Ae,ae as ge,bb as ye,bc as V,ag as ke,ah as ve,aq as Ie,A as Le,p as we,dv as Ge,j as D}from"./index-C1LIsRX7.js";import{useState as h,useEffect as qe}from"react";import{D as Oe}from"./SwitchControl-C3zDl-9W.js";import{F as Ce}from"./FormAccess-BcY70QlP.js";import{G as Fe}from"./GroupPickerDialog-DmX3SBxL.js";import{u as je}from"./useFormatDate-Ypu7MAgr.js";const Ue=({user:r})=>{const{adminClient:n}=I(),e=E(),{realm:o}=ie(),[s,l]=h();return S(()=>e.hasAccess("view-realm")?n.components.findOne({id:r.federationLink||r.origin}):n.userStorageProvider.name({id:r.federationLink||r.origin}),l,[]),s?e.hasAccess("view-realm")?t(v,{variant:"link",component:m=>t(T,{...m,to:ne({id:s.id,providerId:s.providerId,realm:o})}),children:s.name}):t("span",{children:s.name}):null};function xe(r){const n={};Object.entries(r.attributes||{}).forEach(([o,s])=>n[se(o)]=s);const e=oe(r.unmanagedAttributes);return{...r,attributes:n,unmanagedAttributes:e}}function Pe(r){const n=r.username?.trim(),e=Array.isArray(r.attributes)?U(r.attributes):Object.fromEntries(Object.entries(r.attributes||{}).map(([s,l])=>[le(s),l])),o=Array.isArray(r.unmanagedAttributes)?U(r.unmanagedAttributes):r.unmanagedAttributes;for(const s in o)if(e&&Object.hasOwn(e,s))throw Error(`Attribute ${s} is a managed attribute and is already available from the user details.`);return{...r,username:n,attributes:{...o,...e},unmanagedAttributes:void 0}}function Ne(r={},n={}){return Object.fromEntries(Object.entries(r).filter(([e])=>!Object.hasOwn(n,e)))}const Ve=({name:r,label:n,help:e})=>{const{adminClient:o}=I(),{t:s}=R(),[l,m]=h([]);return S(()=>o.authenticationManagement.getRequiredActions(),c=>{const p=c.filter(a=>a.enabled);m(p)},[]),t(ce,{name:r,label:s(n),labelIcon:s(e),controller:{defaultValue:[]},isScrollable:!0,maxMenuHeight:"375px",variant:de.typeaheadMulti,chipGroupProps:{numChips:3},placeholderText:s("requiredActionPlaceholder"),menuAppendTo:"parent",options:l.map(({alias:c,name:p})=>({key:c,value:p||c}))})},Be=({form:r,realm:n,user:e,bruteForce:{isBruteForceProtected:o,isLocked:s}={isBruteForceProtected:!1,isLocked:!1},userProfileMetadata:l,save:m,onGroupsUpdate:c})=>{const{adminClient:p}=I(),{t:a}=R(),H=je(),{addAlert:L,addError:w}=ue(),{hasAccess:G}=E(),M=G("manage-users"),P=G("view-realm"),{whoAmI:N}=me(),B=N.getLocale(),{handleSubmit:z,setValue:q,watch:W,control:K,reset:_,formState:O}=r,{errors:$}=O,J=W("username"),[b,C]=h([]),[F,g]=h(!1),[j,Q]=h(s);qe(()=>{q("requiredActions",e?.requiredActions||[])},[e,q]);const X=async()=>{try{await p.attackDetection.del({id:e.id}),L(a("unlockSuccess"),D.success)}catch(i){w("unlockError",i)}},Y=i=>{C(b.filter(d=>d.name!==i)),c?.(b)},Z=async i=>{C([...b,...i]),c?.([...b,...i])},ee=async i=>{i.forEach(async ae=>{try{await p.users.addToGroup({id:e.id,groupId:ae.id}),L(a("addedGroupMembership"),D.success)}catch(re){w("addedGroupMembershipError",re)}})},te=()=>{g(!F)};return t(Ce,{isHorizontal:!0,onSubmit:z(m),role:"query-users",fineGrainedAccess:e?.access?.manage,className:"pf-v5-u-mt-lg",children:u(pe,{...r,children:[F&&t(Fe,{type:"selectMany",text:{title:"selectGroups",ok:"join"},canBrowse:M,onConfirm:i=>{e?.id?ee(i||[]):Z(i||[]),g(!1)},onClose:()=>g(!1),filterGroups:b}),e?.id&&u(y,{children:[t(f,{label:a("id"),fieldId:"kc-id",isRequired:!0,children:t(x,{id:e.id,"aria-label":a("userID"),value:e.id,readOnly:!0})}),t(f,{label:a("createdAt"),fieldId:"kc-created-at",isRequired:!0,children:t(x,{value:H(new Date(e.createdTimestamp)),id:"kc-created-at",readOnly:!0})})]}),t(Ve,{name:"requiredActions",label:"requiredUserActions",help:"requiredUserActionsHelp"}),(e?.federationLink||e?.origin)&&P&&t(f,{label:a("federationLink"),labelIcon:t(k,{helpText:a("federationLinkHelp"),fieldLabelId:"federationLink"}),children:t(Ue,{user:e})}),l?u(y,{children:[t(Oe,{name:"emailVerified",label:a("emailVerified"),labelIcon:a("emailVerifiedHelp")}),t(be,{form:r,userProfileMetadata:l,hideReadOnly:!e,supportedLocales:n.supportedLocales||[],currentLocale:B,t:(i,d)=>a(i,d)})]}):u(y,{children:[!n.registrationEmailAsUsername&&t(A,{name:"username",label:a("username"),readOnly:!!e?.id&&!n.editUsernameAllowed&&n.editUsernameAllowed!==void 0,rules:{required:a("required")}}),t(A,{name:"email",label:a("email"),type:"email",rules:{pattern:{value:fe,message:a("emailInvalid")}}}),t(he,{name:"emailVerified",label:a("emailVerified"),labelIcon:a("emailVerifiedHelp"),labelOn:a("yes"),labelOff:a("no")}),t(A,{name:"firstName",label:a("firstName")}),t(A,{name:"lastName",label:a("lastName")})]}),o&&t(f,{label:a("temporaryLocked"),fieldId:"temporaryLocked",labelIcon:t(k,{helpText:a("temporaryLockedHelp"),fieldLabelId:"temporaryLocked"}),children:t(Ae,{"data-testid":"user-locked-switch",id:"temporaryLocked",onChange:(i,d)=>{X(),Q(d),m({enabled:!d})},isChecked:j,isDisabled:!j,label:a("on"),labelOff:a("off")})}),!e?.id&&u(f,{label:a("groups"),fieldId:"kc-groups",labelIcon:t(k,{helpText:a("groupsHelp"),fieldLabelId:"groups"}),children:[t(ge,{name:"groups",defaultValue:[],control:K,render:()=>u(ye,{children:[t(V,{children:t(ke,{categoryName:" ",children:b.map(i=>t(ve,{onClick:()=>Y(i.name),children:i.path},i.id))})}),t(V,{children:t(v,{id:"kc-join-groups-button",onClick:te,variant:"secondary","data-testid":"join-groups-button",children:a("joinGroups")})})]})}),$.requiredActions&&t(Ie,{message:a("required")})]}),u(Le,{children:[t(we,{formState:O,"data-testid":e?.id?"save-user":"create-user",isDisabled:!e?.id&&!J&&n.registrationEmailAsUsername===!1,allowNonDirty:!0,allowInvalid:!0,children:e?.id?a("save"):a("create")}),t(v,{"data-testid":"cancel-create-user",variant:"link",onClick:e?.id?()=>_(xe(e)):void 0,component:e?.id?void 0:i=>t(T,{...i,to:Ge({realm:n.realm})}),children:e?.id?a("revert"):a("cancel")})]})]})})};export{Ue as F,Ve as R,Be as U,xe as a,Ne as f,Pe as t};
//# sourceMappingURL=UserForm-_c-oiMDM.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy