{"version":3,"file":"MemberProfileForm.CAdzORE9.mjs","names":["useState","MemberProfileForm","useMemo","auth","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":"gUAAuD,IAA8C,IACzC,IAC4B,IAAwI,CAAM,EAAyB,GAAgD,MAAO,EAAO,MAAM,KAAkB,EAAS,GAAM,CAAC,GAAI,EAA+J,CAAC,GAAK,CAAC,EAAM,GAAUA,EAAS,EAAe,eAAe,CAAC,CAAgL,OAA/K,MAAc,CAAyD,IAAM,EAAY,EAAe,UAAjE,GAAU,CAAC,EAAS,EAAS,EAAgE,EAAK,CAAC,UA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