{"version":3,"file":"CustomEmailWebhookForm.Cg3d9f2K.mjs","names":["React.useState"],"sources":["https:/framerusercontent.com/modules/uFKgdHjbTBSl1fPSljn1/Lb22mCD2b7IksPVsciv0/CustomEmailWebhookForm.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";export default function CustomEmailWebhookForm(props){const{webhookUrl,redirectUrl,emailPlaceholder,buttonText,labelText,successText,errorText,tallySubmissionParam,tallyFormIdParam,captureAllUrlParams,backgroundColor,textColor,inputBackground,inputTextColor,buttonBackground,buttonTextColor,borderColor,borderRadius,padding}=props;const[email,setEmail]=React.useState(\"\");const[loading,setLoading]=React.useState(false);const[status,setStatus]=React.useState(\"idle\");const[message,setMessage]=React.useState(\"\");const getUrlParam=key=>{if(typeof window===\"undefined\")return\"\";const params=new URLSearchParams(window.location.search);return params.get(key)||\"\";};const getAllUrlParams=()=>{if(typeof window===\"undefined\")return{};const params=new URLSearchParams(window.location.search);const data={};params.forEach((value,key)=>{data[key]=value;});return data;};const isValidEmail=value=>{return/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(value);};const handleSubmit=async event=>{event.preventDefault();setStatus(\"idle\");setMessage(\"\");const cleanEmail=email.trim().toLowerCase();if(!cleanEmail||!isValidEmail(cleanEmail)){setStatus(\"error\");setMessage(\"Please enter a valid email address.\");return;}if(!webhookUrl){setStatus(\"error\");setMessage(\"Webhook URL is missing.\");return;}setLoading(true);const tallySubmissionId=getUrlParam(tallySubmissionParam);const tallyFormId=getUrlParam(tallyFormIdParam);const payload={email:cleanEmail,// Hidden tracking fields\ntally_submission_id:tallySubmissionId,tally_form_id:tallyFormId,// Useful page data\npage_url:typeof window!==\"undefined\"?window.location.href:\"\",page_path:typeof window!==\"undefined\"?window.location.pathname:\"\",submitted_at:new Date().toISOString(),// Optional full URL parameter capture\nurl_params:captureAllUrlParams?getAllUrlParams():undefined};try{const response=await fetch(webhookUrl,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify(payload)});if(!response.ok){throw new Error(`Webhook failed with status ${response.status}`);}const data=await response.json();setStatus(\"success\");setMessage(successText);// Prefer the URL returned by the webhook; fall back to the configured redirectUrl.\nconst target=data.url||redirectUrl;if(target){const redirect=new URL(target,window.location.origin);redirect.searchParams.set(\"email\",cleanEmail);if(tallySubmissionId)redirect.searchParams.set(\"tally_submission_id\",tallySubmissionId);if(tallyFormId)redirect.searchParams.set(\"tally_form_id\",tallyFormId);window.location.href=redirect.toString();}}finally{setLoading(false);}};React.useEffect(()=>{if(typeof window===\"undefined\")return;const params=new URLSearchParams(window.location.search);const prefill=params.get(\"email\");if(prefill)setEmail(prefill);},[]);return /*#__PURE__*/_jsxs(\"form\",{onSubmit:handleSubmit,style:{width:\"100%\",height:\"100%\",display:\"flex\",flexDirection:\"column\",gap:14,padding,background:backgroundColor,borderRadius,boxSizing:\"border-box\",color:textColor,fontFamily:\"Inter, sans-serif\"},children:[labelText&&/*#__PURE__*/_jsx(\"label\",{style:{fontSize:14,lineHeight:\"1.4em\",fontWeight:500,color:textColor},children:labelText}),/*#__PURE__*/_jsx(\"input\",{type:\"email\",value:email,onChange:event=>setEmail(event.target.value),placeholder:emailPlaceholder,required:true,style:{width:\"100%\",height:52,padding:\"0 16px\",borderRadius:borderRadius,border:`1px solid ${borderColor}`,background:inputBackground,color:inputTextColor,fontSize:16,outline:\"none\",boxSizing:\"border-box\"}}),/*#__PURE__*/_jsx(\"button\",{type:\"submit\",disabled:loading,style:{width:\"100%\",height:52,border:\"none\",borderRadius:borderRadius,background:buttonBackground,color:buttonTextColor,fontSize:16,fontWeight:600,cursor:loading?\"not-allowed\":\"pointer\",opacity:loading?.7:1},children:loading?\"Submitting...\":buttonText}),message&&/*#__PURE__*/_jsx(\"div\",{style:{fontSize:14,lineHeight:\"1.4em\",color:status===\"error\"?\"#FF4D4D\":textColor},children:message})]});}CustomEmailWebhookForm.defaultProps={webhookUrl:\"\",redirectUrl:\"\",emailPlaceholder:\"Enter your email\",buttonText:\"Continue\",labelText:\"Fill out your email:\",successText:\"Submitted successfully.\",errorText:\"Something went wrong. Please try again.\",tallySubmissionParam:\"submissionId\",tallyFormIdParam:\"formId\",captureAllUrlParams:true,backgroundColor:\"transparent\",textColor:\"#FFFFFF\",inputBackground:\"#FFFFFF\",inputTextColor:\"#111111\",buttonBackground:\"#FFFFFF\",buttonTextColor:\"#111111\",borderColor:\"rgba(255,255,255,0.2)\",borderRadius:10,padding:0};addPropertyControls(CustomEmailWebhookForm,{webhookUrl:{type:ControlType.String,title:\"Webhook URL\",placeholder:\"https://your-webhook-url.com\"},redirectUrl:{type:ControlType.String,title:\"Redirect URL\",placeholder:\"/next-page\"},emailPlaceholder:{type:ControlType.String,title:\"Email Placeholder\"},buttonText:{type:ControlType.String,title:\"Button Text\"},labelText:{type:ControlType.String,title:\"Label Text\"},successText:{type:ControlType.String,title:\"Success Text\"},errorText:{type:ControlType.String,title:\"Error Text\"},tallySubmissionParam:{type:ControlType.String,title:\"Tally Sub ID Param\",placeholder:\"submissionId\"},tallyFormIdParam:{type:ControlType.String,title:\"Tally Form ID Param\",placeholder:\"formId\"},captureAllUrlParams:{type:ControlType.Boolean,title:\"Capture URL Params\",defaultValue:true},backgroundColor:{type:ControlType.Color,title:\"Background\"},textColor:{type:ControlType.Color,title:\"Text\"},inputBackground:{type:ControlType.Color,title:\"Input BG\"},inputTextColor:{type:ControlType.Color,title:\"Input Text\"},buttonBackground:{type:ControlType.Color,title:\"Button BG\"},buttonTextColor:{type:ControlType.Color,title:\"Button Text\"},borderColor:{type:ControlType.Color,title:\"Border\"},borderRadius:{type:ControlType.Number,title:\"Radius\",min:0,max:40,step:1},padding:{type:ControlType.Number,title:\"Padding\",min:0,max:80,step:1}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CustomEmailWebhookForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\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