JezK
Edit File: sc-customer-edit.js.map
{"file":"sc-customer-edit.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,GAAG,+EAA+E,CAAC;AAC1G,6BAAe,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2PC0FyF,UAAE;;;;;;yOAShG,UAAE,wQAGd,UAAE,udASgB,UAAE,gRAGF,UAAE,oRAIE,UAAE,uZAKd,UAAE;;;;;;;;;;;;;;;8BA+BR,UAAE,+TAMI,UAAE;;;;;;;;;;ikBAuBV,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/controllers/dashboard/customer-edit/sc-customer-edit.scss?tag=sc-customer-edit&encapsulation=shadow","src/components/controllers/dashboard/customer-edit/sc-customer-edit.tsx"],"sourcesContent":[":host {\n display: block;\n position: relative;\n}\n\n.customer-edit {\n display: grid;\n gap: 0.75em;\n}\n","import { Component, Prop, h, State } from '@stencil/core';\nimport { __ } from '@wordpress/i18n';\nimport { Customer, Address } from '../../../../types';\nimport apiFetch from '../../../../functions/fetch';\nimport { addQueryArgs } from '@wordpress/url';\n\n@Component({\n tag: 'sc-customer-edit',\n styleUrl: 'sc-customer-edit.scss',\n shadow: true,\n})\nexport class ScCustomerEdit {\n @Prop() heading: string;\n @Prop({ mutable: true }) customer: Customer;\n @Prop() successUrl: string;\n\n @State() loading: boolean;\n @State() error: string;\n\n async handleSubmit(e) {\n this.loading = true;\n try {\n const {\n email,\n first_name,\n last_name,\n phone,\n billing_matches_shipping,\n shipping_name,\n shipping_city,\n 'tax_identifier.number_type': tax_identifier_number_type,\n 'tax_identifier.number': tax_identifier_number,\n shipping_country,\n shipping_line_1,\n shipping_line_2,\n shipping_postal_code,\n shipping_state,\n billing_name,\n billing_city,\n billing_country,\n billing_line_1,\n billing_line_2,\n billing_postal_code,\n billing_state,\n } = await e.target.getFormJson();\n this.customer.billing_address = {\n name: billing_name,\n city: billing_city,\n country: billing_country,\n line_1: billing_line_1,\n line_2: billing_line_2,\n postal_code: billing_postal_code,\n state: billing_state,\n };\n this.customer.shipping_address = {\n name: shipping_name,\n city: shipping_city,\n country: shipping_country,\n line_1: shipping_line_1,\n line_2: shipping_line_2,\n postal_code: shipping_postal_code,\n state: shipping_state,\n };\n\n await apiFetch({\n path: addQueryArgs(`surecart/v1/customers/${this.customer?.id}`, { expand: ['tax_identifier'] }),\n method: 'PATCH',\n data: {\n email,\n first_name,\n last_name,\n phone,\n billing_matches_shipping: billing_matches_shipping === true || billing_matches_shipping === 'on',\n shipping_address: this.customer.shipping_address,\n billing_address: this.customer.billing_address,\n ...(tax_identifier_number && tax_identifier_number_type\n ? {\n tax_identifier: {\n number: tax_identifier_number,\n number_type: tax_identifier_number_type,\n },\n }\n : {}),\n },\n });\n if (this.successUrl) {\n window.location.assign(this.successUrl);\n } else {\n this.loading = false;\n }\n } catch (e) {\n this.error = e?.additional_errors?.length ? e.additional_errors.map(err => err.message).join(', ') : e?.message || __('Something went wrong', 'surecart');\n this.loading = false;\n }\n }\n\n render() {\n return (\n <sc-dashboard-module class=\"customer-edit\" error={this.error}>\n <span slot=\"heading\">\n {this.heading || __('Update Billing Details', 'surecart')}{' '}\n {!this?.customer?.live_mode && (\n <sc-tag type=\"warning\" size=\"small\">\n {__('Test', 'surecart')}\n </sc-tag>\n )}\n </span>\n\n <sc-card>\n <sc-form onScFormSubmit={e => this.handleSubmit(e)}>\n <sc-columns style={{ '--sc-column-spacing': 'var(--sc-spacing-medium)' }}>\n <sc-column>\n <sc-input label={__('First Name', 'surecart')} name=\"first_name\" value={this.customer?.first_name} />\n </sc-column>\n <sc-column>\n <sc-input label={__('Last Name', 'surecart')} name=\"last_name\" value={this.customer?.last_name} />\n </sc-column>\n </sc-columns>\n <sc-column>\n <sc-phone-input label={__('Phone', 'surecart')} name=\"phone\" value={this.customer?.phone} />\n </sc-column>\n <sc-flex style={{ '--sc-flex-column-gap': 'var(--sc-spacing-medium)' }} flexDirection=\"column\">\n <div>\n <sc-address\n label={__('Shipping Address', 'surecart')}\n showName={true}\n address={{\n ...(this.customer?.shipping_address as Address),\n }}\n showLine2={true}\n required={false}\n names={{\n name: 'shipping_name',\n country: 'shipping_country',\n line_1: 'shipping_line_1',\n line_2: 'shipping_line_2',\n city: 'shipping_city',\n postal_code: 'shipping_postal_code',\n state: 'shipping_state',\n }}\n ></sc-address>\n </div>\n\n <div>\n <sc-checkbox\n name=\"billing_matches_shipping\"\n checked={this.customer?.billing_matches_shipping}\n onScChange={e => {\n this.customer = {\n ...this.customer,\n billing_matches_shipping: (e.target as HTMLScCheckboxElement).checked,\n };\n }}\n value=\"on\"\n >\n {__('Billing address is same as shipping', 'surecart')}\n </sc-checkbox>\n </div>\n\n <div style={{ display: this.customer?.billing_matches_shipping ? 'none' : 'block' }}>\n <sc-address\n label={__('Billing Address', 'surecart')}\n showName={true}\n address={{\n ...(this.customer?.billing_address as Address),\n }}\n showLine2={true}\n names={{\n name: 'billing_name',\n country: 'billing_country',\n line_1: 'billing_line_1',\n line_2: 'billing_line_2',\n city: 'billing_city',\n postal_code: 'billing_postal_code',\n state: 'billing_state',\n }}\n required={true}\n ></sc-address>\n </div>\n\n <sc-tax-id-input show number={this.customer?.tax_identifier?.number} type={this.customer?.tax_identifier?.number_type}></sc-tax-id-input>\n </sc-flex>\n <div>\n <sc-button type=\"primary\" full submit>\n {__('Save', 'surecart')}\n </sc-button>\n </div>\n </sc-form>\n </sc-card>\n {this.loading && <sc-block-ui spinner></sc-block-ui>}\n </sc-dashboard-module>\n );\n }\n}\n"],"version":3}