1"use strict";(globalThis.__LOADABLE_LOADED_CHUNKS__=globalThis.__LOADABLE_LOADED_CHUNKS__||[]).push([[9463],{93205(e,s,t){t.r(s),t.d(s,{default:()=>m});var d=t(22224),a=t.n(d),r=t(41594),i=t(98483),l=t(33872),n=(t(16040),t(39054)),o=t(78771),p=t(39913),u=t(53787),h=t(22078),_=t(28027),c=t(29225),g=t(63988);class A extends r.Component{constructor(e){super(e),this.state={address_country:"United States",address_state:"",invalid_address:!1,suggestion:e.suggestion,errors:null},a().bindAll(this,["onFormRef","handleFieldChange","onAddAddress","onEditAddress","ignore"])}componentDidMount(){const{edit_address:e}=this.props;e&&this.setState({...e})}onFormRef(e){this._form=e}handleFieldChange(e,s){this.setState({[s]:e,suggestion:{...this.state.suggestion,[s]:null},errors:{...this.state.errors,[s]:null}})}onAddAddress(e,s){a().every(s,e=>null===e)&&(this.props.address_type&&(e.address_type=this.props.address_type),this.props.onAddAddress(e),this.props.shop_id&&this.props.shop_parent_type&&this.props.address_type&&this.props.onAddShopAddress(e))}onEditAddress(e,s){let t=!1;this.props.psEligible&&1==this.state.split_shipping&&(t=!0);let d=s;if(d.address_line_1=null,d.address_city=null,t)this.updateAddress(e);else{if(!a().every(d,e=>e!=e===null||a().isEmpty(e)))return;const s=this;-1!==["United States","United States of America","US","USA"].indexOf(e.address_country)?this.validateAddress(e.address_state,e.address_postal).then(t=>{let{json:d}=t;if(!0===d.result)s.updateAddress(e);else if(d.result.address_city&&d.result.address_state){let t=a().get(n.xP,this.state.address_country,[]).filter(s=>s.name.toLowerCase()===e.address_state.toLowerCase()||s.abbr.toLowerCase()===e.address_state.toLowerCase());s.setState({suggestion:{address_city:d.result.address_city,address_state:d.result.address_state},errors:{address_state:t.length&&d.result.address_state!==t[0].name||!t.length?{message:(0,g.jsx)("div",{children:(0,g.jsx)("span",{children:`State should be ${d.result.address_state}`})})}:null}},function(){this.state.errors.address_state||s.updateAddress(e)})}else s.setState({suggestion:{address_postal:d.result.address_postal},errors:{address_postal:{message:(0,g.jsx)("div",{children:(0,g.jsx)("span",{children:d.result.address_postal})})}}})}):this.updateAddress(e)}}validateAddress(e,s){return(0,h.oD)("POST","address",{action:"validate-address",address_state:e,address_postal:s})}updateAddress(e){const{onClosePopup:s,onCreateUpdateAddress:t,edit_address:d,onCreateFinalizeUpdateAddress:r}=this.props;a().forEach(e,function(e,s){e!==d[s]&&t(d.address_id,s,d[s],e)}),r(d.address_id,"split_shipping",0)(1),s()}ignore(e){const{onCreateFinalizeUpdateAddress:s,onClosePopup:t}=this.props;s(e,"split_shipping",0)(1),t()}render(){const{onClosePopup:e,index:s,edit_address:t,psEligible:d}=this.props,r=n.Xr.map(e=>({key:e,value:e})),i=a().get(n.xP,this.state.address_country,[]),o=[{key:"",value:"Canada"===this.state.address_country?"Select a Province...":"Select a State..."}].concat(i.map(e=>({key:e.abbr,value:e.name})));let p=(e,s,t)=>{if(this.state.suggestion&&this.state.suggestion[s.field]){let d=this.state.suggestion[s.field];if("address_city"===s.field&&this.state.suggestion[s.field]!==e&&"City is required"!==this.state.suggestion[s.field]&&(d="City should be "+d),"address_state"===s.field){let t=o.filter(s=>s.value.toLowerCase()===e.toLowerCase()||s.key.toLowerCase()===e.toLowerCase());if(t.length&&this.setState({address_state:t[0].key}),(!t.length||this.state.suggestion[s.field]===t[0].value)&&t.length)return{};d="State should be "+d}return{...t||{},message:(0,g.jsx)("div",{children:(0,g.jsx)("span",{children:d})})}}return t};return(0,g.jsxs)("div",{"data-test-name":"AddAddressPopup.render",id:"replace-header-modal",className:"reveal",style:{display:"block",zIndex:_.z+s},"aria-labelledby":"modalTitle","aria-hidden":"true",role:"dialog",children:[(0,g.jsx)("div",{className:"row",children:(0,g.jsxs)("div",{className:"small-12 columns",children:[(0,g.jsx)("h3",{id:"modalTitle",children:t&&d?"Verify Address":t?"Edit Address":"Add Address"}),(0,g.jsx)("a",{className:"alert button",style:{position:"fixed",right:"6rem",top:"1rem"},onClick:s=>{s.preventDefault(),t&&d?this.ignore(t.address_id):e()},children:t&&d?"Ignore":"Cancel"}),(0,g.jsx)("a",{className:"button",style:{position:"fixed",right:"1rem",top:"1rem"},onClick:e=>{e.preventDefault(),this._form&&this._form.submit()}
1,children:t?"Update":"Save"})]})}),(0,g.jsxs)(l.A,{className:"row popup-content form",ref:this.onFormRef,object:{parent_id:t?t.parent_id:this.props.address.parent_id,parent_type:t?t.parent_type:this.props.address.parent_type},onFieldChange:this.handleFieldChange,onSubmit:t?this.onEditAddress:this.onAddAddress,initialValidate:!(!t||!d),errors:this.state.errors,children:[t&&d?(0,g.jsx)("p",{style:{fontSize:"18px",fontStyle:"italic"},className:"row small-12 columns",children:"PromoStandards requires accurate shipping information"}):null,this.state.invalid_address?(0,g.jsx)("div",{className:"row",style:{backgroundColor:"#FFF3D9",padding:"10px",borderRadius:"10px",margin:"0 0 20px 15px",width:"90%"},children:"Invalid address... please check your address and save again"}):null,d?null:(0,g.jsx)(l.A.TextInput,{label:"Address Name",field:"address_name",value:this.state.address_name,required:!0}),(0,g.jsx)(l.A.TextInput,{label:"Company Name",field:"address_company",value:this.state.address_company,required:!0}),(0,g.jsx)(l.A.AddressAutocompleteInput,{label:"Street Address",field:"address_line_1",containerStyles:{marginBottom:"12px !important"},value:this.state.address_line_1,country:c.A.addressAutocompleteCountries,validate:p,required:!0,onChange:e=>{this.setState(e.parsed_address)},onInputChange:e=>{this.setState({address_line_1:e})}}),(0,g.jsx)(l.A.TextInput,{label:"Suite, Apt etc.",field:"address_line_2",value:this.state.address_line_2}),(0,g.jsx)(l.A.TextInput,{label:"Optional 1",field:"address_line_3",value:this.state.address_line_3}),(0,g.jsx)(l.A.TextInput,{label:"Optional 2",field:"address_line_4",value:this.state.address_line_4}),(0,g.jsx)(l.A.TextInput,{label:"City",field:"address_city",value:this.state.address_city,validate:p,required:!0}),(0,g.jsx)(l.A.Select,{label:"Country",field:"address_country",withMarginBottom:!0,options:r,value:this.state.address_country,onChange:e=>this.handleFieldChange("","address_state"),required:!0}),i.length?(0,g.jsx)(l.A.Select,{label:"State/Province",field:"address_state",withMarginBottom:!0,options:o,value:this.state.address_state,validate:p,required:!0}):(0,g.jsx)(l.A.TextInput,{label:"State/Province",field:"address_state",value:this.state.address_state,required:!0}),(0,g.jsx)(l.A.TextInput,{label:"Postal/Zip Code",field:"address_postal",value:this.state.address_postal,validate:p,required:!0})]})]})}}const m=(0,i.Ng)((e,s)=>({edit_address:s.address_id?e.entities.addresses[s.address_id]:null}),(e,s)=>({onAddShopAddress:t=>e((0,o.M1)({...t,parent_id:s.shop_id,parent_type:s.shop_parent_type,address_type:s.address_type})),onAddAddress:t=>e((0,o.M1)(t)).then(t=>{if(e((0,p.fs)()),s.order_id)return e((0,u.Gg)("shipping_address_id"===s.field?"shipping":"billing")(s.order_id,s.previous_value,t.payload.address.address_id))}),onClosePopup:s=>{e((0,p.fs)(s))},onCreateUpdateAddress:(s,t,d,a)=>{e((0,o.yY)(s,t,d,a))},onCreateFinalizeUpdateAddress:(s,t,d)=>a=>{e((0,o._X)(s,t,d,a))}}))(A)}}]); 2//# sourceMappingURL=components-AddAddressPopup.214e4ba3.chunk.js.map
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.