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
events.js
185 lines
| 1 | import httpClient from '../../../plugins/axios' |
| 2 | import { useUrlParams } from '../common/helper' |
| 3 | |
| 4 | function useEvents(params, callback) { |
| 5 | httpClient |
| 6 | .get('/events', { params: useUrlParams(Object.assign({ bookings: false }, params)) }) |
| 7 | .then((response) => { |
| 8 | callback(response.data.data.events) |
| 9 | }) |
| 10 | .catch(() => { |
| 11 | callback([]) |
| 12 | }) |
| 13 | } |
| 14 | |
| 15 | function useEventLocation(event, locations) { |
| 16 | let locationAddress = '' |
| 17 | |
| 18 | if (event.locationId && locations.find((l) => l.id === event.locationId)) { |
| 19 | let location = locations.filter((location) => location.id === event.locationId)[0] |
| 20 | locationAddress = location.address |
| 21 | |
| 22 | if (!locationAddress) { |
| 23 | locationAddress = location.name |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if (event.customLocation) { |
| 28 | locationAddress = event.customLocation |
| 29 | } |
| 30 | |
| 31 | return locationAddress |
| 32 | } |
| 33 | |
| 34 | function useMinTicketPrice(event) { |
| 35 | let priceArray = [] |
| 36 | |
| 37 | event.customTickets.forEach((ticket) => { |
| 38 | if (ticket.enabled) { |
| 39 | let tPrice = ticket.price |
| 40 | if (ticket.dateRangePrice != null) { |
| 41 | tPrice = ticket.dateRangePrice |
| 42 | } |
| 43 | priceArray.push(tPrice) |
| 44 | } |
| 45 | }) |
| 46 | |
| 47 | return Math.min(...priceArray) |
| 48 | } |
| 49 | |
| 50 | function useCheckIfEventNotFree(event) { |
| 51 | let priceArray = [] |
| 52 | |
| 53 | if (event.customPricing) { |
| 54 | event.customTickets.forEach((ticket) => { |
| 55 | if (ticket.enabled) { |
| 56 | let tPrice = ticket.price |
| 57 | if (ticket.dateRangePrice != null) { |
| 58 | tPrice = ticket.dateRangePrice |
| 59 | } |
| 60 | |
| 61 | if (tPrice > 0) { |
| 62 | priceArray.push(tPrice) |
| 63 | } |
| 64 | } |
| 65 | }) |
| 66 | |
| 67 | return priceArray.length > 0 |
| 68 | } |
| 69 | |
| 70 | return event.price > 0 |
| 71 | } |
| 72 | |
| 73 | // function getEventAvailability (evt, labels) { |
| 74 | // if (evt.status === 'approved' || evt.status === 'pending') { |
| 75 | // if (evt.full) { |
| 76 | // return { |
| 77 | // label: labels.full, |
| 78 | // class: 'full' |
| 79 | // } |
| 80 | // } |
| 81 | // if (evt.upcoming) { |
| 82 | // return { |
| 83 | // label: labels.upcoming, |
| 84 | // class: 'upcoming' |
| 85 | // } |
| 86 | // } |
| 87 | // return !evt.bookable ? { |
| 88 | // label: 'Closed', //amLabels.closed, |
| 89 | // class: 'closed' |
| 90 | // } : { |
| 91 | // label: labels.open, |
| 92 | // class: 'open' |
| 93 | // } |
| 94 | // } else { |
| 95 | // return { |
| 96 | // label: labels.canceled, |
| 97 | // class: 'canceled' |
| 98 | // } |
| 99 | // } |
| 100 | // } |
| 101 | |
| 102 | function showEventCapacity(status) { |
| 103 | switch (status) { |
| 104 | case 'open': |
| 105 | case 'upcoming': |
| 106 | return true |
| 107 | case 'canceled': |
| 108 | case 'closed': |
| 109 | case 'full': |
| 110 | return false |
| 111 | default: |
| 112 | return true |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | function useEventStatus(evt) { |
| 117 | if (evt.status === 'approved' || evt.status === 'pending') { |
| 118 | if (evt.full) return 'full' |
| 119 | if (evt.upcoming) return 'upcoming' |
| 120 | return !evt.bookable ? 'closed' : 'open' |
| 121 | } else { |
| 122 | return 'canceled' |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | function useWaitingListAvailability(evt) { |
| 127 | if (evt?.closed || !evt?.waitingList?.enabled) { |
| 128 | return false |
| 129 | } |
| 130 | |
| 131 | let capacityRule |
| 132 | let waitingAlreadyStarted = 0 |
| 133 | |
| 134 | if (evt.customPricing) { |
| 135 | let capacityRulePerTicket = [] |
| 136 | const peoplePerTicket = evt.customTickets.reduce((total, ticket) => { |
| 137 | if (!evt.maxCustomCapacity) { |
| 138 | capacityRulePerTicket.push(ticket.waitingListSpots > ticket.waiting) |
| 139 | } else { |
| 140 | total += ticket.waiting |
| 141 | } |
| 142 | return total + ticket.waiting |
| 143 | }, 0) |
| 144 | |
| 145 | if (!evt.maxCustomCapacity) { |
| 146 | capacityRule = capacityRulePerTicket.some((rule) => rule === true) |
| 147 | } else { |
| 148 | capacityRule = evt.waitingList.maxCapacity > evt.waitingList.peopleWaiting |
| 149 | } |
| 150 | |
| 151 | waitingAlreadyStarted = peoplePerTicket |
| 152 | } else { |
| 153 | capacityRule = evt.waitingList.maxCapacity > evt.waitingList.peopleWaiting |
| 154 | waitingAlreadyStarted = evt.waitingList.peopleWaiting |
| 155 | } |
| 156 | |
| 157 | return capacityRule && (evt.full || waitingAlreadyStarted !== 0) |
| 158 | } |
| 159 | |
| 160 | function useWaitingListOccupancy(evt) { |
| 161 | let spots = 0 |
| 162 | |
| 163 | if (evt.customPricing) { |
| 164 | evt.customTickets.forEach((ticket) => { |
| 165 | spots += ticket.waiting |
| 166 | }) |
| 167 | } else { |
| 168 | spots = evt.waitingList.peopleWaiting |
| 169 | } |
| 170 | |
| 171 | return spots |
| 172 | } |
| 173 | |
| 174 | export { |
| 175 | // getEventAvailability, |
| 176 | useEvents, |
| 177 | useEventLocation, |
| 178 | useMinTicketPrice, |
| 179 | showEventCapacity, |
| 180 | useEventStatus, |
| 181 | useCheckIfEventNotFree, |
| 182 | useWaitingListAvailability, |
| 183 | useWaitingListOccupancy, |
| 184 | } |
| 185 |