PageSourceSearch

https://iconaapp.com/assets/add-address-dialog-CjZNdIWJ.js

js iconaapp.com collected 2026-10-06 15:24:52 UTC 8,470 bytes, 1 lines download raw bytes

1import{i as Q,a as V,r as l,a9 as X,aa as ee,ab as se,ac as te,ae as H,af as ae,j as e,I as y,ad as _,B as J,M as W}from"./index-WHULU0jW.js";import{D as de,a as le,b as ie,c as ne,d as oe,e as re}from"./dialog-DjXxw1NJ.js";import{L as u}from"./label-Cp0G8FgB.js";function pe({open:A,onOpenChange:P,onSuccess:L,address:t}){const{toast:T}=Q(),{user:r}=V(),n=r,[k,U]=l.useState(!1),p=!!t,[z,C]=l.useState(""),[B,b]=l.useState(""),[d,v]=l.useState(null),[i,h]=l.useState(null),[x,c]=l.useState(null),[q,m]=l.useState(""),N=X(d==null?void 0:d.isoCode),$=ee(),R=se(d==null?void 0:d.isoCode),Y=te(d==null?void 0:d.isoCode,i==null?void 0:i.isoCode),D=Y.length>0,[F,Z]=l.useState({open:!1,title:"",message:""}),[I,j]=l.useState(""),[E,S]=l.useState(""),[G,O]=l.useState("");l.useEffect(()=>{if(A)if(t){O(t.name||""),C(t.addrress1||t.address1||""),b(t.addrress2||t.address2||""),j(t.zipcode||t.zip||""),S(t.phone||"");const s=H(t.countryCode||t.country);if(s){v({name:s.name,isoCode:s.isoCode});const a=ae(s.isoCode,t.stateCode||t.state);a?h({name:a.name,isoCode:a.isoCode}):t.state&&h({name:t.state,isoCode:""}),t.city&&(c({name:t.city}),m(t.city))}}else{O(""),C(""),b("");const s=H((r==null?void 0:r.countryCode)||(r==null?void 0:r.country));v(s?{name:s.name,isoCode:s.isoCode}:null),h(null),c(null),m(""),j(""),S("")}},[t,A,r]);const K=async()=>{const s=(x==null?void 0:x.name)||q.trim();if(!z||!d||!i||!s||!I||!E){T({title:"Missing Information",description:"Please fill in all required fields.",variant:"destructive"});return}U(!0);try{const a={name:G||(n==null?void 0:n.firstName)||"Default",addrress1:z,addrress2:B,country:d.name,city:s,countryCode:d.isoCode,zipcode:I,state:i.name,stateCode:i.isoCode,userId:n==null?void 0:n.id,phone:E.trim().replace(/\s/g,""),email:(n==null?void 0:n.email)||"",primary:(t==null?void 0:t.primary)||!1,applying:!1};p&&t._id?(await W("PUT",`/api/address/${t._id}`,a),T({title:"Address Updated",description:"Your shipping address has been updated successfully."})):(await W("POST","/api/address",a),T({title:"Address Added",description:"Your shipping address has been saved successfully."})),C(""),b(""),v(null),h(null),c(null),m(""),j(""),S(""),O(""),L&&L(),P(!1)}catch(a){console.error("Failed to add/update address:",a);let g=p?"Failed to update address. Please try again.":"Failed to add address. Please try again.",w="Error",f="";if(a!=null&&a.text)try{const M=JSON.parse(a.text);f=M.error||M.message||""}catch{typeof a.text=="string"&&(f=a.text)}else a!=null&&a.message&&(f=a.message);const o=f.toLowerCase();o.includes("missing_secondary")||o.includes("missing secondary")||o.includes("apartment, suite")?(w="Apartment or unit number needed",g="This building has multiple flats or units. Please add your flat, apartment or suite number in the Street Address 2 field."):o.includes("address_not_found")||o.includes("not found in the database")||o.includes("invalid address")?(w="Address not found",g="We couldn't find this address. Please check the street, city and postcode and try again."):o.includes("postal_code")||o.includes("zip")||o.includes("postcode")?(w="Check your postcode",g="The postcode doesn't match the city or state. Please double-check it."):f&&(g=f),Z({open:!0,title:w,message:g})}finally{U(!1)}};return e.jsx(de,{open:A,onOpenChange:P,children:e.jsxs(le,{className:"p-0 gap-0 flex flex-col overflow-hidden w-screen h-[100dvh] max-w-none max-h-none rounded-none border-0 translate-x-0 translate-y-0 left-0 top-0 shadow-none max-sm:!duration-150 max-sm:[--tw-enter-translate-x:0px] max-sm:[--tw-enter-translate-y:0px] max-sm:[--tw-enter-scale:1] max-sm:[--tw-exit-translate-x:0px] max-sm:[--tw-exit-translate-y:0px] max-sm:[--tw-exit-scale:1] sm:left-[50%] sm:top-[50%] sm:translate-x-[-50%] sm:translate-y-[-50%] sm:w-full sm:max-w-lg sm:h-auto sm:max-h-[90vh] sm:rounded-lg sm:border sm:shadow-lg","data-testid":"dialog-add-address",children:[e.jsxs(ie,{className:"shrink-0 px-4 sm:px-6 pt-4 sm:pt-6 pb-3 border-b sm:border-b-0 bg-background z-10",children:[e.jsx(ne,{className:"text-lg",children:p?"Edit Address":"Add New Address"}),e.jsx(oe,{children:p?"Update your shipping address.":"Add a new shipping or billing address."})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain px-4 sm:px-6",children:[F.open&&e.jsx("div",{role:"alert",className:"mt-3 rounded-md border border-destructive bg-destructive/10 p-3 text-sm","data-testid":"banner-address-error",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-destructive",children:F.title}),e.jsx("p",{className:"mt-1 text-destructive/90",children:F.message})]}),e.jsx("button",{type:"button",onClick:()=>Z(s=>({...s,open:!1})),className:"text-destructive/70 hover:text-destructive","aria-label":"Dismiss","data-testid":"button-dismiss-error",children:"✕"})]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"street-address",className:"text-sm font-medium",children:"Street Address"}),e.jsx(y,{id:"street-address",placeholder:N.street,value:z,onChange:s=>C(s.target.value),"data-testid":"input-street-address",autoComplete:"address-line1",className:"h-12 text-base sm:h-10 sm:text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"street-address-2",className:"text-sm font-medium",children:"Street Address 2 (Optional)"}),e.jsx(y,{id:"street-address-2",placeholder:N.street2,value:B,onChange:s=>b(s.target.value),"data-testid":"input-street-address-2",autoComplete:"address-line2",className:"h-12 text-base sm:h-10 sm:text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-sm font-medium",children:"Country"}),e.jsx(_,{options:$,value:(d==null?void 0:d.isoCode)||"",onChange:s=>{v((s==null?void 0:s.meta)||null),h(null),c(null),m("")},placeholder:"Select country",searchPlaceholder:"Search country...",emptyText:"No country found",testId:"select-country"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-sm font-medium",children:"State/Province"}),e.jsx(_,{options:R,value:(i==null?void 0:i.isoCode)||"",onChange:s=>
1{h((s==null?void 0:s.meta)||null),c(null),m("")},placeholder:d?"Select state":"Select country first",searchPlaceholder:"Search state...",emptyText:"No state found",disabled:!d||R.length===0,testId:"select-state"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-sm font-medium",children:"City"}),D?e.jsx(_,{options:Y,value:(x==null?void 0:x.name)||"",onChange:s=>{c((s==null?void 0:s.meta)||null),m("")},placeholder:i?"Select city":"Select state first",searchPlaceholder:"Search city...",emptyText:"No city found",disabled:!i,testId:"select-city"}):e.jsx(y,{id:"city-free-text",placeholder:"Enter your city",value:q,onChange:s=>{m(s.target.value),c(null)},"data-testid":"input-city",autoComplete:"address-level2",className:"h-12 text-base sm:h-10 sm:text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"zip",className:"text-sm font-medium",children:"ZIP/Postal Code"}),e.jsx(y,{id:"zip",placeholder:N.zip,value:I,onChange:s=>j(s.target.value),"data-testid":"input-zip",inputMode:"text",autoComplete:"postal-code",className:"h-12 text-base sm:h-10 sm:text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"phone",className:"text-sm font-medium",children:"Phone Number"}),e.jsx(y,{id:"phone",type:"tel",placeholder:N.phone,value:E,onChange:s=>S(s.target.value),"data-testid":"input-phone",inputMode:"tel",autoComplete:"tel",className:"h-12 text-base sm:h-10 sm:text-sm"})]})]})]})]}),e.jsxs(re,{className:"shrink-0 flex-col-reverse sm:flex-row gap-2 px-4 sm:px-6 py-3 border-t bg-background",style:{paddingBottom:"max(0.75rem, env(safe-area-inset-bottom))"},children:[e.jsx(J,{variant:"outline",onClick:()=>P(!1),disabled:k,"data-testid":"button-cancel",className:"w-full sm:w-auto h-12 sm:h-10 text-base sm:text-sm",children:"Cancel"}),e.jsx(J,{onClick:K,disabled:k,"data-testid":"button-add-address",className:"w-full sm:w-auto h-12 sm:h-10 text-base sm:text-sm bg-primary hover:bg-primary/90 text-primary-foreground",children:k?p?"Updating...":"Adding...":p?"Update Address":"Add Address"})]})]})})}export{pe as AddAddressDialog,pe 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.