Astor Ayestas
05/13/2022, 9:28 PMuseEffect(() => {
window.addEventListener("bookingSuccessful", handleBooking);
console.log("test");
// cleanup this component
_return_ () => {
window.removeEventListener("bookingSuccessful", handleBooking);
};
}, []);
Hariom Balhara
05/14/2022, 8:52 AMCal("on", {
action: "bookingSuccessful",
callback: (e)=>{
// `data` is properties for the event.
// `type` is the name of the action(You can also call it type of the action.) This would be same as "ANY_ACTION_NAME" except when ANY_ACTION_NAME="*" which listens to all the events.
// `namespace` tells you the Cal namespace for which the event is fired/
const {data, type, namespace} = e.detail;
}
})
Astor Ayestas
05/15/2022, 2:49 PMHariom Balhara
05/15/2022, 2:50 PMHariom Balhara
05/15/2022, 2:50 PMHariom Balhara
05/15/2022, 2:50 PMAstor Ayestas
05/15/2022, 3:04 PMimport Cal from "@calcom/embed-react";
I have Cal in two places, in the useffect:
useEffect(() => {
Cal("on", {
action: "bookingSuccessful",
callback: (e) => {
const { data, type, namespace } = e.detail;
},
});
return () => {};
}, []);
And in the return of the functional component.
<Cal
calLink="nbulla/15min"
calOrigin="<https://calendso-test.onrender.com>"
config={{
name: "Kunkg fu espinoza",
email: "<mailto:aayestas+ce@ingsw.com|aayestas+ce@ingsw.com>",
notes: "Test Meeting",
theme: "light",
}}
embedJsUrl={
"<https://calendso-test.onrender.com/embed/embed.js>"
}
/>
but give me the following error when I call it in the use effect.Hariom Balhara
05/15/2022, 3:05 PMHariom Balhara
05/15/2022, 3:06 PMHariom Balhara
05/15/2022, 3:06 PMAstor Ayestas
05/15/2022, 3:07 PMHariom Balhara
05/15/2022, 3:27 PMHariom Balhara
05/15/2022, 3:32 PMimport "./styles.css";
import {useEffect} from "react"
export default function App() {
const calConfig = {
theme: "dark"
};
useEffect(() => {
window.Cal("on", {
action: "*",
callback: (e) => {
console.log(e.detail);
},
});
return () => {};
}, []);
return (
<div className="App">
<button
data-cal-link="hariom"
data-cal-config={JSON.stringify(calConfig)}
>
I am an existing button on your website
</button>
<div>
<small>
You can either have Cal component imported on the page already for
this to work or you can install VanillaJS snippet on the page.
<div>
<i>
In this example we have included Vanilla JS snippet in React
Application
</i>
</div>
</small>
</div>
</div>
);
}
On mobile, looks like codesandbox isn't saving. So, if the link doesn't have the code. This is what I usedAstor Ayestas
05/15/2022, 3:34 PMHariom Balhara
05/15/2022, 3:34 PMAstor Ayestas
05/15/2022, 3:35 PMAstor Ayestas
05/15/2022, 3:35 PMAstor Ayestas
05/15/2022, 3:36 PMAstor Ayestas
05/15/2022, 3:37 PMsrc/types/index.d.ts
export {};
declare global {
interface Window {
Cal: any;
}
}
Hariom Balhara
05/15/2022, 3:40 PMHariom Balhara
05/15/2022, 3:42 PMAstor Ayestas
05/16/2022, 1:49 PMHariom Balhara
05/16/2022, 1:53 PMimport {globalCal} from "@calcom/embed-react"
and then do globalCal.on()
Need to look for a better name though calApi
is better than globalCal
Astor Ayestas
05/16/2022, 1:55 PMHariom Balhara
05/16/2022, 1:56 PMHariom Balhara
05/17/2022, 8:39 AMAstor Ayestas
05/19/2022, 4:36 PMAstor Ayestas
05/31/2022, 5:33 PM