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

3 lines
6.5 KiB
JavaScript

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