keycloak-d4science-spi-parent/keycloak-d4science-theme/src/main/resources/theme/d4science/account/resources/assets/PersonalInfo-5w_t768h.js

3 lines
6.1 KiB
JavaScript

import{jsx as l,jsxs as P}from"react/jsx-runtime";import*as u from"react";import{useState as R}from"react";import{r as N,s as U,_ as D,f as m,A as j,u as w,a as F,t as O,G as V,b as G,S as H,z as B,B as T,E as J,v as q,J as $,o as K,W as Q,U as X}from"./index-CmO9OReA.js";import{P as Y,s as Z,h as ee,i as te}from"./Page-0WGWoSmH.js";import{F as ae,A as ne}from"./Form-DzOsnxGQ.js";import"react-dom";const o={expandableSection:"pf-c-expandable-section",expandableSectionContent:"pf-c-expandable-section__content",expandableSectionToggle:"pf-c-expandable-section__toggle",expandableSectionToggleIcon:"pf-c-expandable-section__toggle-icon",expandableSectionToggleText:"pf-c-expandable-section__toggle-text",modifiers:{expanded:"pf-m-expanded",detached:"pf-m-detached",truncate:"pf-m-truncate",limitWidth:"pf-m-limit-width",displayLg:"pf-m-display-lg",indented:"pf-m-indented",active:"pf-m-active",expandTop:"pf-m-expand-top",overpassFont:"pf-m-overpass-font"}},M={name:"--pf-c-expandable-section--m-truncate__content--LineClamp",value:"3",var:"var(--pf-c-expandable-section--m-truncate__content--LineClamp)"};var c;(function(t){t.default="default",t.truncate="truncate"})(c||(c={}));const W=(t,e)=>{!e||t<1||e.style.setProperty(M.name,t.toString())};class k extends u.Component{constructor(e){super(e),this.expandableContentRef=u.createRef(),this.observer=()=>{},this.checkToggleVisibility=()=>{var a;if(!((a=this.expandableContentRef)===null||a===void 0)&&a.current){const d=this.props.truncateMaxLines||parseInt(M.value),p=this.expandableContentRef.current.scrollHeight/parseInt(getComputedStyle(this.expandableContentRef.current).lineHeight);this.setState({hasToggle:p>d})}},this.resize=()=>{const{offsetWidth:a}=this.expandableContentRef.current;this.state.previousWidth!==a&&(this.setState({previousWidth:a}),this.checkToggleVisibility())},this.handleResize=N(this.resize,250),this.state={isExpanded:e.isExpanded,hasToggle:!0,previousWidth:void 0}}calculateToggleText(e,a,d,p){return p&&a!==""?a:!p&&d!==""?d:e}componentDidMount(){if(this.props.variant===c.truncate){const e=this.expandableContentRef.current;this.setState({previousWidth:e.offsetWidth}),this.observer=U(e,this.handleResize,!1),this.props.truncateMaxLines&&W(this.props.truncateMaxLines,e),this.checkToggleVisibility()}}componentDidUpdate(e){if(this.props.variant===c.truncate&&e.truncateMaxLines!==this.props.truncateMaxLines){const a=this.expandableContentRef.current;W(this.props.truncateMaxLines,a),this.checkToggleVisibility()}}componentWillUnmount(){this.props.variant===c.truncate&&this.observer()}render(){const e=this.props,{onToggle:a,isActive:d,className:p,toggleText:E,toggleTextExpanded:h,toggleTextCollapsed:S,toggleContent:f,children:C,isExpanded:x,isDetached:b,displaySize:L,isWidthLimited:_,isIndented:y,contentId:A,variant:g,truncateMaxLines:I}=e,n=D(e,["onToggle","isActive","className","toggleText","toggleTextExpanded","toggleTextCollapsed","toggleContent","children","isExpanded","isDetached","displaySize","isWidthLimited","isIndented","contentId","variant","truncateMaxLines"]);let r=a,i=x;x===void 0&&(i=this.state.isExpanded,r=z=>{this.setState({isExpanded:z},()=>a(this.state.isExpanded))});const s=this.calculateToggleText(E,h,S,i),v=!b&&u.createElement("button",{className:m(o.expandableSectionToggle),type:"button","aria-expanded":i,onClick:()=>r(!i)},g!==c.truncate&&u.createElement("span",{className:m(o.expandableSectionToggleIcon)},u.createElement(j,{"aria-hidden":!0})),u.createElement("span",{className:m(o.expandableSectionToggleText)},f||s));return u.createElement("div",Object.assign({className:m(o.expandableSection,i&&o.modifiers.expanded,d&&o.modifiers.active,b&&o.modifiers.detached,L==="large"&&o.modifiers.displayLg,_&&o.modifiers.limitWidth,y&&o.modifiers.indented,g===c.truncate&&o.modifiers.truncate,p)},n),g===c.default&&v,u.createElement("div",{ref:this.expandableContentRef,className:m(o.expandableSectionContent),hidden:g!==c.truncate&&!i,id:A},C),g===c.truncate&&this.state.hasToggle&&v)}}k.displayName="ExpandableSection";k.defaultProps={className:"",toggleText:"",toggleTextExpanded:"",toggleTextCollapsed:"",onToggle:t=>{},isActive:!1,isDetached:!1,displaySize:"default",isWidthLimited:!1,isIndented:!1,contentId:"",variant:"default"};const de=()=>{const{t}=w(),e=F(),[a,d]=R(),[p,E]=R([]),h=O({mode:"onChange"}),{handleSubmit:S,reset:f,setValue:C,setError:x}=h,{addAlert:b,addError:L}=V();G(n=>Promise.all([ee({signal:n,context:e}),te({signal:n,context:e})]),([n,r])=>{d(n.userProfileMetadata),E(r),f(n),Object.entries(n.attributes||{}).forEach(([i,s])=>C(`attributes[${X(i)}]`,s))});const _=async n=>{try{const r=Object.fromEntries(Object.entries(n.attributes||{}).map(([s,v])=>[$(s),v]));await Z(e,{...n,attributes:r});const i=r.locale?.toString();K.changeLanguage(i,s=>{s&&console.warn("Error(s) loading locale",i,s)}),e.keycloak.updateToken(),b(t("accountUpdatedMessage"))}catch(r){L(t("accountUpdatedError").toString()),Q({responseData:{errors:r}},(i,s)=>x(i,s),(i,s)=>t(i,s))}};if(!a)return l(H,{});const{updateEmailFeatureEnabled:y,updateEmailActionEnabled:A,isRegistrationEmailAsUsername:g,isEditUserNameAllowed:I}=e.environment.features;return l(Y,{title:t("personalInfo"),description:t("personalInfoDescription"),children:P(ae,{isHorizontal:!0,onSubmit:S(_),children:[l(B,{form:h,userProfileMetadata:a,supportedLocales:p,t:(n,r)=>t(n,r),renderer:n=>n.name==="email"&&y&&A&&(!g||I)?l(T,{id:"update-email-btn",variant:"link",onClick:()=>e.keycloak.login({action:"UPDATE_EMAIL"}),icon:l(J,{}),iconPosition:"right",children:t("updateEmail")}):void 0}),P(ne,{children:[l(T,{"data-testid":"save",type:"submit",id:"save-btn",variant:"primary",children:t("save")}),l(T,{"data-testid":"cancel",id:"cancel-btn",variant:"link",onClick:()=>f(),children:t("cancel")})]}),e.environment.features.deleteAccountAllowed&&l(k,{"data-testid":"delete-account",toggleText:t("deleteAccount"),children:l(q,{isInline:!0,title:t("deleteAccount"),variant:"danger",actionLinks:l(T,{id:"delete-account-btn",variant:"danger",onClick:()=>e.keycloak.login({action:"delete_account"}),className:"delete-button",children:t("delete")}),children:t("deleteAccountWarning")})})]})})};export{de as PersonalInfo,de as default};
//# sourceMappingURL=PersonalInfo-5w_t768h.js.map