PageSourceSearch

https://www.consumer.org.nz/assets/account-D-tigNUH.js

js consumer.org.nz collected 2026-10-02 03:14:46 UTC 10,286 bytes, 1 lines download raw bytes

1import{r as o,c as $,w as J}from"./chunk-OB3PAWPO-S5BgGmX4.js";import{j as e}from"./jsx-runtime-u17CrQMm.js";import{u as q,a as Y,U as g}from"./errors-DuRCaT6R.js";import{A as G}from"./acount-page-header-DHTIj6y4.js";import{P as H}from"./page-loading-CNx3Fvjw.js";import{M as m}from"./message-Dy5hj93O.js";import{c as U,a as x,b as K,F as B,R as j,o as L,d as W}from"./rhf-text-input-Dp49wBCX.js";import"./index-CUQnGpmN.js";import{A as X,R as Z}from"./rhf-address-finder-Dac4sJnB.js";import{R as z}from"./rhf-select-input-CgdoyQir.js";import{a as O}from"./navigation.client-rHt7fHwd.js";import{b as Q}from"./build-meta-tags-DxkD4IL1.js";import"./page-header-CX7QVKLR.js";import"./date-Dol-OOvp.js";import"./links-BdBdwYb-.js";import"./text-input-DVOI7SAQ.js";import"./input-error-C3RbP7_V.js";import"./select-input-D7GJk_7F.js";import"./index-Cq2Ke1RW.js";function ee(l){const{accountData:h}=l,[i,t]=o.useState(!1),[d,a]=o.useState(null),[u,n]=o.useState(null),w=q(),S=Y(),{display_name:c,first_name:_,last_name:r,contact_number:P,address:b,title:v}=h,C=["Mr","Mrs","Miss","Ms","Dr","Mr & Mrs"],R=C.map(s=>({label:s,value:s})),A=U({display_name:x().defined(),first_name:x().required("Please enter your first name"),last_name:x().required("Please enter your last name"),contact_number:x().defined().matches(/^$|^\d{7,20}$/,"Please enter a valid contact number"),address:X.nullable(),title:x().oneOf(["",...C],"Please select a title from the list").nullable().defined()}).required(),E=K({mode:"onBlur",reValidateMode:"onBlur",resolver:L(A),defaultValues:{display_name:c||"",first_name:_||"",last_name:r||"",contact_number:P||"",address:b||{},title:v}}),{handleSubmit:T,formState:k,reset:D}=E,{isDirty:F}=k;function f(s){t(!0),a(null),n(null),fetch("/api/members/account",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).then(async p=>{if(!p.ok){w(p,"updateAccount");const I=await p.json();a(I?.error||g),t(!1);return}const N=await p.json(),{success:M,account_data:y,errors:V}=N?.data||{};M&&y?(n("Profile updated successfully"),D({display_name:y.display_name,first_name:y.first_name,last_name:y.last_name,contact_number:y.contact_number,address:y.address||{},title:y.title})):(w(p,"updateAccount",N),a(V?.join(", ")||g)),t(!1)}).catch(p=>{S(p,s),a(g),t(!1)})}return e.jsxs("div",{className:"relative",children:[e.jsx("h2",{children:"Profile"}),e.jsx(m,{error:!0,message:d,wrapperClassName:"hidden tablet:block mb-2 -mt-2",dismissAction:()=>a(null)}),e.jsx(m,{success:!0,message:u,wrapperClassName:"hidden tablet:block mb-2 -mt-2",dismissAction:()=>n(null),timeout:7e3}),e.jsx(B,{...E,children:e.jsxs("form",{onSubmit:T(f),onChange:()=>{a(null),n(null)},children:[e.jsx(j,{label:"Display name",fieldKey:"display_name"}),e.jsxs("div",{className:"tablet:flex tablet:gap-4",children:[e.jsx("div",{className:"tablet:flex-1 tablet:max-w-[200px]",children:e.jsx(z,{label:"Title",fieldKey:"title",placeholder:"Select your title",options:R,clearable:!0,searchable:!0})}),e.jsx("div",{className:"tablet:flex-1",children:e.jsx(j,{label:"First name",fieldKey:"first_name",required:!0})}),e.jsx("div",{className:"tablet:flex-1",children:e.jsx(j,{label:"Last name",fieldKey:"last_name",required:!0})})]}),e.jsx(Z,{label:"Address",fieldKey:"address_finder",defaultAddress:b}),e.jsx(j,{label:"Phone",type:"tel",fieldKey:"contact_number"}),e.jsx("button",{type:"submit",className:"Button--red w-fit! min-w-0! ml-auto tablet:absolute tablet:right-0 tablet:top-0",disabled:i||!F,children:i?"Saving...":"Save"})]})}),e.jsx(m,{error:!0,message:d,wrapperClassName:"mt-4 tablet:hidden",dismissAction:()=>a(null)}),e.jsx(m,{success:!0,message:u,wrapperClassName:"mt-4 tablet:hidden",dismissAction:()=>n(null),timeout:7e3})]})}function se(l){const{accountData:h}=l,i=$(),[t,d]=o.useState(!1),[a,u]=o.useState(!1),[n,w]=o.useState(!1),[S,c]=o.useState(null),[_,r]=o.useState(null),[P,b]=o.useState(null),v=q(),{email:C}=h,R=U({email:x().email("Please enter a valid email address").required("Please enter your email address")}).required(),A=K({mode:"onBlur",reValidateMode:"onBlur",resolver:L(R),defaultValues:{email:C}}),{handleSubmit:E,formState:T}=A,{isDirty:k}=T;o.useEffect(()=>{if(!i)return;const s=new URLSearchParams(i.search).getAll("message");s.includes("invalid_email_confirmation_token_logged_in")?(b("Your request to change your email address has expired. Please update your details below to request a new confirmation email."),O({},["message"])):s.includes("email_confirmation_logged_in_success")?(r("Success! Your email address has been successfully updated."),O({},["message"])):s.includes("email_already_changed")&&(r("Your email address has already been changed."),O({},["message"]))},[i?.search]);function D(f){d(!0),c(null),r(null),fetch("/api/members/email-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)}).then(s=>{if(!s.ok)throw v(s,"email update"),new Error("Email update failed");return s.json()}).then(s=>{const{success:p,errors:N,message:M}=s?.data||{};if(p){console.log("Email update success message:",M),r(M);return}N&&N.length>0?c(N.join("<br />")):(c(g),v(s,"email update")),d(!1)}).catch(()=>{c(g),d(!1)})}function F(){u(!0),c(null),r(null),fetch("/api/members/email-preferences",{method:"POST",headers:{"Content-Type":"application/json"}}).then(f=>f.json().then(s=>({ok:f.ok,data:s}))).then(({ok:f,data:s})=>{if(console.log("Email preferences request response data",s),f&&!s.error){w(!0),u(!1);return}const p=s?.data?.message||s?.statusText||g;
1c(p),v(s,"email preferences request"),u(!1)}).catch(f=>{console.error("Error requesting email preferences:",f),c(g),u(!1)})}return e.jsxs("div",{className:"relative",children:[e.jsx("h2",{children:"Email"}),e.jsx(m,{error:!0,message:S,wrapperClassName:"hidden tablet:block mb-2 -mt-2",dismissAction:()=>c(null)}),e.jsx(m,{success:!0,message:_,wrapperClassName:"hidden tablet:block mb-2 -mt-2",dismissAction:()=>r(null),timeout:7e3}),e.jsx(B,{...A,children:e.jsxs("form",{onSubmit:E(D),onChange:()=>{c(null),r(null),b(null)},children:[e.jsxs("div",{className:"tablet:flex tablet:gap-6 items-center",children:[e.jsx("div",{className:"tablet:flex-1",children:e.jsx(j,{label:"Email",type:"email",fieldKey:"email",required:!0})}),e.jsx("div",{className:"mb-2 tablet:flex-1 tablet:pt-3.5",children:e.jsx("button",{type:"button",className:"a",disabled:t||a||n,onClick:F,children:a?"Sending request...":"Manage email preferences"})})]}),e.jsx("button",{type:"submit",className:"Button--red w-fit! min-w-0! ml-auto tablet:absolute tablet:right-0 tablet:top-0",disabled:t||a||!k,children:t?"Saving...":"Save"}),n&&e.jsx(m,{success:!0,message:"Please check your inbox for an email with a link to manage your preferences.",wrapperClassName:"mt-1",small:!0,timeout:7e3})]})}),e.jsx(m,{info:!0,message:P,wrapperClassName:"mt-1",dismissAction:()=>b(null),timeout:15e3}),e.jsx(m,{error:!0,message:S,wrapperClassName:"mt-4 tablet:hidden",dismissAction:()=>c(null)}),e.jsx(m,{success:!0,message:_,wrapperClassName:"mt-4 tablet:hidden",dismissAction:()=>r(null),timeout:7e3})]})}function te(){const[l,h]=o.useState(!1),[i,t]=o.useState(null),d=q(),a=U({current_password:x().required("Please enter your current password"),password:x().min(8,"Password must be at least 8 characters").required("Please enter a new password"),password_confirmation:x().oneOf([W("password")],"Passwords must match").required("Please confirm your new password")}).required(),u=K({mode:"onBlur",reValidateMode:"onBlur",resolver:L(a),defaultValues:{current_password:"",password:"",password_confirmation:""}}),{handleSubmit:n,watch:w}=u;function S(_){h(!0),t(null),fetch("/api/members/password-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)}).then(r=>{if(!r.ok)throw d(r,"password update"),new Error("Password update failed");return r.json()}).then(r=>{const{success:P,errors:b}=r?.data||{};if(P){window.location.href=`${window.location.pathname}?message=password_changed`;return}b&&b.length>0?t(b.join("<br />")):(t(g),d(r,"password update")),h(!1)}).catch(()=>{t(g),h(!1)})}const c=w("password")?.length>0;return e.jsxs("div",{className:"relative",children:[e.jsx("h2",{children:"Password"}),e.jsx(m,{error:!0,message:i,wrapperClassName:"hidden tablet:block mb-2 -mt-2",dismissAction:()=>t(null)}),e.jsx(B,{...u,children:e.jsxs("form",{onSubmit:n(S),onChange:()=>t(null),children:[e.jsx(j,{label:"Current password",type:"password",fieldKey:"current_password",required:!0,autoComplete:"current-password"}),e.jsx(j,{label:"New password",type:"password",fieldKey:"password",required:!0,autoComplete:"new-password"}),e.jsx("p",{className:"text-sm text-grey text-left -mt-3 mb-3",children:"Password must be a minimum of 8 characters long."}),e.jsx(j,{label:"Confirm new password",type:"password",fieldKey:"password_confirmation",required:!0,autoComplete:"new-password"}),e.jsx("button",{type:"submit",className:"Button--red w-fit! min-w-0! ml-auto tablet:absolute tablet:right-0 tablet:top-0",disabled:l||!c,children:l?"Saving...":"Save"})]})}),e.jsx(m,{error:!0,message:i,wrapperClassName:"mt-4 tablet:hidden",dismissAction:()=>t(null)})]})}function ae(){const[l,h]=o.useState(null),[i,t]=o.useState(!1),d=q();function a(){fetch("/api/members/account",{method:"GET",headers:{"Content-Type":"application/json"}}).then(n=>{if(!n.ok)throw d(n,"fetchAccountData"),new Error("Account data retrieval failed");return n.json()}).then(n=>{const{data:w}=n;h(w)}).catch(()=>{t(!0)})}o.useEffect(()=>{a()},[]);const u=!i&&!l;return e.jsxs("div",{children:[e.jsx(G,{currentPath:"/account"}),u&&e.jsx(H,{narrow:!0,blocks:!0}),!u&&e.jsxs("div",{className:"container-narrow min-h-[50vh] my-10",children:[i&&e.jsx(m,{error:!0,className:"w-fit m-auto text-center mb-2 relative",message:g,defaultOpen:!0}),!i&&l&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{accountData:l}),e.jsx("div",{className:"mb-16"}),e.jsx(se,{accountData:l}),e.jsx("div",{className:"mb-16"}),e.jsx(te,{}),e.jsx("div",{className:"mb-16"})]})]})]})}function _e({matches:l}){const t=l.find(a=>a&&a.id==="root")?.data?.datoData?.site?.globalSeo;return Q({title:"Account",description:"Manage your Consumer NZ account",noIndex:!0,globalSeo:t})}const Ne=J(function(){return e.jsx(ae,{})});
1export{Ne as default,_e as meta};

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.