1import { Controller } from "@hotwired/stimulus" 2 3export default class extends Controller { 4 static targets = [ 'mainElement', 'appointmentFormSubmitButton', 'appointmentForm' ]; 5 static values = { 6 linkPath: String, 7 linkOrigin: String, 8 requestOrigin: { type: String, default: 'proposal' }, 9 meetingData: { type: Object, default: {} } 10 } 11 12 connect() { 13 this.initiateCalComClient() 14 this.initCalComWidget() 15 this.trackCalComWidgetBookingSuccessfulEvent() 16 // this.trackCalComWidgetBookingSuccessfulV2Event() 17 } 18 19 initiateCalComClient = () => { 20 const origin = this.linkOriginValue.includes('.com') ? "https://app.cal.com" : "https://app.cal.eu" 21 Cal("init", { origin: origin }); 22 } 23 24 initCalComWidget = () => { 25 let meetingData = this.meetingDataValue 26 27 Cal("inline", { 28 elementOrSelector: this.mainElementTarget, // You can also provide an element directly 29 calLink: this.linkPathValue, // The link that you want to embed. It would open https://cal.com/jane in embed 30 config: { 31 name: meetingData.name, // Prefill Name 32 email: meetingData.email, // Prefill Email 33 } 34 }); 35 } 36 37 trackCalComWidgetBookingSuccessfulEvent = () => {
38 let controller = this; 39 Cal("on", { 40 action: "bookingSuccessful", 41 callback: (e)=>{ 42 const {data, type, namespace} = e.detail; 43 console.log(e.detail); 44 document.getElementById('raw_meeting_data').value = JSON.stringify(data) 45 46 if (this.requestOriginValue !== 'proposal') { 47 this.appointmentFormTarget.requestSubmit() 48 } else { 49 controller.showRedirectLink(); 50 } 51 } 52 }) 53 } 54 55 showRedirectLink = () => { 56 let controller = this; 57 controller.appointmentFormSubmitButtonTarget.classList.remove('hidden!') 58 setTimeout(function() { 59 controller.appointmentFormSubmitButtonTarget.click(); 60 }, 60000); 61 } 62}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.