1import{r as a,j as e}from"./react-vendor-Bqf2vwgD.js";import{F as ge}from"./fontawesome-B_YrodPL.js";import{w as me,u as he,h7 as pe,at as xe,ai as le,C as x,Z as te,X as _,aY as j,bg as we,hb as be,B as u,G as B,c as ae,aW as Se,e as C,a as de,P as je,n as Pe,bK as Q,a_ as ee,hE as ye,be as se,M as ue,l as ce,hr as ve,hf as _e}from"./index-MfYquvAk.js";import{E as Ce}from"./EmailInput-CfF3HI9H.js";import{M as ke}from"./MobileNumberSelect-CAqeLz19.js";import{u as Ee}from"./react-hook-form-NX7SULTW.js";import{U as Fe,V as Me}from"./main-B8aAhXJ7.js";import Ae from"./SetupTwoFactorAuthModal-E07X49rr.js";import{U as Te}from"./UserSessions-D_f9F9Bt.js";import{C as Ie}from"./Confirm-0h-9t8Fo.js";import{L as Le}from"./Login-FBtBqL0O.js";import{P as Ne}from"./PasswordInputWithStrengthIndicator-Bd_VYSGw.js";import"./detect-browser-KS8fqzLC.js";import"./raygun-8T1JTxH6.js";import"./dexie-CHhaZb09.js";import"./lodash-DwqJlx9e.js";import"./react-router-BdiPjGpe.js";import"./uuid-SoommWqA.js";import"./libphonenumber-Bs_56CJR.js";import"./iconLibrary-DY9wls56.js";import"./CountrySelect-CbQm6vOG.js";import"./countryUtils-B_10-2pG.js";import"./google-oauth-B1e8M3oY.js";import"./axios-42ANG6Sg.js";import"./headlessui-DGoynQdn.js";import"./gtm-8jAo5NOf.js";import"./OTPInput-C4a_4dPQ.js";const Re=({user:t,userUpdated:i})=>{var T,O,W,Y,K,$,z,I,L,G,N;const m=he(),P=pe(m,t.role_id),y=xe(t)&&!!P,[d,k]=a.useState(!1),[v,f]=a.useState(null),[w,n]=a.useState(!1),[E,c]=a.useState(!1),[U,F]=a.useState(!1),[H,M]=a.useState(le(t)),[A,b]=a.useState(null),q=a.useRef(null),o=Ee({mode:"onBlur"}),V=async h=>{c(!0),f(null);let g={username:t.username},X={url:H};if(A&&t&&(X=await Me(m,t,A,"image/*"),g.profile_picture_filename=A.name,!X.url)){f("Failed to upload profile picture");return}let R=null,Z;if(d){let{first_names:l,surname:D,email:p,phone_number:J}=h;p=p.toLowerCase(),g={...g,first_names:l,surname:D,email:p,phone_number:J}}try{const l=await ae(m,"/users/my-profile","PATCH",g);l.ok&&(M(le({...t,profile_picture_filename:g.profile_picture_filename})),Z=l.data,Se(Z,void 0,m),F(!0),n(!1),k(!1),i({...l.data,role:m.roles.filter(D=>{var p;return D.id===((p=l==null?void 0:l.data)==null?void 0:p.role_id)})[0]})),l.ok||(R=C(l,!0))}catch(l){R=C(l)}c(!1),f(R)};return t?e.jsxs(x,{heading:{title:"Contact details",icon:"user",iconColor:"yellow",toggleEditMode:()=>k(!0),isEditModeHidden:d},children:[e.jsxs("div",{className:"grid grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{children:d?e.jsx(te,{label:"First names",defaultValue:t.first_names,name:"first_names",validation:o,rules:{required:"This field is required"},type:"text",onChange:()=>n(!0),validationStatus:{hasError:!!(o.formState.errors&&o.formState.errors.first_names),message:(W=(O=(T=o.formState.errors)==null?void 0:T.first_names)==null?void 0:O.message)==null?void 0:W.toString()}}):e.jsx(_,{label:"First names",value:t.first_names})}),e.jsx("div",{children:d?e.jsx(te,{label:"Surname",defaultValue:t.surname,name:"surname",validation:o,rules:{required:"This field is required"},type:"text",onChange:()=>n(!0),validationStatus:{hasError:!!(o.formState.errors&&o.formState.errors.surname),message:($=(K=(Y=o.formState.errors)==null?void 0:Y.surname)==null?void 0:K.message)==null?void 0:$.toString()}}):e.jsx(_,{label:"Surname",value:t.surname})}),e.jsx("div",{children:d?e.jsx("div",{className:"w-96",children:e.jsx(ke,{label:"Contact number",value:t.phone_number,name:"phone_number",onChange:()=>n(!0),validation:o,validationStatus:{hasError:!!(o.formState.errors&&o.formState.errors.phone_number),message:(I=(z=o.formState.errors.phone_number)==null?void 0:z.message)==null?void 0:I.toString()}})}):e.jsx(_,{label:"Contact number",value:t.phone_number})}),e.jsxs("div",{children:[d&&y&&e.jsxs(j.Info,{children:["Your email address must be on the ",e.jsxs("b",{children:["@",P]})," domain."]}),d?e.jsx(Ce,{label:"Email address",defaultValue:t.email,name:"email",validation:o,rules:{pattern:{value:we,message:"Invalid email address"},required:"This field is required",validate:{domain:h=>!y||be(P,h)||`Email must use the @${P} domain`}}
1,type:"text",onChange:()=>n(!0),validationStatus:{hasError:!!(o.formState.errors&&o.formState.errors.email),message:(N=(G=(L=o.formState.errors)==null?void 0:L.email)==null?void 0:G.message)==null?void 0:N.toString()}}):e.jsx(_,{label:"Email",value:t.email})]})]}),e.jsx("div",{className:"flex flex-row justify-end",children:e.jsx(Fe,{setResetImage:h=>{q.current=h},user:t,canEdit:!0,onProfilePictureChanged:h=>{n(!0),b(h)}})})]}),w&&e.jsxs(u.ButtonsPanel,{children:[e.jsx(u.Cancel,{title:"Cancel",onClick:()=>{q.current(),n(!1),b(null),k(!1)},isDisabled:E}),e.jsx(u.Primary,{onClick:o.handleSubmit(V),isDisabled:E||!w,isLoading:E,title:U&&!w?"Saved":"Save",icon:U&&!w?"check":void 0,loadingTitle:"Saving"})]}),v&&e.jsx("div",{className:"mt-70",children:B(v)})]}):null},De=me(Re);function Be(){var re,oe,ie;const t=he(),i=de(t),m=t.account,[P,y]=a.useState(!1),[d,k]=a.useState(!1),[v,f]=a.useState(!1),[w,n]=a.useState(null),[E,c]=a.useState(null),[U,F]=a.useState(""),[H,M]=a.useState(""),[A,b]=a.useState(!1),[q,o]=a.useState(!1),[V,T]=a.useState(!1),[O,W]=a.useState(((re=t.get("user_settings"))==null?void 0:re.dark_mode)??!1),[Y,K]=a.useState(!(((oe=t.get("user_settings"))==null?void 0:oe.disable_modal_blur)??!1)),[$,z]=a.useState(((ie=t.get("user_settings"))==null?void 0:ie.remember_filters)??!0),[I,L]=a.useState(null),[G,N]=a.useState(!1);async function h(){if(i){c(null);let s=null;try{const r=await _e(t,U,i.username);r.ok?ce(t):s=C(r)}catch(r){s=C(r)}f(!1),c(s),M(""),F("")}}async function g(s){var ne;n(null);let r=de(t);if(r){f(!0);try{const S=await ve(t,r.email,H,!1,void 0,s);S&&S.loginSuccess===!0&&S.user?(r=void 0,h()):(c(C(S)),f(!1))}catch(S){S.message="Please check your current password",c(S),f(!1),r=void 0,(ne=document.getElementById("oldPasswordField"))==null||ne.focus();return}}}async function X(){n(null),T(!0);const s=await ae(t,"/users/2fa/setup","POST",{});if(s.ok){const r=ee(i);r&&(r.two_factor_auth_enabled=!1,t.set("logged_in_user",r))}else n(s);T(!1)}async function R(s){W(s),ye(s);const r=await se(t,"dark_mode",s?"true":"false");r?n(r):t.emitter.emit("showToast",{text:"Preference updated.",variant:"success",autoHide:1500})}async function Z(s){K(s);const r=await se(t,"disable_modal_blur",s?"false":"true");r?n(r):t.emitter.emit("showToast",{text:"Preference updated.",variant:"success",autoHide:1500})}async function l(s){z(s);const r=await se(t,"remember_filters",s?"true":"false");r?n(r):t.emitter.emit("showToast",{text:"Preference updated.",variant:"success",autoHide:1500})}async function D(){L(null),N(!0);let s=await ae(t,"/users/sessions","DELETE",{username:i==null?void 0:i.username});N(!1),s.ok?ce(t):L(C(s))}function p(){return e.jsxs(e.Fragment,{children:[q&&e.jsx(Le.TwoFactorAuthenticationModal,{onHide:()=>o(!1),onChange:s=>{g(s),o(!1)}}),P&&e.jsxs(ue.Small,{shouldNotCloseOnEscPress:!0,onHide:()=>{c(null),y(!1),M(""),F("")},isCloseButtonVisible:!0,title:"Change password",children:[e.jsx(te,{containerClassName:"mt-4",shouldAutoFocus:!0,label:"Enter current password",type:d?"text":"password",name:"current-password",autoComplete:"current-password",value:H,id:"oldPasswordField",inputID:"oldPasswordField",onChange:s=>{M(s.target.value.trim())},appendIcon:d?"eye-slash":"eye",onAppendIconClick:()=>{k(!d)}}),e.jsx("div",{className:"mt-4 w-full",id:"passwordStrength",children:e.jsx(Ne,{requiredPasswordLength:8,inputLabel:"Enter new password",onChange:s=>{F(s.target.value.trim())}})}),e.jsx("div",{children:e.jsx(j.Warning,{children:"Please note that changing your password will log you out of all active sessions."})}),B(E),e.jsxs(ue.ButtonsPanel,{children:[e.jsx(u.Cancel,{title:"Cancel",onClick:()=>{c(null),y(!1)},isDisabled:v}),e.jsx(u.Primary,{isDisabled:v,isLoading:v,title:"Change password",loadingTitle:"Resetting",onClick:()=>{i!=null&&i.two_factor_auth_enabled?o(!0):g()}})]})]}),A&&e.jsx(Ae,{onHide:()=>b(!1),onSuccess:()=>{const s=ee(i);s&&(s.two_factor_auth_enabled=!0,t.set("logged_in_user",s),t.emitter.emit("showToast",{text:"2FA set up successfully",variant:"success",autoHide:3e3}),b(!1))},on2FADisabled:()=>{const s=ee(i);s&&(s.two_factor_auth_enabled=!1,t.set("logged_in_user",s),b(!1))}})]})}function J(){return i&&e.jsxs(x,{heading:{title:"User sessions",icon:"id-badge",iconColor:"blue",rightContent:e.jsx("div",{children:e.jsx(u.Danger,{title:"Log me out everywhere",onClick:D,isLoading:G})})},children:[I&&B(I),e.jsx(Te,{username:i.username})]})}function fe(){return i?e.jsxs(e.Fragment,{children:[e.jsx(je,{icon:"user",children:"Preferences"}),B(w),e.jsx(De,{user:i,userUpdated:s=>{t.set("logged_in_user",s)}}),m&&e.jsxs(x,{heading:{title:"Account",icon:"star",iconColor:"pink"},children:[e.jsx(_,{label:"Account name",value:e.jsx(u.Link,{hasNoPadding:!0,to:"/account",title:m.name})}),e.jsx(_,{label:"Account code",value:e.jsx(u.Link,{hasNoPadding:!0,to:"/account",title:m.account_code})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 items-stretch mt-3 mb-2",children:[e.jsxs(x,{hasNoVerticalMargin:!0,heading:{title:"Password",icon:"lock",iconColor:"blue"},children:[e.jsx(j.Instruction,{hasNoTopPadding:!0,children:"Ensure your password is strong and unique to protect your account."}),e.jsx(u.Link,{hasNoPadding:!0,title:"Change password",onClick:()=>{c(null),y(!0)}})]}),Pe(i,"API_/users/2fa/setup:POST")&&e.jsxs(x,{hasNoVerticalMargin:!0,heading:{title:"Two-factor authentication (2FA) via authenticator app",icon:"shield-
1heart",iconColor:"blue"},children:[e.jsx(j.Instruction,{hasNoTopPadding:!0,children:"Two-factor authentication adds an additional layer of security to your account by requiring more than just a password to log in. Once enabled, you will need to enter a 6 digit code generated by an authenticator app of your choice."}),i.two_factor_auth_enabled&&e.jsxs("div",{className:"flex items-center space-x-2 text-green font-bold my-4",children:[e.jsx(ge,{icon:"check-circle",color:"green"})," ",e.jsx("div",{children:"2FA is enabled"})]}),i.two_factor_auth_enabled?e.jsx(Ie,{title:"Are you sure?",body:e.jsxs("div",{children:["Are you sure you want to remove 2FA? It is recommended to keep it enabled for better security. ",e.jsx("br",{}),e.jsx("br",{}),"You can always enable it again later."]}),shouldShowCancelButton:!0,confirmText:"Yes, remove",onConfirm:()=>{X()},children:e.jsx(u.Link,{color:"red",title:"Remove 2FA",hasNoPadding:!0,isLoading:V})}):e.jsx(u.Link,{hasNoPadding:!0,isLoading:V,onClick:()=>{b(!0)},title:"Enable 2FA"}),B(w)]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 items-stretch mt-3 mb-2",children:[e.jsxs(x,{hasNoVerticalMargin:!0,heading:{title:"Dark mode",icon:"moon",iconColor:"pink"},children:[e.jsx(j.Instruction,{hasNoTopPadding:!0,children:"Enable dark mode to reduce eye strain in low-light environments. This setting will apply across all your sessions."}),e.jsx(Q,{isChecked:O,label:"Enable dark mode",onChange:s=>{R(s)}})]}),e.jsxs(x,{hasNoVerticalMargin:!0,heading:{title:"Remember my filters",icon:"filter",iconColor:"blue"},children:[e.jsx(j.Instruction,{hasNoTopPadding:!0,children:"Keep the filters you apply on a page so they are still there when you return to it. This setting applies across all your sessions."}),e.jsx(Q,{isChecked:$,label:"Remember my filters",info:"When enabled, the filters you apply are remembered across pages and reloads. When disabled, filters are reset to their defaults on every page.",onChange:s=>{l(s)}})]})]}),e.jsxs(x,{heading:{title:"Modal background blur",icon:"window-maximize",iconColor:"blue"},children:[e.jsx(j.Instruction,{hasNoTopPadding:!0,children:"Blur the page behind modals to help you focus. Turn this off to keep the page in focus behind a dark background so you can still see the context. This setting will apply across all your sessions."}),e.jsx(Q,{isChecked:Y,label:"Enable background blur",onChange:s=>{Z(s)}})]}),J(),p()]}):null}return fe()}const ms=me(Be);export{ms 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.