Skip to content

Commit

Permalink
Calendly widget component
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBroddin committed Sep 30, 2024
1 parent 4601cb8 commit 212134b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,21 @@ const CalendlyWidget: React.FC< CalendlyWidgetProps > = ( { url, id, prefill, on
}

const loadCalendly = async () => {
while ( typeof window.Calendly === 'undefined' ) {
while ( typeof window.Calendly === 'undefined' || ! url ) {
await new Promise( ( resolve ) => setTimeout( resolve, 100 ) );
}

// Clear out the container div when props change.
const element = document.getElementById( widgetId );
if ( element ) {
// Clear out the container div when props change.
element.innerHTML = '';
window.Calendly.initInlineWidget( {
url: `https://calendly.com/${ url }`,
parentElement: document.getElementById( widgetId ),
prefill: prefill || {},
utm: {},
} );
}

window.Calendly.initInlineWidget( {
url: `https://calendly.com/${ url }`,
parentElement: document.getElementById( widgetId ),
prefill: prefill || {},
utm: {},
} );
};

loadCalendly();
Expand All @@ -83,7 +82,7 @@ const CalendlyWidget: React.FC< CalendlyWidgetProps > = ( { url, id, prefill, on
};
}, [ url, widgetId, prefill ] );

return <div id={ widgetId } style={ { minWidth: '320px', height: '630px' } } />;
return <div id={ widgetId } className="calendly-widget" />;
};

export default CalendlyWidget;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.calendly-widget {
min-width: 320px;
height: 630px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ const HundredYearPlanScheduleAppointment: Step = function HundredYearPlanSchedul
<div className="hundred-year-plan-schedule-appointment-content__right-pane">
<CalendlyWidget
url={ CALENDLY_ID }
prefill={ { name: currentUser?.display_name, email: currentUser?.email } }
prefill={
currentUser
? { name: currentUser?.display_name, email: currentUser?.email }
: undefined
}
onSchedule={ () => {
submit?.();
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
width: 50%;
}

.calendly-inline-widget {
.calendly-widget {
min-width: 320px;
height: 700px;
}
Expand Down

0 comments on commit 212134b

Please sign in to comment.