Improve phone editing for new custorder

let user choose from existing phones, or add a new one.  not yet
implemented, they can check a box to add new phone to customer proper
in addition to setting it for the order
This commit is contained in:
Lance Edgar 2021-10-04 12:24:24 -04:00
parent 711e526822
commit 1884edb334
2 changed files with 70 additions and 17 deletions

View file

@ -164,12 +164,36 @@
</header> </header>
<section class="modal-card-body"> <section class="modal-card-body">
<b-field label="Phone Number"
:type="editPhoneNumberValue ? null : 'is-danger'"> <b-field v-for="phone in contactPhones"
<b-input v-model="editPhoneNumberValue" :key="phone.uuid">
ref="editPhoneNumberInput"> <b-radio v-model="existingPhoneUUID"
</b-input> :native-value="phone.uuid">
{{ phone.type }} {{ phone.number }}
<span v-if="phone.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field> </b-field>
<b-field>
<b-radio v-model="existingPhoneUUID"
:native-value="null">
other
</b-radio>
</b-field>
<b-field v-if="!existingPhoneUUID"
grouped>
<b-input v-model="otherPhoneNumber">
</b-input>
<b-checkbox v-model="addOtherPhoneNumber"
disabled>
add this phone number to customer record
</b-checkbox>
</b-field>
</section> </section>
<footer class="modal-card-foot"> <footer class="modal-card-foot">
@ -512,18 +536,20 @@
contactDisplay: ${json.dumps(six.text_type(batch.customer or ''))|n}, contactDisplay: ${json.dumps(six.text_type(batch.customer or ''))|n},
customerEntry: null, customerEntry: null,
contactProfileURL: ${json.dumps(contact_profile_url)|n}, contactProfileURL: ${json.dumps(contact_profile_url)|n},
## phoneNumberEntry: ${json.dumps(batch.phone_number)|n},
orderPhoneNumber: ${json.dumps(batch.phone_number)|n}, orderPhoneNumber: ${json.dumps(batch.phone_number)|n},
phoneNumberSaved: true, contactPhones: ${json.dumps(contact_phones)|n},
existingPhoneUUID: null,
otherPhoneNumber: null,
addOtherPhoneNumber: false,
editPhoneNumberShowDialog: false,
editPhoneNumberSaving: false,
customerName: null, customerName: null,
phoneNumber: null, phoneNumber: null,
orderEmailAddress: ${json.dumps(batch.email_address)|n}, orderEmailAddress: ${json.dumps(batch.email_address)|n},
contactNotes: ${json.dumps(contact_notes)|n}, contactNotes: ${json.dumps(contact_notes)|n},
editPhoneNumberShowDialog: false,
editPhoneNumberValue: null,
editPhoneNumberSaving: false,
editEmailAddressShowDialog: false, editEmailAddressShowDialog: false,
editEmailAddressValue: null, editEmailAddressValue: null,
editEmailAddressSaving: false, editEmailAddressSaving: false,
@ -607,6 +633,12 @@
text: "Please provide a phone number for the customer.", text: "Please provide a phone number for the customer.",
} }
} }
if (this.contactNotes.length) {
return {
type: 'is-warning',
text: "Please review notes below.",
}
}
phoneNumber = this.orderPhoneNumber phoneNumber = this.orderPhoneNumber
} else { // customer is not known } else { // customer is not known
if (!this.customerName) { if (!this.customerName) {
@ -649,7 +681,7 @@
if (this.editPhoneNumberSaving) { if (this.editPhoneNumberSaving) {
return true return true
} }
if (!this.editPhoneNumberValue) { if (!this.existingPhoneUUID && !this.otherPhoneNumber) {
return true return true
} }
return false return false
@ -830,11 +862,17 @@
}, },
editPhoneNumberInit() { editPhoneNumberInit() {
this.editPhoneNumberValue = this.orderPhoneNumber this.existingPhoneUUID = null
let normalOrderPhone = this.orderPhoneNumber.replace(/\D/g, '')
for (let phone of this.contactPhones) {
let normal = phone.number.replace(/\D/g, '')
if (normal == normalOrderPhone) {
this.existingPhoneUUID = phone.uuid
break
}
}
this.otherPhoneNumber = this.existingPhoneUUID ? this.orderPhoneNumber : null
this.editPhoneNumberShowDialog = true this.editPhoneNumberShowDialog = true
this.$nextTick(() => {
this.$refs.editPhoneNumberInput.focus()
})
}, },
editPhoneNumberSave() { editPhoneNumberSave() {
@ -842,7 +880,21 @@
let params = { let params = {
action: 'update_phone_number', action: 'update_phone_number',
phone_number: this.editPhoneNumberValue, phone_number: null,
}
if (this.existingPhoneUUID) {
for (let phone of this.contactPhones) {
if (phone.uuid == this.existingPhoneUUID) {
params.phone_number = phone.number
break
}
}
}
if (!params.phone_number) {
params.phone_number = this.otherPhoneNumber
// params.add_phone_number = this.addOtherPhoneNumber
} }
this.submitBatchData(params, response => { this.submitBatchData(params, response => {

View file

@ -255,6 +255,7 @@ class CustomerOrderView(MasterView):
context = {'batch': batch, context = {'batch': batch,
'normalized_batch': self.normalize_batch(batch), 'normalized_batch': self.normalize_batch(batch),
'new_order_requires_customer': self.handler.new_order_requires_customer(), 'new_order_requires_customer': self.handler.new_order_requires_customer(),
'contact_phones': self.handler.get_contact_phones(batch),
'contact_profile_url': None, 'contact_profile_url': None,
'contact_notes': self.handler.get_contact_notes(batch), 'contact_notes': self.handler.get_contact_notes(batch),
'order_items': items, 'order_items': items,