{"version":3,"file":"SendOTP.BdL6gvu_.mjs","names":["SendOTP","useState","useMemo","sendOTP","BaseForm"],"sources":["https:/framerusercontent.com/modules/EijhjtD7VOR0PwaZAhlf/SjAAfVHYOsd9Y7Vr2VZ3/SendOTP.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useMemo,useState}from\"react\";// @ts-ignore\nimport{addPropertyControls,ControlType,withCSS,inferInitialRouteFromPath,useRouter}from\"framer\";import{sendOTP}from\"https://cdn.jsdelivr.net/npm/@framerauth/sdk@2/dist/framerauth.mjs\";import BaseForm,{basePropertyControls,getURLSearchParam}from\"https://framerusercontent.com/modules/tU0OhNHakDNO2P6BFnP9/fM8K9G5fbhne3lYQfGf4/BaseForm.js\";//////////////////////////////////\n/////// FORM CONFIGURATION ///////\n//////////////////////////////////\n// Define inputs\nconst baseInputs=[{displayName:\"Email\",name:\"email\",type:\"string\",format:\"email\",required:true,overridable:false,placeholder:\"Email\",render:true,hidden:false}];const formId=\"signin_send_otp\"// Unique form ID for this form.\n;const defaultButtonLabel=\"Send Code\"// Default submit button label on this form.\n;const buttonLabelKey=`${formId}_button_label`// Key for button label property control.\n;/**\n * SendOTP.tsx\n * By Joel Whitaker\n *\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 300\n * @framerIntrinsicHeight 40\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n */const SendOTP=withCSS(function SendOTP({...baseProps}){const router=useRouter();const[inputs,setInputs]=useState(baseInputs)// We can override inputs with property controls.\n;const[defaultValues,setDefaultValues]=useState(undefined);const buttonProps=useMemo(()=>{// Map button label to button\n// This is to avoid style copy-pasting of the button label.\nreturn{...baseProps.button,label:baseProps.button[buttonLabelKey]};},[baseProps.button,baseProps.button[buttonLabelKey]]);useEffect(()=>{const email=getURLSearchParam(\"email\");setDefaultValues({email:email});},[]);useEffect(()=>{// Map input labels to inputs\nif(baseProps.inputFields){const newInputs=[];baseInputs.forEach((input,_idx)=>{const inputControlName=snakeToCamel(input.name);if(!(inputControlName in baseProps.inputFields)){// If the input is not in the inputFields object, skip it.\nreturn;}const inputField=baseProps.inputFields[inputControlName];const render=inputField.render||true;const hidden=inputField.hidden||false;const displayName=inputField.displayName;const placeholder=displayName;if(render===true){newInputs.push({...input,hidden,displayName,placeholder});}});setInputs(newInputs);}},[undefined,baseProps.inputFields]);const onSubmit=async formData=>{const sendOTPResponse=await sendOTP({email:formData.email,type:\"sign-in\"});if(sendOTPResponse.error){return{ok:false,message:sendOTPResponse.error.message};}return{ok:true,message:sendOTPResponse.data?.message||\"Email instructions sent.\",data:{email:formData.email}};};const onSuccessCallback=data=>{if(baseProps.link&&data?.email){const[path,_existingHash]=baseProps.link.split(\"#\");// Create new hash with email parameter\nconst emailParam=`email=${encodeURIComponent(data.email)}`;const{routeId,pathVariables}=inferInitialRouteFromPath(router.routes,path);if(routeId){router.navigate(routeId,emailParam,pathVariables);// Wait for navigation to complete\nsetTimeout(()=>{},500);}}};return /*#__PURE__*/_jsx(BaseForm,{...baseProps,button:buttonProps,fields:inputs,defaultValues:defaultValues,onSubmit:onSubmit,onSuccess:onSuccessCallback});},[]);const snakeToCamel=str=>{return str.split(\"_\").map((word,index)=>{if(index===0){return word;}return word.charAt(0).toUpperCase()+word.slice(1);}).join(\"\");};// Here we can override property controls if we don't want to expose them to the user.\n// We generate the inputs property controls dynamically based on the inputs array.\nconst inputsPropertyControls={};baseInputs.forEach((input,_idx)=>{const inputControlName=snakeToCamel(input.name);inputsPropertyControls[inputControlName]={title:`${input.displayName}`,type:ControlType.Object,controls:{render:input.overridable===true?{title:\"Render\",type:ControlType.Boolean,defaultValue:true}:undefined,hidden:input.overridable===true?{title:\"Hidden\",type:ControlType.Boolean,defaultValue:false,hidden:props=>props.render===true}:undefined,displayName:{title:\"Display Name\",type:ControlType.String,defaultValue:input.displayName,hidden:props=>props.render===true&&props.hidden===false}}};});const exportBasePropertyControls={...basePropertyControls,inputFields:{title:\"Inputs\",type:ControlType.Object,controls:inputsPropertyControls},link:{title:\"Redirect\",type:ControlType.Link},button:{// Inject default button label\n...basePropertyControls.button,controls:{...basePropertyControls.button.controls,label:undefined,[buttonLabelKey]:{...basePropertyControls.button.controls.label,defaultValue:defaultButtonLabel}}}};// @ts-ignore - TS doesn't like our basePropertyControls type.\naddPropertyControls(SendOTP,exportBasePropertyControls);SendOTP.defaultProps={...BaseForm.defaultProps,...SendOTP.defaultProps};export default SendOTP;\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SendOTP\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"*\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"300\",\"framerSupportedLayoutHeight\":\"any\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerIntrinsicHeight\":\"40\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"+TAA2C,IAA8C,IACO,IAAwF,IAA0J,CAI5U,EAAW,CAAC,CAAC,YAAY,QAAQ,KAAK,QAAQ,KAAK,SAAS,OAAO,QAAQ,SAAS,GAAK,YAAY,GAAM,YAAY,QAAQ,OAAO,GAAK,OAAO,GAAM,CAAC,CAAO,EAAO,kBACtK,EAAmB,YACnB,EAAe,GAAG,EAAO,eAYvB,EAAQ,EAAQ,SAAiB,CAAC,GAAG,GAAW,CAAC,IAAM,EAAO,GAAW,CAAM,CAAC,EAAO,GAAWC,EAAS,EAAW,CACzH,CAAC,EAAc,GAAkBA,EAAS,IAAA,GAAU,CAAO,EAAYC,OAEvE,CAAC,GAAG,EAAU,OAAO,MAAM,EAAU,OAAO,GAAgB,EAAG,CAAC,EAAU,OAAO,EAAU,OAAO,GAAgB,CAAC,CAAC,MAAc,CAAwC,EAAiB,CAAC,MAA7C,EAAkB,QAAQ,CAA+B,CAAC,EAAG,EAAE,CAAC,CAAC,MAAc,CACpO,GAAG,EAAU,YAAY,CAAC,IAAM,EAAU,EAAE,CAAC,EAAW,SAAS,EAAM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