{"version":3,"file":"MemberProfileForm.BZZLLsFH.mjs","names":["MemberProfileForm","BaseForm"],"sources":["https:/framerusercontent.com/modules/ueOlAb7fUfs5ZevgdOgP/hbUOZZtVcqOczgag1oif/MemberProfileForm.js"],"sourcesContent":["var _window;import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useMemo,useState}from\"react\";// @ts-ignore\nimport{addPropertyControls,ControlType,withCSS}from\"framer\";// @ts-ignore\nimport{auth}from\"https://cdn.framerauth.com/packages/sdk/live/latest/framerauth.esm.js\";import BaseForm,{basePropertyControls}from\"https://framerusercontent.com/modules/ExV5oOjPmSTY0gHEjmby/NpqywsqBSPokrP5l2Kmw/BaseForm.js\";const storeFunctions=((_window=window)===null||_window===void 0?void 0:_window.$auth)?window.$auth:null;export const useStore=keys=>{if(!storeFunctions){const dummyState={user:null,isAuthenticated:false,isLoaded:false};return{store:dummyState,setStore:()=>{},getCurrentStore:()=>dummyState};}else{const[state,setState]=useState(storeFunctions.getStoreState());useEffect(()=>{const handleStateChange=newState=>{setState(newState);};const unsubscribe=storeFunctions.subscribe(handleStateChange,keys);return()=>{unsubscribe();};},[keys]);return{store:state,setStore:storeFunctions.setStoreState,getCurrentStore:storeFunctions.getStoreState};}};//////////////////////////////////\n/////// FORM CONFIGURATION ///////\n//////////////////////////////////\n// Define inputs\nconst baseInputs=[{label:\"Email\",name:\"email\",type:\"email\",required:true,extra:false,placeholder:\"Email\"},{label:\"First Name\",name:\"first_name\",type:\"text\",required:true,extra:false,placeholder:\"First Name\"},{label:\"Last Name\",name:\"last_name\",type:\"text\",required:true,extra:false,placeholder:\"Last Name\"}];const formId=\"member_profile\"// Unique form ID for this form.\n;const defaultButtonLabel=\"Save Changes\"// Default submit button label on this form.\n;const exposeIconColor=false// Expose icon color property for input icons (eg hide/show password icon).\n;const buttonLabelKey=`${formId}_button_label`// Key for button label property control.\n;/**\n * Profile Form\n * By Joel Whitaker\n *\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 300\n * @framerIntrinsicHeight 40\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n */const MemberProfileForm=withCSS(function MemberProfileForm({...baseProps}){// const [user, setUser] = useState<IUser | null>(null);\nconst[defaultValues,setDefaultValues]=useState(undefined);const[inputs,setInputs]=useState(baseInputs)// We can override inputs with property controls.\n;const{store,setStore}=useStore([\"user\"]);const user=useMemo(()=>{return store.user;},[store]);const updateUser=newUser=>{setStore(state=>({...state,user:newUser}));};useEffect(()=>{if(user){const{email,first_name,last_name}=user;setDefaultValues({email,first_name,last_name});}},[user]);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(()=>{// 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.\nconsole.log(`Input ${inputControlName} not found in inputFields object.`);return;}const inputField=baseProps.inputFields[inputControlName];const display=inputField.display;const label=inputField.label;const placeholder=label;if(display===true||display===undefined){newInputs.push({...input,label,placeholder});}});setInputs(newInputs);}},[baseProps.inputFields]);const onSubmit=async formData=>{const{data,error}=await auth.updateUser(formData);const newUser=data.user;if(error){return{ok:false,message:error.message};}updateUser(newUser);// const event = new Event('framerAuthRefetchUser');\n// window.dispatchEvent(event);\nreturn{ok:true,message:\"Profile updated successfully.\"};};return /*#__PURE__*/_jsx(BaseForm,{...baseProps,button:buttonProps,inputs:inputs,defaultValues:defaultValues,onSubmit:onSubmit});},[]);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.label}`,type:ControlType.Object,controls:{display:input.extra===true?{title:\"Display\",type:ControlType.Boolean,defaultValue:true}:undefined,label:{title:\"Label\",type:ControlType.String,defaultValue:input.label}}};});const exportBasePropertyControls={...basePropertyControls,inputFields:{title:\"Inputs\",type:ControlType.Object,controls:inputsPropertyControls},input:{...basePropertyControls.input,controls:{...basePropertyControls.input.controls,iconColor:exposeIconColor?{// Add icon color property so users can control input icons (eg hide/show password icon).\ntitle:\"Icons\",type:ControlType.Color,defaultValue:\"#000\"}:undefined}},button:{// Inject default button label\n...basePropertyControls.button,controls:{...basePropertyControls.button.controls,label:undefined,[buttonLabelKey]:{...basePropertyControls.button.controls.label,defaultValue:defaultButtonLabel}}},link:undefined};// @ts-ignore - TS doesn't like our basePropertyControls type.\naddPropertyControls(MemberProfileForm,exportBasePropertyControls);MemberProfileForm.defaultProps={...BaseForm.defaultProps,...MemberProfileForm.defaultProps};export default MemberProfileForm;\nexport const __FramerMetadata__ = {\"exports\":{\"useStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"default\":{\"type\":\"reactComponent\",\"name\":\"MemberProfileForm\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"fixed\",\"framerIntrinsicWidth\":\"300\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"40\",\"framerSupportedLayoutHeight\":\"any\",\"framerDisableUnlink\":\"*\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"wfAAY,GAA2C,IAA8C,CACrG,GAA4D,CAC5D,GAAwF,IAAwI,CAAM,GAAiB,EAAQ,IAAgD,MAAO,EAAO,MAAM,KAAkB,EAAS,GAAM,CAAC,GAAI,EAA+J,CAAC,GAAK,CAAC,EAAM,EAAS,CAAC,EAAS,EAAe,eAAe,CAAC,CAAgL,MAA/K,GAAU,IAAI,CAAC,IAAM,EAAkB,GAAU,CAAC,EAAS,EAAS,AAAE,EA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