-import{j as n,u as xe,r as D,g as De,a as Ee}from"./iframe-Bbl8xWS4.js";import{F as j,S as O}from"./SubmissionOutputPanel-DIaTA9BC.js";import{A as E}from"./action-form-CSpkjj0t.js";import"./preload-helper-BUAbRzmt.js";import"./DropdownField-DdP67yjj.js";import"./debounce-BFaUKRpC.js";import"./useOsdkClient-BVIzgYNI.js";import"./index-BrhvBMro.js";import"./Input-C7X_QVu0.js";import"./useBaseUiId-Cmt5VEHx.js";import"./useControlled-DGf-N-MW.js";import"./index-Dg_zHENz.js";import"./index-CHJ1j1l2.js";import"./PopoverPopup-CwfkGrBk.js";import"./InternalBackdrop-DQJVIwhZ.js";import"./composite-BZ5wkolO.js";import"./index-CE5JSKtI.js";import"./getDisabledMountTransitionStyles-DYMa362i.js";import"./ToolbarRootContext-mlwQOMjb.js";import"./tick-CSFR0LjW.js";import"./svgIconContainer-C49n10_C.js";import"./small-cross-DTh3t08g.js";import"./search-BoObENrO.js";import"./cross-D1K3qdEd.js";import"./useValueChanged-1sJEL3iN.js";import"./getPseudoElementBounds-r4lx2DpE.js";import"./CompositeItem-UpHYLeRj.js";import"./makeExternalStore-k_EKqWBg.js";import"./BaseForm-BYgVWEj4.js";import"./ActionButton-B0l2nlsG.js";import"./Button-vDgXwn6I.js";import"./SkeletonBar-BtzllBK1.js";import"./Tooltip-d-UN8rHt.js";import"./info-sign-SPnyj-7G.js";import"./chevron-up-e2-zMua8.js";import"./chevron-down-CguzkHKU.js";import"./useEventCallback-BqyCjoBA.js";import"./iconLoader-CnVhGmsY.js";import"./CompositeRoot-BV_6M09p.js";import"./Switch--jL4z2rR.js";import"./TimePicker-C5j-jd8V.js";import"./CollapsiblePanel-j2kmvttF.js";import"./error-BL4iX6t3.js";import"./assertUnreachable-tCT10eXl.js";import"./withOsdkMetrics-D-pE8QrY.js";const{expect:i,fn:y,userEvent:s,waitFor:u,within:c}=__STORYBOOK_MODULE_TEST__,Ne=xe.actionDefinition,Be=De.actionDefinition,Re=Ee.actionDefinition,Pe=1500,Ie=[{fieldKey:"fullName",label:"Full name",fieldComponent:"TEXT_INPUT",defaultValue:"Grace Hopper",fieldComponentProps:{}},{fieldKey:"yearsExperience",label:"Years of experience",fieldComponent:"NUMBER_INPUT",defaultValue:42,fieldComponentProps:{min:0}},{fieldKey:"isRemote",label:"Remote employee",fieldComponent:"RADIO_BUTTONS",defaultValue:!0,fieldComponentProps:{options:[{label:"True",value:!0},{label:"False",value:!1}]}},{fieldKey:"isFullTime",label:"Employment type",fieldComponent:"DROPDOWN",defaultValue:!0,fieldComponentProps:{items:[!0,!1],itemToStringLabel:t=>t===!0?"Full-time":"Contractor",placeholder:"Select employment type"}}],Ue=[{fieldKey:"fullName",label:"Employee legal name",fieldComponent:"TEXT_INPUT",helperText:"Use the name that should appear in HR records.",fieldComponentProps:{placeholder:"Ada Lovelace",minLength:2}},{fieldKey:"yearsExperience",label:"Relevant experience",fieldComponent:"NUMBER_INPUT",helperText:"Whole years only.",fieldComponentProps:{min:0,max:80}},{fieldKey:"isRemote",label:"Remote employee",fieldComponent:"SWITCH",helperText:"Turn on when the employee is not assigned to an office.",fieldComponentProps:{}},{fieldKey:"isFullTime",label:"Employment type",fieldComponent:"DROPDOWN",helperText:"Choose whether this employee is full-time or a contractor.",fieldComponentProps:{items:[!0,!1],itemToStringLabel:t=>t===!0?"Full-time":"Contractor",placeholder:"Select employment type"}}],d=y().mockName("onSuccess"),P=y().mockName("onError"),I=y().mockName("onSubmit"),U=y().mockName("onSubmit:slow"),k=y().mockName("onSubmit:failure");function ke(t){d(t)}function B(t,e){return e(t)}function je(t,e){return e(t)}function Oe(t,e){return e(t)}const He=(t,e)=>(I(t),B(t,e)),Ke=async(t,e)=>(U(t),await Ae(Pe),B(t,e)),We=async t=>{throw k(t),await Ae(300),new Error("Demo submission failed")};function Ae(t){return new Promise(e=>setTimeout(e,t))}function R({applyStoryAction:t,onSubmit:e}){const[o,a]=D.useState({status:"idle"}),p=D.useCallback(async(r,m)=>{a({status:"submitting",submittedValues:r});try{let l;if(e==null){const K=await t(r,m);ke(K),l=K}else l=await e(r,m);return a({status:"success",submittedValues:r,response:l}),l}catch(l){throw a({status:"error",submittedValues:r,error:l}),l}},[t,e]);return{handleStoryError:D.useCallback(r=>{a(m=>({...m,status:"error",error:r})),P(r)},[]),handleStorySubmit:p,submission:o}}function _e({formFieldDefinitions:t,formTitle:e,isSubmitDisabled:o,onSubmit:a,showFormTitle:p}){const{handleStoryError:H,handleStorySubmit:r,submission:m}=R({applyStoryAction:B,onSubmit:a});return n.jsx(j,{output:n.jsx(O,{idleMessage:"Submit the form to see the action response.",snapshot:m}),children:n.jsx(E,{actionDefinition:Ne,formFieldDefinitions:t,formTitle:e,isSubmitDisabled:o,onError:H,onSubmit:r,showFormTitle:p})})}function Le(){const{handleStoryError:t,handleStorySubmit:e}=R({applyStoryAction:je});return n.jsx("div",{className:"osdkFormCard",style:{marginInline:"auto"},children:n.jsx(E,{actionDefinition:Be,onError:t,onSubmit:e,showFormTitle:!0})})}function Ve(){const{handleStoryError:t,handleStorySubmit:e,submission:o}=R({applyStoryAction:Oe});return n.jsx(j,{output:n.jsx(O,{idleMessage:"Submit the form to see the action response.",snapshot:o}),children:n.jsx(E,{actionDefinition:Re,onError:t,onSubmit:e,showFormTitle:!0})})}const jt={title:"Components/ActionForm/Usage",component:_e,tags:["beta"],parameters:{controls:{expanded:!0},docs:{description:{component:"ActionForm fetches action metadata through @osdk/react, renders fields for each action parameter, validates user input, and submits through useOsdkAction."}}},argTypes:{formFieldDefinitions:{control:!1,description:"Complete replacement for generated fields. Include every action parameter that should appear in the form."},formTitle:{control:"text",description:"Optional title used when showFormTitle is true."},isSubmitDisabled:{control:"boolean",description:"Disables the submit button before validation runs."},onSubmit:{control:!1,table:{category:"Events"}},showFormTitle:{control:"boolean",description:"Shows the form title above the generated fields."}},args:{isSubmitDisabled:!1,showFormTitle:!1}},f={render:()=>n.jsx(Le,{}),parameters:{docs:{description:{story:"Shows ActionForm's default behavior: it maps action metadata to generated field components when no formFieldDefinitions are provided."},source:{code:`import { ActionForm } from "@osdk/react-components/experimental";
0 commit comments