Last active
April 22, 2024 23:13
-
-
Save dougwithseismic/ebb5c5b0ecb77b342eab156667369fbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getCalApi } from "@calcom/embed-react" | |
import { useRef, useEffect } from "react" | |
const useCalDotCom = (namespace: string, link: string, config: object) => { | |
const calRef = useRef<any>(null) | |
useEffect(() => { | |
const initCal = async () => { | |
const cal = await getCalApi() | |
cal('ui', { | |
theme: 'dark', | |
styles: { branding: { brandColor: '#000000' } }, | |
hideEventTypeDetails: false, | |
layout: 'month_view' | |
}) | |
} | |
initCal() | |
}, []) | |
useEffect(() => { | |
if (calRef.current) { | |
calRef.current.setAttribute('data-cal-namespace', namespace) | |
calRef.current.setAttribute('data-cal-link', link) | |
calRef.current.setAttribute('data-cal-config', JSON.stringify(config)) | |
} | |
}, [namespace, link, config, calRef]) | |
return [calRef] | |
} | |
export default useCalDotCom | |
// Example usage | |
const CalendarButton = () => { | |
const [calRef] = useCalDotCom( | |
'', | |
'dougwithseismic/30min', | |
{ layout: 'month_view' } // Todo: Types because 2024. | |
) | |
return ( | |
<button ref={calRef} className="calendar-button"> | |
Book a Time | |
</button> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment