appointment.js
1 year ago
attendee.js
1 year ago
auth.js
1 year ago
bookableType.js
3 years ago
booking.js
1 year ago
cabinet.js
1 year ago
cabinetFilters.js
1 year ago
coupon.js
2 years ago
customFields.js
2 years ago
customerInfo.js
1 year ago
employee.js
1 year ago
entities.js
1 year ago
event.js
1 year ago
eventBooking.js
3 years ago
eventEntities.js
1 year ago
eventWaitingListOptions.js
1 year ago
pagination.js
3 years ago
params.js
1 year ago
payment.js
2 years ago
persons.js
1 year ago
recurring.js
1 year ago
shortcodeParams.js
2 years ago
tickets.js
1 year ago
customerInfo.js
296 lines
| 1 | import httpClient from "../../plugins/axios"; |
| 2 | |
| 3 | export default { |
| 4 | namespaced: true, |
| 5 | |
| 6 | state: () => ({ |
| 7 | id: null, |
| 8 | externalId: '', |
| 9 | firstName: '', |
| 10 | lastName: '', |
| 11 | email: '', |
| 12 | phone: '', |
| 13 | countryPhoneIso: '', |
| 14 | loggedUser: false, |
| 15 | translations: '', |
| 16 | gender: '', |
| 17 | birthday: '', |
| 18 | note: '', |
| 19 | loading: false, |
| 20 | customers: [], |
| 21 | customersIds: [], |
| 22 | wpUsers: [] |
| 23 | }), |
| 24 | |
| 25 | getters: { |
| 26 | getCustomerId (state) { |
| 27 | return state.id |
| 28 | }, |
| 29 | |
| 30 | getCustomerExternalId (state) { |
| 31 | return state.externalId |
| 32 | }, |
| 33 | |
| 34 | getCustomerFirstName (state) { |
| 35 | return state.firstName |
| 36 | }, |
| 37 | |
| 38 | getCustomerLastName (state) { |
| 39 | return state.lastName |
| 40 | }, |
| 41 | |
| 42 | getCustomerEmail (state) { |
| 43 | return state.email |
| 44 | }, |
| 45 | |
| 46 | getCustomerPhone (state) { |
| 47 | return state.phone |
| 48 | }, |
| 49 | |
| 50 | getCustomerCountryPhoneIso (state) { |
| 51 | return state.countryPhoneIso |
| 52 | }, |
| 53 | |
| 54 | getCustomerLanguage (state) { |
| 55 | return state.translations.defaultLanguage |
| 56 | }, |
| 57 | |
| 58 | getCustomerBirthday (state) { |
| 59 | return state.birthday |
| 60 | }, |
| 61 | |
| 62 | getCustomerGender (state) { |
| 63 | return state.gender |
| 64 | }, |
| 65 | |
| 66 | getCustomerNote (state) { |
| 67 | return state.note |
| 68 | }, |
| 69 | |
| 70 | getLoggedUser (state) { |
| 71 | return state.loggedUser |
| 72 | }, |
| 73 | |
| 74 | getAllData (state) { |
| 75 | return { |
| 76 | id: state.id, |
| 77 | externalId: state.externalId, |
| 78 | firstName: state.firstName, |
| 79 | lastName: state.lastName, |
| 80 | email: state.email, |
| 81 | phone: state.phone, |
| 82 | countryPhoneIso : state.countryPhoneIso, |
| 83 | loggedUser: state.loggedUser |
| 84 | } |
| 85 | }, |
| 86 | |
| 87 | getLoading (state) { |
| 88 | return state.loading |
| 89 | }, |
| 90 | |
| 91 | getCustomers (state) { |
| 92 | return state.customers |
| 93 | }, |
| 94 | |
| 95 | getCustomersIds (state) { |
| 96 | return state.customersIds |
| 97 | }, |
| 98 | |
| 99 | getWpUsers (state) { |
| 100 | return state.wpUsers |
| 101 | }, |
| 102 | |
| 103 | getCustomer (state) { |
| 104 | return { |
| 105 | id: state.id, |
| 106 | externalId: state.externalId, |
| 107 | firstName: state.firstName, |
| 108 | lastName: state.lastName, |
| 109 | email: state.email, |
| 110 | phone: state.phone, |
| 111 | countryPhoneIso: state.countryPhoneIso, |
| 112 | translations: state.translations, |
| 113 | gender: state.gender, |
| 114 | birthday: state.birthday, |
| 115 | note: state.note, |
| 116 | } |
| 117 | } |
| 118 | }, |
| 119 | |
| 120 | mutations: { |
| 121 | setCustomerId (state, payload) { |
| 122 | state.id = payload |
| 123 | }, |
| 124 | |
| 125 | setCustomerExternalId (state, payload) { |
| 126 | state.externalId = payload |
| 127 | }, |
| 128 | |
| 129 | setCustomerFirstName (state, payload) { |
| 130 | state.firstName = payload |
| 131 | }, |
| 132 | |
| 133 | setCustomerLastName (state, payload) { |
| 134 | state.lastName = payload |
| 135 | }, |
| 136 | |
| 137 | setCustomerEmail (state, payload) { |
| 138 | state.email = payload |
| 139 | }, |
| 140 | |
| 141 | setCustomerPhone (state, payload) { |
| 142 | state.phone = payload |
| 143 | }, |
| 144 | |
| 145 | setCustomerCountryPhoneIso (state, payload) { |
| 146 | state.countryPhoneIso = payload |
| 147 | }, |
| 148 | |
| 149 | setCustomerBirthday (state, payload) { |
| 150 | state.birthday = payload |
| 151 | }, |
| 152 | |
| 153 | setCustomerLanguage (state, payload) { |
| 154 | state.translations.defaultLanguage = payload |
| 155 | }, |
| 156 | |
| 157 | setCustomerGender (state, payload) { |
| 158 | state.gender = payload |
| 159 | }, |
| 160 | |
| 161 | setCustomerNote (state, payload) { |
| 162 | state.note = payload |
| 163 | }, |
| 164 | |
| 165 | setLoggedUser (state, payload) { |
| 166 | state.loggedUser = payload |
| 167 | }, |
| 168 | |
| 169 | setCurrentUser (state, payload) { |
| 170 | state.id = payload.id |
| 171 | state.externalid = payload.externalid |
| 172 | state.firstName = payload.firstName |
| 173 | state.lastName = payload.lastName |
| 174 | state.email = payload.email |
| 175 | state.phone = payload.phone || '' |
| 176 | state.countryPhoneIso = payload.countryPhoneIso || '' |
| 177 | }, |
| 178 | |
| 179 | setAllData (state, payload) { |
| 180 | state.id = payload.id |
| 181 | state.externalId = payload.externalId |
| 182 | state.firstName = payload.firstName |
| 183 | state.lastName = payload.lastName |
| 184 | state.email = payload.email |
| 185 | state.phone = payload.phone |
| 186 | state.countryPhoneIso = payload.countryPhoneIso |
| 187 | state.loggedUser = payload.loggedUser |
| 188 | }, |
| 189 | |
| 190 | setCustomer (state, payload) { |
| 191 | state.id = payload.id |
| 192 | state.externalId = payload.externalId |
| 193 | state.firstName = payload.firstName |
| 194 | state.lastName = payload.lastName |
| 195 | state.email = payload.email |
| 196 | state.phone = payload.phone |
| 197 | state.countryPhoneIso = payload.countryPhoneIso |
| 198 | state.translations = payload.translations |
| 199 | state.gender = payload.gender |
| 200 | state.birthday = payload.birthday |
| 201 | state.note = payload.note |
| 202 | }, |
| 203 | |
| 204 | setLoading (state, payload) { |
| 205 | state.loading = payload |
| 206 | }, |
| 207 | |
| 208 | setCustomers (state, payload) { |
| 209 | state.customers = payload |
| 210 | }, |
| 211 | |
| 212 | setCustomersIds (state, payload) { |
| 213 | state.customersIds = payload |
| 214 | }, |
| 215 | |
| 216 | setWpUsers (state, payload) { |
| 217 | state.wpUsers = payload |
| 218 | } |
| 219 | }, |
| 220 | |
| 221 | actions: { |
| 222 | requestCurrentUserData ({ commit }) { |
| 223 | commit('setLoading', true, {root: true}) |
| 224 | if (!('ameliaUser' in window) || !window.ameliaUser) { |
| 225 | httpClient.get( |
| 226 | '/users/current' |
| 227 | ).then((response) => { |
| 228 | if (response.data.data.user) { |
| 229 | window.ameliaUser = response.data.data.user ? response.data.data.user : null |
| 230 | |
| 231 | commit('setCurrentUser', window.ameliaUser) |
| 232 | commit('setLoggedUser', true) |
| 233 | } |
| 234 | commit('setLoading', false, {root: true}) |
| 235 | }).catch(() => { |
| 236 | commit('setLoading', false, {root: true}) |
| 237 | }) |
| 238 | } else { |
| 239 | let ameliaApiInterval = setInterval( |
| 240 | () => { |
| 241 | if ('ameliaUser' in window) { |
| 242 | clearInterval(ameliaApiInterval) |
| 243 | |
| 244 | commit('setCurrentUser', window.ameliaUser) |
| 245 | commit('setLoggedUser', true) |
| 246 | } |
| 247 | commit('setLoading', false, {root: true}) |
| 248 | }, |
| 249 | 1000 |
| 250 | ) |
| 251 | } |
| 252 | }, |
| 253 | |
| 254 | requestWpUsers ({ commit, getters }, payload) { |
| 255 | let { label } = payload |
| 256 | commit('setLoading', true) |
| 257 | httpClient.get( |
| 258 | 'users/wp-users', |
| 259 | { |
| 260 | params: { |
| 261 | id: getters['getCustomerId'], |
| 262 | role: 'customer' |
| 263 | } |
| 264 | } |
| 265 | ).then((response) => { |
| 266 | commit('setWpUsers', [{value: 0, label: label}, ...response.data.data.users]) |
| 267 | |
| 268 | if (getters['getWpUsers'].map(user => user.value).indexOf(getters['getCustomerExternalId']) === -1) { |
| 269 | commit('setCustomerExternalId', null) |
| 270 | } |
| 271 | |
| 272 | commit('setLoading', false) |
| 273 | }).catch(() => { |
| 274 | commit('setLoading', false) |
| 275 | }).finally(() => { |
| 276 | commit('setLoading', false) |
| 277 | }) |
| 278 | }, |
| 279 | |
| 280 | resetCustomer({commit}) { |
| 281 | commit('setCustomer', { |
| 282 | id: null, |
| 283 | externalId: '', |
| 284 | firstName: '', |
| 285 | lastName: '', |
| 286 | email: '', |
| 287 | phone: '', |
| 288 | countryPhoneIso: '', |
| 289 | translations: {defaultLanguage: ''}, |
| 290 | gender: '', |
| 291 | birthday: '', |
| 292 | note: '', |
| 293 | }) |
| 294 | } |
| 295 | } |
| 296 | } |