Files
synapse-app-mas/mas/share/assets/_account.index-Bgj2uEUe.js
2025-12-01 08:14:13 -06:00

74 lines
17 KiB
JavaScript

import{r,j as e,v as we,w as $,x as O,y as Ce,R as z,F as D,f as S,g as G,m as X,S as be,B as y,C as ve,z as ye,E as Ee,V as Ae,H,b as T,u as I,d as te,l as V,k as E,D as se,e as ne,G as Ne,T as k,J as Re,K as C,M as Ie,N as Z,h as re,i as ae,a as Se,Q as Te,U as ke,W as Pe,X as Q,Y as De,Z as Fe,_ as qe,$ as Me,n as Oe,c as Be,a0 as Le,a1 as Ue,a2 as $e,o as ze,q as Ge,p as He,a3 as Ve}from"./main-CiAhdYQG.js";import{A as Qe}from"./Avatar-B3RWCmae.js";import{I as oe}from"./check-Cx46Fv0J.js";import{S as R}from"./Separator-CVNE-7yB.js";import{T as We}from"./Trans-CeobkUgR.js";import{B as Ke}from"./ButtonLink-kWcKQZoZ.js";import{a as Ye}from"./Heading-zTQC9Kqs.js";import{u as Je}from"./EndBrowserSessionButton-DXsnVcVV.js";import"./_commonjsHelpers-DaWZu8wl.js";/* empty css */import"./computer-Cx9wZ7Nf.js";const Xe="_container_1hel1_10",Ze="_input_1hel1_18",et="_ui_1hel1_19",B={container:Xe,input:Ze,ui:et},tt=r.forwardRef(function({className:t,...a},n){const i=$(B.container,t);return e.jsxs("div",{className:i,children:[e.jsx("input",{ref:n,className:B.input,...a,type:"checkbox"}),e.jsx("div",{className:B.ui,children:e.jsx(oe,{"aria-hidden":!0})})]})}),st=r.forwardRef(function(t,a){return e.jsx(we,{asChild:!0,children:e.jsx(tt,{ref:a,...t})})}),nt=r.forwardRef(function({className:t,control:a,children:n,...i},u){const c=$(O["inline-field"],t);return e.jsxs(Ce,{ref:u,...i,className:c,children:[e.jsx("div",{className:O["inline-field-control"],children:a}),e.jsx("div",{className:O["inline-field-body"],children:n})]})}),rt="_controls_17lij_8",L={controls:rt,"button-group":"_button-group_17lij_18"};function at(s,t){switch(t){case 0:return s===0||s===3?1:s;case 1:return 2;case 4:return 0;case 2:return s===2?3:s;case 3:return s===2?0:s;case 5:return s===3?0:s}ot(t)}function ot(s){throw new Error(`Unreachable value: ${s}`)}const it=r.forwardRef(function({className:t,label:a,onSave:n,onCancel:i,onInput:u,onClearServerErrors:c,serverInvalid:h,saveButtonLabel:p,cancelButtonLabel:f,savedLabel:g,savingLabel:x,helpLabel:_,disabled:m,children:b,...o},j){const[l,d]=r.useReducer(at,0),v=r.useRef(!1),[q,P]=r.useState(!1),he=l===1||l===2||q,N=r.useRef(void 0);r.useEffect(()=>(l===3&&(N.current=setTimeout(()=>{d(5),N.current=void 0},2e3)),()=>{N.current&&clearTimeout(N.current),N.current=void 0}),[l]);const fe=r.useRef(null),J=r.useRef(null),M=r.useRef(null),pe=r.useCallback(()=>{v.current||(v.current=!0,P(!0))},[q,P]),ge=r.useCallback(w=>{v.current&&(w.currentTarget.contains(w.relatedTarget)||(v.current=!1,P(!1)))},[q,P]),xe=r.useCallback(w=>{d(0),u?.(w)},[d,u]),_e=r.useCallback(async w=>{if(w.preventDefault(),l!==0)try{d(1),J.current?.blur(),await n?.(w),d(2)}catch{d(3)}},[n,l,N]),je=r.useCallback(w=>{M.current?.blur(),i?.(w),d(4)},[M,i]);return e.jsx(z,{className:t,onSubmit:_e,onReset:je,onFocus:pe,onBlur:ge,onClearServerErrors:c,ref:fe,children:e.jsxs(D,{name:"input",serverInvalid:h,children:[e.jsx(S,{children:a}),e.jsxs("div",{className:L.controls,children:[e.jsx(G,{ref:j,...o,onInput:xe,disabled:m||l===2}),he&&e.jsxs("div",{className:L["button-group"],children:[e.jsx(X,{label:p,children:e.jsx(be,{asChild:!0,children:e.jsx(y,{type:"submit",kind:"primary",size:"sm",ref:J,disabled:l!==1,iconOnly:!0,Icon:oe})})}),e.jsx(X,{label:f,children:e.jsx(y,{type:"reset",kind:"secondary",size:"sm",ref:M,className:L.button,disabled:l===2,iconOnly:!0,Icon:ve})})]})]}),l===2?e.jsx(ye,{children:x}):b,g&&l===3&&e.jsx(Ee,{children:g}),_&&(l===0||l===1)&&e.jsx(Ae,{children:w=>(w===void 0||w.valid)&&!h&&e.jsx(H,{children:_})})]})})});function ie(s,t){return e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 24 24",ref:t,...s,children:e.jsx("path",{d:"M9 12.031q0-.424.288-.712A.97.97 0 0 1 10 11.03h7.15l-1.875-1.875a.96.96 0 0 1-.3-.7q0-.4.325-.725a.93.93 0 0 1 .712-.287.98.98 0 0 1 .688.287l3.6 3.6q.15.15.212.325.063.175.063.375 0 .201-.062.375a.9.9 0 0 1-.213.325l-3.6 3.6q-.3.3-.712.288a.98.98 0 0 1-.688-.288 1.02 1.02 0 0 1-.312-.712.93.93 0 0 1 .287-.713l1.875-1.875H10a.97.97 0 0 1-.712-.287A.97.97 0 0 1 9 12.03m-6-7q0-.824.588-1.412A1.93 1.93 0 0 1 5 3.03h6q.424 0 .713.288.287.287.287.712t-.287.713A.97.97 0 0 1 11 5.03H5v14h6q.424 0 .713.288.287.287.287.712t-.287.713a.97.97 0 0 1-.713.287H5q-.824 0-1.412-.587A1.93 1.93 0 0 1 3 19.03z"})})}ie.displayName="SignOutIcon";const ee=r.forwardRef(ie),ct=E(`
fragment AccountDeleteButton_user on User {
username
hasPassword
matrix {
mxid
displayName
}
}
`),lt=E(`
fragment AccountDeleteButton_siteConfig on SiteConfig {
passwordLoginEnabled
}
`),dt=E(`
mutation DeactivateUser($hsErase: Boolean!, $password: String) {
deactivateUser(input: { hsErase: $hsErase, password: $password }) {
status
}
}
`),ut=({mxid:s,displayName:t,username:a})=>e.jsxs("section",{className:"flex items-center p-4 gap-4 border border-[var(--cpd-color-gray-400)] rounded-xl",children:[e.jsx(Qe,{id:s,name:t||a,size:"56px"}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx(k,{type:"body",weight:"semibold",size:"lg",className:"text-primary",children:t||a}),e.jsx(k,{type:"body",weight:"regular",size:"md",className:"text-secondary",children:s})]})]}),mt=s=>{const t=T(ct,s.user),a=T(lt,s.siteConfig),{t:n}=I(),i=te({mutationFn:({password:o,hsErase:j})=>V({query:dt,variables:{password:o,hsErase:j}}),onSuccess:o=>{o.deactivateUser.status==="DEACTIVATED"&&window.location.reload()}}),[u,c]=r.useState(!1),[h,p]=r.useState(!1);r.useEffect(()=>{if(u){const o=setTimeout(()=>{p(!0)},500);return()=>clearTimeout(o)}p(!1)},[u]);const f=r.useCallback(o=>{c(o.currentTarget.value!=="")},[]),g=r.useCallback(o=>{c(o.currentTarget.value===t.matrix.mxid)},[t.matrix.mxid]),x=r.useCallback(o=>{if(o.preventDefault(),!h)return;const j=new FormData(o.currentTarget),l=j.get("password");if(l!==null&&typeof l!="string")throw new Error;const d=j.get("hs-erase")==="on";i.mutate({password:l,hsErase:d})},[i.mutate,h]),_=i.data?.deactivateUser.status==="INCORRECT_PASSWORD",m=i.isPending||i.data?.deactivateUser.status==="DEACTIVATED",b=t.hasPassword&&a.passwordLoginEnabled;return e.jsxs(se,{trigger:e.jsx(y,{kind:"tertiary",destructive:!0,size:"sm",className:"self-center",Icon:Z,children:n("frontend.account.delete_account.button")}),children:[e.jsx(ne,{children:n("frontend.account.delete_account.dialog_title")}),e.jsx(Ne,{className:"flex flex-col gap-4",children:e.jsx(We,{t:n,i18nKey:"frontend.account.delete_account.dialog_description",components:{text:e.jsx(k,{type:"body",weight:"regular",size:"md"}),list:e.jsx("ul",{className:"list-disc list-outside pl-6"}),item:e.jsx(k,{as:"li",type:"body",weight:"regular",size:"md"}),profile:e.jsx(ut,{mxid:t.matrix.mxid,username:t.username,displayName:t.matrix.displayName})}})}),e.jsxs(z,{onSubmit:x,children:[e.jsx(nt,{control:e.jsx(st,{}),name:"hs-erase",children:e.jsx(S,{children:n("frontend.account.delete_account.erase_checkbox_label")})}),e.jsx(R,{className:"my-1"}),b?e.jsxs(D,{name:"password",serverInvalid:_,children:[e.jsx(S,{children:n("frontend.account.delete_account.password_label")}),e.jsx(Re,{autoComplete:"current-password",required:!0,onInput:f}),e.jsx(C,{match:"valueMissing",children:n("frontend.errors.field_required")}),_&&e.jsx(C,{children:n("frontend.account.delete_account.incorrect_password")})]}):e.jsxs(D,{name:"mxid",children:[e.jsx(S,{children:n("frontend.account.delete_account.mxid_label",{mxid:t.matrix.mxid})}),e.jsx(G,{required:!0,placeholder:t.matrix.mxid,onInput:g}),e.jsx(C,{match:"valueMissing",children:n("frontend.errors.field_required")}),e.jsx(C,{match:o=>o!==t.matrix.mxid,children:n("frontend.account.delete_account.mxid_mismatch")})]}),u&&e.jsx(Ie,{type:"critical",title:n("frontend.account.delete_account.alert_title"),children:n("frontend.account.delete_account.alert_description")}),e.jsxs(y,{type:"submit",kind:"primary",destructive:!0,disabled:!h||m,Icon:m?void 0:Z,children:[m&&e.jsx(re,{inline:!0}),n("frontend.account.delete_account.button")]})]}),e.jsx(ae,{asChild:!0,children:e.jsx(y,{kind:"tertiary",children:n("action.cancel")})})]})},ht="_link_1g96u_8",ft={link:ht},pt=E(`
fragment PasswordChange_siteConfig on SiteConfig {
passwordChangeAllowed
}
`);function gt({siteConfig:s}){const{t}=I(),{passwordChangeAllowed:a}=T(pt,s);return e.jsx(z,{children:e.jsxs(D,{name:"password_preview",children:[e.jsx(S,{children:t("frontend.account.password.label")}),e.jsx(G,{type:"password",readOnly:!0,value:"this looks like a password"}),e.jsxs(H,{children:[a&&e.jsx(Se,{to:"/password/change",className:ft.link,children:t("frontend.account.password.change")}),!a&&t("frontend.account.password.change_disabled")]})]})})}var F="Collapsible",[xt,Kt]=ke(F),[_t,W]=xt(F),ce=r.forwardRef((s,t)=>{const{__scopeCollapsible:a,open:n,defaultOpen:i,disabled:u,onOpenChange:c,...h}=s,[p,f]=Te({prop:n,defaultProp:i??!1,onChange:c,caller:F});return e.jsx(_t,{scope:a,disabled:u,contentId:Pe(),open:p,onOpenToggle:r.useCallback(()=>f(g=>!g),[f]),children:e.jsx(Q.div,{"data-state":Y(p),"data-disabled":u?"":void 0,...h,ref:t})})});ce.displayName=F;var le="CollapsibleTrigger",de=r.forwardRef((s,t)=>{const{__scopeCollapsible:a,...n}=s,i=W(le,a);return e.jsx(Q.button,{type:"button","aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":Y(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled,...n,ref:t,onClick:De(s.onClick,i.onOpenToggle)})});de.displayName=le;var K="CollapsibleContent",ue=r.forwardRef((s,t)=>{const{forceMount:a,...n}=s,i=W(K,s.__scopeCollapsible);return e.jsx(Fe,{present:a||i.open,children:({present:u})=>e.jsx(jt,{...n,ref:t,present:u})})});ue.displayName=K;var jt=r.forwardRef((s,t)=>{const{__scopeCollapsible:a,present:n,children:i,...u}=s,c=W(K,a),[h,p]=r.useState(n),f=r.useRef(null),g=qe(t,f),x=r.useRef(0),_=x.current,m=r.useRef(0),b=m.current,o=c.open||h,j=r.useRef(o),l=r.useRef(void 0);return r.useEffect(()=>{const d=requestAnimationFrame(()=>j.current=!1);return()=>cancelAnimationFrame(d)},[]),Me(()=>{const d=f.current;if(d){l.current=l.current||{transitionDuration:d.style.transitionDuration,animationName:d.style.animationName},d.style.transitionDuration="0s",d.style.animationName="none";const v=d.getBoundingClientRect();x.current=v.height,m.current=v.width,j.current||(d.style.transitionDuration=l.current.transitionDuration,d.style.animationName=l.current.animationName),p(n)}},[c.open,n]),e.jsx(Q.div,{"data-state":Y(c.open),"data-disabled":c.disabled?"":void 0,id:c.contentId,hidden:!o,...u,ref:g,style:{"--radix-collapsible-content-height":_?`${_}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...s.style},children:o&&i})});function Y(s){return s?"open":"closed"}var wt=ce,Ct=de,bt=ue;function me(s,t){return e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 24 24",ref:t,...s,children:e.jsx("path",{d:"m12 10.775-3.9 3.9a.95.95 0 0 1-.7.275.95.95 0 0 1-.7-.275.95.95 0 0 1-.275-.7q0-.425.275-.7l4.6-4.6q.15-.15.325-.212Q11.8 8.4 12 8.4t.375.063a.9.9 0 0 1 .325.212l4.6 4.6a.95.95 0 0 1 .275.7.95.95 0 0 1-.275.7.95.95 0 0 1-.7.275.95.95 0 0 1-.7-.275z"})})}me.displayName="ChevronUpIcon";const vt=r.forwardRef(me),yt="_root_1hqni_8",Et="_heading_1hqni_14",At="_trigger_1hqni_20",Nt="_trigger-title_1hqni_29",Rt="_trigger-icon_1hqni_34",It="_description_1hqni_42",St="_content_1hqni_48",A={root:yt,heading:Et,trigger:At,triggerTitle:Nt,triggerIcon:Rt,description:It,content:St},U=({title:s,description:t,defaultOpen:a,className:n,children:i,...u})=>{const{t:c}=I(),[h,p]=r.useState(a||!1),f=r.useId(),g=r.useId(),x=r.useCallback(_=>{_.preventDefault(),p(m=>!m)},[]);return e.jsx(wt,{...u,open:h,onOpenChange:p,asChild:!0,"aria-labelledby":f,"aria-describedby":t?g:void 0,className:$(A.root,n),children:e.jsxs("section",{children:[e.jsxs("header",{className:A.heading,children:[e.jsxs("div",{className:A.trigger,children:[e.jsx(Ye,{onClick:x,id:f,className:A.triggerTitle,children:s}),e.jsx(Ct,{className:A.triggerIcon,asChild:!0,children:e.jsx(Oe,{tooltip:c(h?"action.collapse":"action.expand"),children:e.jsx(vt,{})})})]}),t&&e.jsx("p",{className:A.description,id:g,children:t})]}),e.jsx(bt,{asChild:!0,children:e.jsx("article",{className:A.content,children:i})})]})})},Tt=E(`
fragment AddEmailForm_user on User {
hasPassword
}
`),kt=E(`
fragment AddEmailForm_siteConfig on SiteConfig {
passwordLoginEnabled
}
`),Pt=E(`
mutation AddEmail($email: String!, $password: String, $language: String!) {
startEmailAuthentication(
input: { email: $email, password: $password, language: $language }
) {
status
violations
authentication {
id
}
}
}
`),Dt=({user:s,siteConfig:t,onAdd:a})=>{const{hasPassword:n}=T(Tt,s),{passwordLoginEnabled:i}=T(kt,t),u=n&&i,{t:c,i18n:h}=I(),p=Be(),[f,g]=Le(),x=te({mutationFn:({email:o,password:j,language:l})=>V({query:Pt,variables:{email:o,password:j,language:l}}),onSuccess:async o=>{if(p.invalidateQueries({queryKey:["userEmails"]}),o.startEmailAuthentication.status==="STARTED"){if(!o.startEmailAuthentication.authentication?.id)throw new Error("Unexpected response from server");await a(o.startEmailAuthentication.authentication?.id)}}}),_=r.useCallback(async o=>{o.preventDefault();const l=new FormData(o.currentTarget).get("input");let d;if(u&&(d=await f()),(await x.mutateAsync({email:l,password:d,language:h.languages[0]})).startEmailAuthentication.status!=="STARTED")throw new Error},[x.mutateAsync,u,f,h.languages]),m=x.data?.startEmailAuthentication.status??null,b=x.data?.startEmailAuthentication.violations??[];return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{title:c("frontend.add_email_form.password_confirmation"),ref:g}),e.jsxs(it,{onSave:_,required:!0,type:"email",serverInvalid:!!m&&m!=="STARTED",label:c("frontend.add_email_form.email_field_label"),helpLabel:c("frontend.add_email_form.email_field_help"),saveButtonLabel:c("action.save"),savingLabel:c("common.saving"),savedLabel:c("common.saved"),cancelButtonLabel:c("action.cancel"),children:[e.jsx(C,{match:"typeMismatch",forceMatch:m==="INVALID_EMAIL_ADDRESS",children:c("frontend.add_email_form.email_invalid_error")}),m==="IN_USE"&&e.jsx(C,{children:c("frontend.add_email_form.email_in_use_error")}),m==="RATE_LIMITED"&&e.jsx(C,{children:c("frontend.errors.rate_limit_exceeded")}),m==="DENIED"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{children:c("frontend.add_email_form.email_denied_error")}),b.map(o=>e.jsx(H,{children:o},o))]}),m==="INCORRECT_PASSWORD"&&e.jsx(C,{children:c("frontend.add_email_form.incorrect_password_error")})]})]})},Ft=E(`
query UserProfile {
viewerSession {
__typename
... on BrowserSession {
id
user {
...AddEmailForm_user
...UserEmailList_user
...AccountDeleteButton_user
hasPassword
emails(first: 0) {
totalCount
}
}
}
}
siteConfig {
emailChangeAllowed
passwordLoginEnabled
accountDeactivationAllowed
...AddEmailForm_siteConfig
...UserEmailList_siteConfig
...PasswordChange_siteConfig
...AccountDeleteButton_siteConfig
}
}
`),qt=Ge({queryKey:["userProfile"],queryFn:({signal:s})=>V({query:Ft,signal:s})}),Mt=({id:s})=>{const{t}=I(),a=Je(s);return e.jsxs(se,{trigger:e.jsx(y,{kind:"primary",destructive:!0,size:"lg",Icon:ee,children:t("frontend.account.sign_out.button")}),children:[e.jsx(ne,{children:t("frontend.account.sign_out.dialog")}),e.jsxs(y,{type:"button",kind:"primary",destructive:!0,onClick:()=>a.mutate(),disabled:a.isPending,Icon:a.isPending?void 0:ee,children:[a.isPending&&e.jsx(re,{inline:!0}),t("action.sign_out")]}),e.jsx(ae,{asChild:!0,children:e.jsx(y,{kind:"tertiary",children:t("action.cancel")})})]})};function Yt(){const s=$e(),{t}=I(),{data:{viewerSession:a,siteConfig:n}}=ze(qt);if(a?.__typename!=="BrowserSession")throw He();const i=async u=>{await s({to:"/emails/$id/verify",params:{id:u}})};return e.jsxs("div",{className:"flex flex-col gap-6",children:[(n.emailChangeAllowed||a.user.emails.totalCount>0)&&e.jsxs(e.Fragment,{children:[e.jsxs(U,{defaultOpen:!0,title:t("frontend.account.contact_info"),children:[e.jsx(Ve,{user:a.user,siteConfig:n}),n.emailChangeAllowed&&e.jsx(Dt,{user:a.user,siteConfig:n,onAdd:i})]}),e.jsx(R,{kind:"section"})]}),n.passwordLoginEnabled&&a.user.hasPassword&&e.jsxs(e.Fragment,{children:[e.jsx(U,{defaultOpen:!0,title:t("frontend.account.account_password"),children:e.jsx(gt,{siteConfig:n})}),e.jsx(R,{kind:"section"})]}),e.jsxs(U,{title:t("common.e2ee"),children:[e.jsx(k,{className:"text-secondary",size:"md",children:t("frontend.reset_cross_signing.description")}),e.jsx(Ke,{to:"/reset-cross-signing",kind:"secondary",destructive:!0,children:t("frontend.reset_cross_signing.start_reset")})]}),e.jsx(R,{kind:"section"}),e.jsx(Mt,{id:a.id}),n.accountDeactivationAllowed&&e.jsxs(e.Fragment,{children:[e.jsx(R,{}),e.jsx(mt,{user:a.user,siteConfig:n})]}),e.jsx(R,{})]})}export{Yt as component};
//# sourceMappingURL=_account.index-Bgj2uEUe.js.map