PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / public / ivy.js
ameliabooking / v3 / src / assets / js / public Last commit date
actions.js 5 days ago booking.js 5 days ago cabinet.js 5 days ago cart.js 5 days ago catalog.js 5 days ago coupon.js 5 days ago customFields.js 5 days ago events.js 5 days ago facebookPixel.js 5 days ago ivy.js 5 days ago package.js 5 days ago panel.js 5 days ago public.js 5 days ago renderActions.js 5 days ago restore.js 5 days ago slots.js 5 days ago translation.js 5 days ago user.js 5 days ago
ivy.js
98 lines
1 import { parsePhoneNumberFromString } from 'libphonenumber-js'
2 import { settings } from '../../../plugins/settings'
3
4 function getCountryIsoMutation(store) {
5 return store.getters['booking/getBookableType'] === 'event'
6 ? 'customerInfo/setCustomerCountryPhoneIso'
7 : 'booking/setCustomerCountryPhoneIso'
8 }
9
10 function applyIvyPhoneValue(store, infoFormData, rawPhone) {
11 const value = rawPhone == null ? '' : String(rawPhone).trim()
12
13 if (!value) {
14 return false
15 }
16
17 const countryIsoMutation = getCountryIsoMutation(store)
18 let parsed = parsePhoneNumberFromString(value)
19
20 if (!parsed?.isValid?.()) {
21 const defaultCountry = store.state.settings?.general?.phoneDefaultCountryCode
22
23 if (defaultCountry && defaultCountry !== 'auto') {
24 parsed = parsePhoneNumberFromString(value, defaultCountry.toUpperCase())
25 }
26 }
27
28 if (parsed) {
29 if (parsed.country) {
30 store.commit(countryIsoMutation, parsed.country.toLowerCase())
31 }
32
33 // MazInputPhoneNumber expects international format for v-model.
34 infoFormData.value.phone = parsed.formatInternational()
35 return true
36 }
37
38 infoFormData.value.phone = value
39 return true
40 }
41
42 function useIvyMapping(store, shortcodeData, infoFormData) {
43 const formId = shortcodeData.value?.ivy?.formId
44 const ivyValues = shortcodeData.value?.ivy?.values
45 let phoneMapped = false
46
47 if (formId && settings?.ivy && formId in settings.ivy) {
48 const formMapping = settings.ivy[formId]
49
50 if (formMapping && ivyValues && typeof ivyValues === 'object') {
51 const keys = ['firstName', 'lastName', 'email', 'phone']
52
53 keys.forEach((key) => {
54 const fieldMapping = formMapping[key]
55
56 if (key in formMapping && fieldMapping) {
57 const formKey = fieldMapping.type + '_' + fieldMapping.index
58
59 if (!(formKey in ivyValues)) {
60 return
61 }
62
63 const ivyValue = ivyValues[formKey]
64 const currentValue = infoFormData.value[key]
65 const hasIvyValue = ivyValue != null && String(ivyValue).trim() !== ''
66 const shouldMap = hasIvyValue && (key === 'phone' || !currentValue)
67
68 if (!shouldMap) {
69 return
70 }
71
72 if (fieldMapping.type === 'name') {
73 const nameFieldKey = fieldMapping.key
74 const nameValues = ivyValues[formKey]
75
76 if (
77 nameFieldKey &&
78 nameValues &&
79 typeof nameValues === 'object' &&
80 nameFieldKey in nameValues
81 ) {
82 infoFormData.value[key] = nameValues[nameFieldKey]
83 }
84 } else if (key === 'phone') {
85 phoneMapped = applyIvyPhoneValue(store, infoFormData, ivyValue) || phoneMapped
86 } else {
87 infoFormData.value[key] = ivyValue
88 }
89 }
90 })
91 }
92 }
93
94 return phoneMapped
95 }
96
97 export { useIvyMapping }
98