-import{j as n,u as xe,r as D,g as De,a as Ee}from"./iframe-CNz8RlYl.js";import{F as j,S as O}from"./SubmissionOutputPanel-DUUnyvXT.js";import{A as E}from"./action-form-DqmdZXzd.js";import"./preload-helper-BIeB60q0.js";import"./DropdownField-DQKVOkv8.js";import"./debounce-DBQB4U5e.js";import"./useOsdkClient-il4guZPb.js";import"./index-XxW0KRYf.js";import"./Input-CpAPI-dP.js";import"./useBaseUiId-D4vwSczU.js";import"./useControlled-DQvqj1ii.js";import"./index-DGRndsQB.js";import"./index-BlGd4sFh.js";import"./PopoverPopup-Dj7q3xHP.js";import"./InternalBackdrop--VJLOWNr.js";import"./composite-CZy-mnNe.js";import"./index-CPfBu2RL.js";import"./getDisabledMountTransitionStyles-B2i134Af.js";import"./ToolbarRootContext-D4VXXO-L.js";import"./tick-Bs481eBK.js";import"./svgIconContainer-B0JmWAlI.js";import"./small-cross-PTH7Ve-P.js";import"./search-ERRW7qI9.js";import"./cross-CO8ceZUf.js";import"./useValueChanged-C6ABxE1k.js";import"./getPseudoElementBounds-Der8dMUs.js";import"./CompositeItem-rHSaquZY.js";import"./makeExternalStore-pBRszKy8.js";import"./BaseForm-xK3mIVy3.js";import"./ActionButton-revmG3rY.js";import"./Button-BoQYF-o_.js";import"./SkeletonBar-Sl0pLnzx.js";import"./Tooltip-CAngo_3k.js";import"./info-sign-B5KaJKdk.js";import"./chevron-up-DgraSbQm.js";import"./chevron-down-DoirlpdZ.js";import"./useEventCallback-DfP35NXy.js";import"./iconLoader-CgxA1V0b.js";import"./CompositeRoot-DlGasQEx.js";import"./Switch-Di7_drwN.js";import"./TimePicker-CIp9BYT3.js";import"./CollapsiblePanel-DvAEYQfZ.js";import"./error-DqoZ7f_W.js";import"./assertUnreachable-tCT10eXl.js";import"./withOsdkMetrics-CtoWR-rA.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