{"version":3,"file":"WebhookButton.DSV-WS3n.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/MENsU7osVqXO61PNRwoU/Zo536eHmU2feqHM5FN50/WebhookButton.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef,useState}from\"react\";// @ts-ignore\nimport{fetchUserData}from\"https://framer.com/m/ThentyHelpers-I0Oh.js\";// ─── Spinner keyframe (injected once) ────────────────────────────────────────\nconst SPINNER_KEYFRAME_ID=\"__wb_spinner_kf\";function ensureSpinnerKeyframe(){if(typeof document===\"undefined\")return;if(document.getElementById(SPINNER_KEYFRAME_ID))return;const style=document.createElement(\"style\");style.id=SPINNER_KEYFRAME_ID;style.textContent=`@keyframes __wb_spin { to { transform: rotate(360deg); } }`;document.head.appendChild(style);}// ─── Component ───────────────────────────────────────────────────────────────\nexport default function WebhookButton(props){const{webhookUrl,calendarId,eventId,notionReferenceField,verboseDebug,text,confirmationText,font,padding,paddingLeft,paddingRight,borderRadius,backgroundColor,textColor,hoverBackgroundColor,loadingBackgroundColor,loadingTextColor,confirmationBackgroundColor,confirmationTextColor,confirmationDuration,style}=props;const{userData,loggedIn}=fetchUserData();const[buttonState,setButtonState]=useState(\"idle\");const[hovered,setHovered]=useState(false);const confirmationTimer=useRef(null);useEffect(()=>{ensureSpinnerKeyframe();},[]);// Auto-revert from confirmation → idle\nuseEffect(()=>{if(buttonState===\"confirmation\"){confirmationTimer.current=setTimeout(()=>{setButtonState(\"idle\");},confirmationDuration*1e3);}return()=>{if(confirmationTimer.current)clearTimeout(confirmationTimer.current);};},[buttonState,confirmationDuration]);async function handleClick(){if(buttonState!==\"idle\")return;const payload={calendar_id:calendarId,event_id:eventId,notion_reference:notionReferenceField,attendee_email:loggedIn?userData?.email:null};if(verboseDebug){console.log(\"[WebhookButton] Request\",{url:webhookUrl,payload,thenty:{loggedIn,email:userData?.email}});}setButtonState(\"loading\");try{// mode: \"no-cors\" bypasses the CORS preflight that blocks browser→Zapier\n// requests. The response will be opaque (status 0, unreadable body), so\n// we treat any successful fetch() call as a confirmed delivery.\nconst response=await fetch(webhookUrl,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify(payload),mode:\"no-cors\"});if(verboseDebug){console.log(\"[WebhookButton] Response (no-cors — opaque)\",{type:response.type,status:response.status,note:\"Request delivered. Body/status unreadable due to no-cors mode.\"});}// An opaque response has status 0 — that's expected and means success.\n// fetch() itself only throws on network-level failures.\nsetButtonState(\"confirmation\");}catch(err){if(verboseDebug){console.error(\"[WebhookButton] Error\",{name:err instanceof Error?err.name:\"Error\",message:err instanceof Error?err.message:String(err),cause:err instanceof Error?err.cause:undefined,stack:err instanceof Error?err.stack:undefined});}setButtonState(\"idle\");}}// ── Derived styles ──────────────────────────────────────────────────────\nconst bgColor=buttonState===\"loading\"?loadingBackgroundColor:buttonState===\"confirmation\"?confirmationBackgroundColor:hovered?hoverBackgroundColor:backgroundColor;const fgColor=buttonState===\"loading\"?loadingTextColor:buttonState===\"confirmation\"?confirmationTextColor:textColor;const cursor=buttonState===\"loading\"?\"wait\":buttonState===\"confirmation\"?\"default\":\"pointer\";const label=buttonState===\"confirmation\"?confirmationText:text;// ── Render ──────────────────────────────────────────────────────────────\nreturn /*#__PURE__*/_jsxs(\"button\",{onClick:handleClick,onMouseEnter:()=>setHovered(true),onMouseLeave:()=>setHovered(false),disabled:buttonState!==\"idle\",style:{// Canvas sizing\nwidth:\"100%\",height:\"100%\",// Layout\ndisplay:\"flex\",alignItems:\"center\",justifyContent:\"center\",padding,paddingLeft,paddingRight,borderRadius,// Colors\nbackgroundColor:bgColor,color:fgColor,// Typography (spread font object from ControlType.Font)\n...font,// Interaction\ncursor,border:\"none\",outline:\"none\",transition:\"background-color 0.2s ease\",// Spread any Framer-injected positioning styles\n...style},children:[buttonState===\"loading\"&&/*#__PURE__*/_jsx(\"span\",{style:{display:\"inline-block\",width:\"1em\",height:\"1em\",border:`2px solid ${fgColor}`,borderTopColor:\"transparent\",borderRadius:\"50%\",animation:\"__wb_spin 0.7s linear infinite\",flexShrink:0,marginRight:\"0.5em\"},\"aria-hidden\":\"true\"}),/*#__PURE__*/_jsx(\"span\",{style:{pointerEvents:\"none\"},children:label})]});}WebhookButton.defaultProps={webhookUrl:\"\",calendarId:\"\",eventId:\"\",notionReferenceField:\"\",verboseDebug:false,text:\"Book Now\",confirmationText:\"Booked!\",font:{fontSize:16,fontWeight:600,letterSpacing:0,lineHeight:1.2},padding:\"12px 24px\",paddingLeft:24,paddingRight:24,borderRadius:\"8px\",backgroundColor:\"#1A1A1A\",textColor:\"#FFFFFF\",hoverBackgroundColor:\"#333333\",loadingBackgroundColor:\"#555555\",loadingTextColor:\"#FFFFFF\",confirmationBackgroundColor:\"#22C55E\",confirmationTextColor:\"#FFFFFF\",confirmationDuration:3};addPropertyControls(WebhookButton,{// ── Webhook ──────────────────────────────────────────────────────────────\nwebhookUrl:{type:ControlType.String,title:\"Webhook URL\",placeholder:\"https://…\",description:\"POST endpoint that receives the booking payload.\"},calendarId:{type:ControlType.String,title:\"Calendar ID\",placeholder:\"cal_abc123\",description:\"Sent as `calendar_id` in the payload.\"},eventId:{type:ControlType.String,title:\"Event ID\",placeholder:\"evt_xyz789\",description:\"Sent as `event_id` in the payload.\"},notionReferenceField:{type:ControlType.String,title:\"Notion Reference Field\",placeholder:\"\",description:\"Title to search in the Notion database to log sign-ups. Should be the same name as the workshop.\"},verboseDebug:{type:ControlType.Boolean,title:\"Verbose Debug\",enabledTitle:\"On\",disabledTitle:\"Off\",defaultValue:false,description:\"Log request, response and errors to the browser console.\"},// ── Text ─────────────────────────────────────────────────────────────────\ntext:{type:ControlType.String,title:\"Label\",defaultValue:\"Book Now\"},confirmationText:{type:ControlType.String,title:\"Confirmed Label\",defaultValue:\"Booked!\",description:\"Shown after a successful webhook response.\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",displayFontSize:true,displayTextAlignment:false,defaultValue:{fontSize:16,variant:\"Semibold\"}},// ── Layout ───────────────────────────────────────────────────────────────\npadding:{type:ControlType.Padding,title:\"Padding\",defaultValue:\"12px 24px\"},paddingLeft:{type:ControlType.Number,title:\"Left Offset\",defaultValue:24,min:0,max:200,unit:\"px\",displayStepper:true,description:\"Extra left padding — reserve space for a left icon.\"},paddingRight:{type:ControlType.Number,title:\"Right Offset\",defaultValue:24,min:0,max:200,unit:\"px\",displayStepper:true,description:\"Extra right padding — reserve space for a right icon.\"},borderRadius:{type:ControlType.BorderRadius,title:\"Radius\",defaultValue:\"8px\"},// ── Idle state ───────────────────────────────────────────────────────────\nbackgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#1A1A1A\"},textColor:{type:ControlType.Color,title:\"Text\",defaultValue:\"#FFFFFF\"},hoverBackgroundColor:{type:ControlType.Color,title:\"Hover BG\",defaultValue:\"#333333\"},// ── Loading state ────────────────────────────────────────────────────────\nloadingBackgroundColor:{type:ControlType.Color,title:\"Loading BG\",defaultValue:\"#555555\"},loadingTextColor:{type:ControlType.Color,title:\"Loading Text\",defaultValue:\"#FFFFFF\"},// ── Confirmation state ───────────────────────────────────────────────────\nconfirmationBackgroundColor:{type:ControlType.Color,title:\"Confirm BG\",defaultValue:\"#22C55E\"},confirmationTextColor:{type:ControlType.Color,title:\"Confirm Text\",defaultValue:\"#FFFFFF\"},confirmationDuration:{type:ControlType.Number,title:\"Confirm Duration\",defaultValue:3,min:1,max:30,unit:\"s\",displayStepper:true,description:\"Seconds before the button resets to idle.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"WebhookButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WebhookButton.map"],"mappings":"6PAE4C,SAAS,GAAuB,CAAyC,GAArC,OAAO,SAAW,KAAsB,SAAS,eAAe,EAAoB,CAAC,OAAO,IAAM,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