@remoteoss/remote-flows 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-AG6UYT2C.js +2 -0
- package/dist/chunk-AG6UYT2C.js.map +1 -0
- package/dist/flows/CostCalculator/CostCalculatorForm.d.ts +5 -1
- package/dist/flows/CostCalculator/CostCalculatorForm.js +1 -1
- package/dist/flows/CostCalculator/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-J2YJI5VK.js +0 -2
- package/dist/chunk-J2YJI5VK.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as n}from"./chunk-KSHK3ZPX.js";import{a as C}from"./chunk-UDCOYAXP.js";import{g as c}from"./chunk-STEO7MS2.js";import{a as l}from"./chunk-P37U34EQ.js";import{useEffect as S}from"react";import{jsx as m}from"react/jsx-runtime";function w({onSubmit:f,onError:d,onSuccess:p,shouldResetForm:e,resetFields:a}){let{form:o,formId:E,costCalculatorBag:t}=n();process.env.NODE_ENV==="development"&&e&&a&&(console.warn('CostCalculatorForm: Both "shouldResetForm" and "resetFields" were provided. Using "shouldResetForm" and ignoring "resetFields".'),a=void 0);let{formState:{isSubmitSuccessful:i}}=o;S(()=>{if(i&&e&&(t?.resetForm(),o.reset()),i&&a){let s={...o.getValues()};a.forEach(r=>{s[r]=""}),t?.resetForm(),o.reset(s)}},[i,o,e,t,a]);let F=l(async u=>{let s=t?.parseFormValues(u),r=await t?.onSubmit(s);await f?.(s),r?.error?d?.(r.error):r?.data&&await p?.(r?.data)},"handleSubmit");return m(c,{...o,children:m("form",{id:E,onSubmit:o.handleSubmit(F),className:"space-y-4 RemoteFlows__CostCalculatorForm",children:m(C,{fields:t?.fields??[]})})})}l(w,"CostCalculatorForm");export{w as a};
|
|
2
|
+
//# sourceMappingURL=chunk-AG6UYT2C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flows/CostCalculator/CostCalculatorForm.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { CostCalculatorEstimateResponse } from '@/src/client';\nimport { JSONSchemaFormFields } from '@/src/components/form/JSONSchemaForm';\nimport { Form } from '@/src/components/ui/form';\nimport { useCostCalculatorContext } from '@/src/flows/CostCalculator/context';\nimport { EstimationError } from '@/src/flows/CostCalculator/hooks';\nimport {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationSubmitValues,\n} from '@/src/flows/CostCalculator/types';\n\ntype CostCalculatorFormProps = Partial<{\n /**\n * Callback function that handles form submission. When form is submit, the form values are sent to the consumer app before behind submitted to Remote.\n * @param data - The payload sent to the /cost-calculator/estimation endpoint.\n */\n onSubmit: (\n data: CostCalculatorEstimationSubmitValues,\n ) => Promise<void> | void;\n /**\n * Callback function to handle the success when the estimation succeeds. The CostCalculatorEstimateResponse is sent back to you.\n * @param data - The response data from the /cost-calculator/estimation endpoint.\n */\n onSuccess: (data: CostCalculatorEstimateResponse) => Promise<void> | void;\n /**\n * Callback function to handle the error when the estimation fails.\n * @param error - The error object.\n */\n onError: (error: EstimationError) => void;\n /**\n * Whether to reset the form when the form is successfully submitted.\n */\n shouldResetForm?: boolean;\n\n /**\n * Fields to reset when the form is successfully submitted.\n */\n resetFields?: ('country' | 'currency' | 'salary')[];\n}>;\n\nexport function CostCalculatorForm({\n onSubmit,\n onError,\n onSuccess,\n shouldResetForm,\n resetFields,\n}: CostCalculatorFormProps) {\n const { form, formId, costCalculatorBag } = useCostCalculatorContext();\n\n if (\n process.env.NODE_ENV === 'development' &&\n shouldResetForm &&\n resetFields\n ) {\n console.warn(\n 'CostCalculatorForm: Both \"shouldResetForm\" and \"resetFields\" were provided. Using \"shouldResetForm\" and ignoring \"resetFields\".',\n );\n resetFields = undefined;\n }\n\n const {\n formState: { isSubmitSuccessful },\n } = form;\n\n useEffect(() => {\n // resets the entire form if the form is successfully submitted and the shouldResetForm prop is true\n if (isSubmitSuccessful && shouldResetForm) {\n costCalculatorBag?.resetForm();\n form.reset();\n }\n\n // resets the specified fields if the form is successfully submitted and the resetFields prop is provided\n if (isSubmitSuccessful && resetFields) {\n // Reset only the specified fields\n const currentValues = form.getValues();\n const resetValues = { ...currentValues };\n resetFields.forEach((field) => {\n resetValues[field] = '';\n });\n\n costCalculatorBag?.resetForm();\n form.reset(resetValues);\n }\n }, [\n isSubmitSuccessful,\n form,\n shouldResetForm,\n costCalculatorBag,\n resetFields,\n ]);\n\n const handleSubmit = async (values: CostCalculatorEstimationFormValues) => {\n const cleanedValues = costCalculatorBag?.parseFormValues(\n values,\n ) as CostCalculatorEstimationSubmitValues;\n const costCalculatorResults =\n await costCalculatorBag?.onSubmit(cleanedValues);\n\n await onSubmit?.(cleanedValues);\n\n if (costCalculatorResults?.error) {\n onError?.(costCalculatorResults.error);\n } else if (costCalculatorResults?.data) {\n await onSuccess?.(costCalculatorResults?.data);\n }\n };\n\n return (\n <Form {...form}>\n <form\n id={formId}\n onSubmit={form.handleSubmit(handleSubmit)}\n className=\"space-y-4 RemoteFlows__CostCalculatorForm\"\n >\n <JSONSchemaFormFields fields={costCalculatorBag?.fields ?? []} />\n </form>\n </Form>\n );\n}\n"],"mappings":"gKAAA,OAAS,aAAAA,MAAiB,QAkHlB,cAAAC,MAAA,oBA1ED,SAASC,EAAmB,CACjC,SAAAC,EACA,QAAAC,EACA,UAAAC,EACA,gBAAAC,EACA,YAAAC,CACF,EAA4B,CAC1B,GAAM,CAAE,KAAAC,EAAM,OAAAC,EAAQ,kBAAAC,CAAkB,EAAIC,EAAyB,EAGnE,QAAQ,IAAI,WAAa,eACzBL,GACAC,IAEA,QAAQ,KACN,iIACF,EACAA,EAAc,QAGhB,GAAM,CACJ,UAAW,CAAE,mBAAAK,CAAmB,CAClC,EAAIJ,EAEJK,EAAU,IAAM,CAQd,GANID,GAAsBN,IACxBI,GAAmB,UAAU,EAC7BF,EAAK,MAAM,GAITI,GAAsBL,EAAa,CAGrC,IAAMO,EAAc,CAAE,GADAN,EAAK,UAAU,CACE,EACvCD,EAAY,QAASQ,GAAU,CAC7BD,EAAYC,CAAK,EAAI,EACvB,CAAC,EAEDL,GAAmB,UAAU,EAC7BF,EAAK,MAAMM,CAAW,CACxB,CACF,EAAG,CACDF,EACAJ,EACAF,EACAI,EACAH,CACF,CAAC,EAED,IAAMS,EAAeC,EAAA,MAAOC,GAA+C,CACzE,IAAMC,EAAgBT,GAAmB,gBACvCQ,CACF,EACME,EACJ,MAAMV,GAAmB,SAASS,CAAa,EAEjD,MAAMhB,IAAWgB,CAAa,EAE1BC,GAAuB,MACzBhB,IAAUgB,EAAsB,KAAK,EAC5BA,GAAuB,MAChC,MAAMf,IAAYe,GAAuB,IAAI,CAEjD,EAdqB,gBAgBrB,OACEnB,EAACoB,EAAA,CAAM,GAAGb,EACR,SAAAP,EAAC,QACC,GAAIQ,EACJ,SAAUD,EAAK,aAAaQ,CAAY,EACxC,UAAU,4CAEV,SAAAf,EAACqB,EAAA,CAAqB,OAAQZ,GAAmB,QAAU,CAAC,EAAG,EACjE,EACF,CAEJ,CA9EgBO,EAAAf,EAAA","names":["useEffect","jsx","CostCalculatorForm","onSubmit","onError","onSuccess","shouldResetForm","resetFields","form","formId","costCalculatorBag","useCostCalculatorContext","isSubmitSuccessful","useEffect","resetValues","field","handleSubmit","__name","values","cleanedValues","costCalculatorResults","Form","JSONSchemaFormFields"]}
|
|
@@ -26,7 +26,11 @@ type CostCalculatorFormProps = Partial<{
|
|
|
26
26
|
* Whether to reset the form when the form is successfully submitted.
|
|
27
27
|
*/
|
|
28
28
|
shouldResetForm?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Fields to reset when the form is successfully submitted.
|
|
31
|
+
*/
|
|
32
|
+
resetFields?: ('country' | 'currency' | 'salary')[];
|
|
29
33
|
}>;
|
|
30
|
-
declare function CostCalculatorForm({ onSubmit, onError, onSuccess, shouldResetForm, }: CostCalculatorFormProps): react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare function CostCalculatorForm({ onSubmit, onError, onSuccess, shouldResetForm, resetFields, }: CostCalculatorFormProps): react_jsx_runtime.JSX.Element;
|
|
31
35
|
|
|
32
36
|
export { CostCalculatorForm };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../../chunk-
|
|
1
|
+
import{a}from"../../chunk-AG6UYT2C.js";import"../../chunk-KSHK3ZPX.js";import"../../chunk-UDCOYAXP.js";import"../../chunk-OYI5OCMY.js";import"../../chunk-MPMOHDZP.js";import"../../chunk-WZSGDTVV.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-STEO7MS2.js";import"../../chunk-CNYSTJVL.js";import"../../chunk-TC3SWPEN.js";import"../../chunk-P37U34EQ.js";export{a as CostCalculatorForm};
|
|
2
2
|
//# sourceMappingURL=CostCalculatorForm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../chunk-YJXRJTOH.js";import{a as j}from"../../chunk-L6CLZL2D.js";import"../../chunk-CVXZNBHC.js";import"../../chunk-3TAUIOLW.js";import"../../chunk-ZOTFG7GS.js";import"../../chunk-MIALHORP.js";import"../../chunk-NTJN7NCK.js";import"../../chunk-2IOIRPXX.js";import"../../chunk-BHXNRWYC.js";import{a as e}from"../../chunk-
|
|
1
|
+
import"../../chunk-YJXRJTOH.js";import{a as j}from"../../chunk-L6CLZL2D.js";import"../../chunk-CVXZNBHC.js";import"../../chunk-3TAUIOLW.js";import"../../chunk-ZOTFG7GS.js";import"../../chunk-MIALHORP.js";import"../../chunk-NTJN7NCK.js";import"../../chunk-2IOIRPXX.js";import"../../chunk-BHXNRWYC.js";import{a as e}from"../../chunk-AG6UYT2C.js";import{a as g}from"../../chunk-LU6YNL6P.js";import{a as f}from"../../chunk-HRIDANZ6.js";import{a as i}from"../../chunk-KKM4IXYC.js";import{a as h}from"../../chunk-DYB3RWP7.js";import{a as d}from"../../chunk-7RQYLR2B.js";import"../../chunk-KSHK3ZPX.js";import{b as a,d as c}from"../../chunk-QTN4WTLR.js";import"../../chunk-S2G7GEGF.js";import"../../chunk-UPRUP24B.js";import"../../chunk-X5UOBUIX.js";import"../../chunk-MOUO52OS.js";import"../../chunk-WVJDCDGZ.js";import{d as b}from"../../chunk-MC6FNME3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-276MJCIE.js";import"../../chunk-UDCOYAXP.js";import"../../chunk-OYI5OCMY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-MPMOHDZP.js";import"../../chunk-WZSGDTVV.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-STEO7MS2.js";import"../../chunk-CNYSTJVL.js";import"../../chunk-TC3SWPEN.js";import"../../chunk-P37U34EQ.js";export{i as CostCalculatorDisclaimer,d as CostCalculatorFlow,e as CostCalculatorForm,g as CostCalculatorResetButton,j as CostCalculatorResults,f as CostCalculatorSubmitButton,a as buildCostCalculatorEstimationPayload,h as disclaimerData,c as useCostCalculator,b as useCostCalculatorEstimationPdf};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./chunk-M22FKNEY.js";import{a as or}from"./chunk-6JWQ4PZE.js";import"./chunk-JW2HLB6X.js";import"./chunk-SYEPIESJ.js";import"./chunk-5LJOLMV4.js";import"./chunk-6GMGXSKN.js";import"./chunk-W5DG5WWJ.js";import"./chunk-VX2UC3HG.js";import"./chunk-XSHHMBMT.js";import"./chunk-XFD3ULUF.js";import"./chunk-JODJFARP.js";import"./chunk-WWANHPT7.js";import"./chunk-S4XU4SE7.js";import"./chunk-KUIJOFEW.js";import"./chunk-2E4TPU4E.js";import"./chunk-3N2Z72JT.js";import"./chunk-ABFF6YSW.js";import"./chunk-UBIYEKYH.js";import"./chunk-25OMQHCO.js";import"./chunk-MRYRNB7Y.js";import"./chunk-GULCZWSK.js";import{a as ir}from"./chunk-MBIQ2ECY.js";import"./chunk-Z7WBY27D.js";import"./chunk-7TOZZQQJ.js";import"./chunk-RTNT5LSU.js";import"./chunk-OOK2XH5H.js";import"./chunk-2EPROBXQ.js";import"./chunk-4CZKKCKQ.js";import"./chunk-DBRBPYIF.js";import"./chunk-LXHKMGWZ.js";import"./chunk-CCYHGN4R.js";import"./chunk-R4PWQPR6.js";import"./chunk-PGWKJ6FK.js";import"./chunk-XOOG5SNT.js";import"./chunk-2A5R3YN2.js";import"./chunk-6VWI4FCI.js";import"./chunk-F66G33YT.js";import"./chunk-YJXRJTOH.js";import{a as S}from"./chunk-L6CLZL2D.js";import"./chunk-CVXZNBHC.js";import"./chunk-3TAUIOLW.js";import"./chunk-ZOTFG7GS.js";import"./chunk-MIALHORP.js";import"./chunk-NTJN7NCK.js";import"./chunk-2IOIRPXX.js";import"./chunk-BHXNRWYC.js";import{a as T}from"./chunk-
|
|
1
|
+
import"./chunk-M22FKNEY.js";import{a as or}from"./chunk-6JWQ4PZE.js";import"./chunk-JW2HLB6X.js";import"./chunk-SYEPIESJ.js";import"./chunk-5LJOLMV4.js";import"./chunk-6GMGXSKN.js";import"./chunk-W5DG5WWJ.js";import"./chunk-VX2UC3HG.js";import"./chunk-XSHHMBMT.js";import"./chunk-XFD3ULUF.js";import"./chunk-JODJFARP.js";import"./chunk-WWANHPT7.js";import"./chunk-S4XU4SE7.js";import"./chunk-KUIJOFEW.js";import"./chunk-2E4TPU4E.js";import"./chunk-3N2Z72JT.js";import"./chunk-ABFF6YSW.js";import"./chunk-UBIYEKYH.js";import"./chunk-25OMQHCO.js";import"./chunk-MRYRNB7Y.js";import"./chunk-GULCZWSK.js";import{a as ir}from"./chunk-MBIQ2ECY.js";import"./chunk-Z7WBY27D.js";import"./chunk-7TOZZQQJ.js";import"./chunk-RTNT5LSU.js";import"./chunk-OOK2XH5H.js";import"./chunk-2EPROBXQ.js";import"./chunk-4CZKKCKQ.js";import"./chunk-DBRBPYIF.js";import"./chunk-LXHKMGWZ.js";import"./chunk-CCYHGN4R.js";import"./chunk-R4PWQPR6.js";import"./chunk-PGWKJ6FK.js";import"./chunk-XOOG5SNT.js";import"./chunk-2A5R3YN2.js";import"./chunk-6VWI4FCI.js";import"./chunk-F66G33YT.js";import"./chunk-YJXRJTOH.js";import{a as S}from"./chunk-L6CLZL2D.js";import"./chunk-CVXZNBHC.js";import"./chunk-3TAUIOLW.js";import"./chunk-ZOTFG7GS.js";import"./chunk-MIALHORP.js";import"./chunk-NTJN7NCK.js";import"./chunk-2IOIRPXX.js";import"./chunk-BHXNRWYC.js";import{a as T}from"./chunk-AG6UYT2C.js";import{a as _}from"./chunk-LU6YNL6P.js";import{a as z}from"./chunk-HRIDANZ6.js";import"./chunk-A7ZJQCNU.js";import{a as E}from"./chunk-KKM4IXYC.js";import{a as B}from"./chunk-DYB3RWP7.js";import{a as R}from"./chunk-7RQYLR2B.js";import"./chunk-KSHK3ZPX.js";import{b as k,d as F}from"./chunk-QTN4WTLR.js";import"./chunk-S2G7GEGF.js";import"./chunk-UPRUP24B.js";import"./chunk-X5UOBUIX.js";import"./chunk-MOUO52OS.js";import"./chunk-WVJDCDGZ.js";import{d as C}from"./chunk-MC6FNME3.js";import"./chunk-PWUYHFON.js";import{a as tr}from"./chunk-5IMSGRC3.js";import{a as J}from"./chunk-YECC5GAT.js";import{a as er}from"./chunk-SX5W3CBP.js";import{a as rr,b as ar}from"./chunk-VTNGEN34.js";import"./chunk-QW4JPW6J.js";import"./chunk-Z4FTX74F.js";import{a as g}from"./chunk-276MJCIE.js";import"./chunk-PJBAQZ6G.js";import"./chunk-HS3TP43Z.js";import{a as Z}from"./chunk-HUEFMP54.js";import{a as H}from"./chunk-DMWRLPWG.js";import"./chunk-UDCOYAXP.js";import"./chunk-OYI5OCMY.js";import"./chunk-CFIJKJXD.js";import"./chunk-MPMOHDZP.js";import"./chunk-WZSGDTVV.js";import{a as v,c as u}from"./chunk-3ZWDIEEM.js";import"./chunk-STEO7MS2.js";import"./chunk-CNYSTJVL.js";import"./chunk-TVZAFTPT.js";import{c as P,d as h}from"./chunk-TC3SWPEN.js";import{a as e}from"./chunk-P37U34EQ.js";import{QueryClient as q,QueryClientProvider as Q}from"@tanstack/react-query";function l(r){let a=document.documentElement;Object.keys(r).forEach(t=>{let o=r[t];o&&a.style.setProperty(t,o)})}e(l,"setCssProperties");function N(r){let a={};return Object.keys(r).forEach(t=>{a[`--${t}`]=r[t]}),a}e(N,"mapThemeColors");function O(r){return{"--spacing":r}}e(O,"mapThemeSpacing");function j(r){return{"--radius":r}}e(j,"mapThemeBorderRadius");function D(r){return{"--fontSizeBase":r.fontSizeBase}}e(D,"mapThemeFont");function m(r){r?.colors&&l(N(r.colors)),r?.spacing&&l(O(r.spacing)),r?.borderRadius&&l(j(r.borderRadius)),r?.font&&l(D(r.font))}e(m,"applyTheme");import{createContext as I,useEffect as A,useMemo as K}from"react";import{jsx as U}from"react/jsx-runtime";var V=I({theme:{}});function w(r){A(()=>{r.theme&&Object.keys(r.theme).length>0&&m(r.theme)},[r.theme]);let a=K(()=>({theme:r.theme}),[r.theme]);return U(V.Provider,{value:a,children:r.children})}e(w,"ThemeProvider");var f={partners:"https://gateway.partners.remote-sandbox.com",production:"https://gateway.remote.com",sandbox:"https://gateway.remote-sandbox.com",staging:"https://gateway.niceremote.com"};import{createClient as W}from"@hey-api/client-fetch";import{useQuery as M}from"@tanstack/react-query";import{useRef as x}from"react";function L(r){try{return new URL(r),!0}catch{return!1}}e(L,"isValidUrl");var b=e(({auth:r,options:a})=>{let t=x(null),{refetch:o}=M({queryKey:["auth"],queryFn:r,enabled:!1}),c=a?.environment?f[a?.environment]:"https://gateway.remote.com",s=g.getConfig(),p="0.7.0";a?.environment&&a?.environment!=="production"&&h(p);let d=!!a?.proxy&&L(a.proxy.url);return a?.proxy&&!d&&console.error("Invalid proxy URL provided. Using default base URL."),x(W({...s,headers:{...s.headers,...d?a?.proxy?.headers:{},"X-Client-Name":"remote-flows-sdk","X-Client-Version":p},baseUrl:d?a.proxy?.url:c,auth:e(async()=>{function y(i){return!i||Date.now()+6e4>i}if(e(y,"hasTokenExpired"),!t.current||y(t.current.expiresAt)){let{data:i}=await o();i&&(t.current={accessToken:i.accessToken,expiresAt:Date.now()+i.expiresIn*1e3})}return t.current?.accessToken},"auth")}))},"useAuth");import{jsx as n}from"react/jsx-runtime";var X=new q;function Y({children:r,auth:a,proxy:t,environment:o}){let c=b({auth:a,options:{proxy:t,environment:o}});return n(u.Provider,{value:{client:c.current},children:r})}e(Y,"RemoteFlowContextWrapper");function $({children:r,components:a}){return n(v.Provider,{value:a?{components:a}:{components:{}},children:r})}e($,"FormFieldsProvider");function G({auth:r,children:a,components:t,theme:o,proxy:c,environment:s}){return n(Q,{client:X,children:n($,{components:t,children:n(Y,{auth:r,proxy:c,environment:s,children:n(w,{theme:o,children:a})})})})}e(G,"RemoteFlows");export{Z as ContractAmendmentConfirmationForm,tr as ContractAmendmentFlow,H as ContractAmendmentForm,J as ContractAmendmentSubmit,E as CostCalculatorDisclaimer,R as CostCalculatorFlow,T as CostCalculatorForm,_ as CostCalculatorResetButton,S as CostCalculatorResults,z as CostCalculatorSubmitButton,ir as OnboardingFlow,G as RemoteFlows,or as TerminationFlow,k as buildCostCalculatorEstimationPayload,B as disclaimerData,P as transformYupErrorsIntoObject,er as useContractAmendment,F as useCostCalculator,C as useCostCalculatorEstimationPdf,rr as useEmploymentQuery,ar as useTimeOffQuery};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/dist/chunk-J2YJI5VK.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{b as i}from"./chunk-KSHK3ZPX.js";import{a as e}from"./chunk-UDCOYAXP.js";import{g as l}from"./chunk-STEO7MS2.js";import{a as r}from"./chunk-P37U34EQ.js";import{jsx as s}from"react/jsx-runtime";function b({onSubmit:u,onError:c,onSuccess:C,shouldResetForm:n}){let{form:a,formId:d,costCalculatorBag:o}=i(),f=r(async p=>{let m=o?.parseFormValues(p),t=await o?.onSubmit(m);await u?.(m),t?.error?c?.(t.error):t?.data&&(await C?.(t?.data),n&&(o?.resetForm(),a.reset()))},"handleSubmit");return s(l,{...a,children:s("form",{id:d,onSubmit:a.handleSubmit(f),className:"space-y-4 RemoteFlows__CostCalculatorForm",children:s(e,{fields:o?.fields??[]})})})}r(b,"CostCalculatorForm");export{b as a};
|
|
2
|
-
//# sourceMappingURL=chunk-J2YJI5VK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/flows/CostCalculator/CostCalculatorForm.tsx"],"sourcesContent":["import { CostCalculatorEstimateResponse } from '@/src/client';\nimport { JSONSchemaFormFields } from '@/src/components/form/JSONSchemaForm';\nimport { Form } from '@/src/components/ui/form';\nimport { useCostCalculatorContext } from '@/src/flows/CostCalculator/context';\nimport { EstimationError } from '@/src/flows/CostCalculator/hooks';\nimport {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationSubmitValues,\n} from '@/src/flows/CostCalculator/types';\n\ntype CostCalculatorFormProps = Partial<{\n /**\n * Callback function that handles form submission. When form is submit, the form values are sent to the consumer app before behind submitted to Remote.\n * @param data - The payload sent to the /cost-calculator/estimation endpoint.\n */\n onSubmit: (\n data: CostCalculatorEstimationSubmitValues,\n ) => Promise<void> | void;\n /**\n * Callback function to handle the success when the estimation succeeds. The CostCalculatorEstimateResponse is sent back to you.\n * @param data - The response data from the /cost-calculator/estimation endpoint.\n */\n onSuccess: (data: CostCalculatorEstimateResponse) => Promise<void> | void;\n /**\n * Callback function to handle the error when the estimation fails.\n * @param error - The error object.\n */\n onError: (error: EstimationError) => void;\n /**\n * Whether to reset the form when the form is successfully submitted.\n */\n shouldResetForm?: boolean;\n}>;\n\nexport function CostCalculatorForm({\n onSubmit,\n onError,\n onSuccess,\n shouldResetForm,\n}: CostCalculatorFormProps) {\n const { form, formId, costCalculatorBag } = useCostCalculatorContext();\n\n const handleSubmit = async (values: CostCalculatorEstimationFormValues) => {\n const cleanedValues = costCalculatorBag?.parseFormValues(\n values,\n ) as CostCalculatorEstimationSubmitValues;\n const costCalculatorResults =\n await costCalculatorBag?.onSubmit(cleanedValues);\n\n await onSubmit?.(cleanedValues);\n\n if (costCalculatorResults?.error) {\n onError?.(costCalculatorResults.error);\n } else {\n if (costCalculatorResults?.data) {\n await onSuccess?.(costCalculatorResults?.data);\n if (shouldResetForm) {\n costCalculatorBag?.resetForm();\n form.reset();\n }\n }\n }\n };\n\n return (\n <Form {...form}>\n <form\n id={formId}\n onSubmit={form.handleSubmit(handleSubmit)}\n className=\"space-y-4 RemoteFlows__CostCalculatorForm\"\n >\n <JSONSchemaFormFields fields={costCalculatorBag?.fields ?? []} />\n </form>\n </Form>\n );\n}\n"],"mappings":"gKAuEQ,cAAAA,MAAA,oBArCD,SAASC,EAAmB,CACjC,SAAAC,EACA,QAAAC,EACA,UAAAC,EACA,gBAAAC,CACF,EAA4B,CAC1B,GAAM,CAAE,KAAAC,EAAM,OAAAC,EAAQ,kBAAAC,CAAkB,EAAIC,EAAyB,EAE/DC,EAAeC,EAAA,MAAOC,GAA+C,CACzE,IAAMC,EAAgBL,GAAmB,gBACvCI,CACF,EACME,EACJ,MAAMN,GAAmB,SAASK,CAAa,EAEjD,MAAMX,IAAWW,CAAa,EAE1BC,GAAuB,MACzBX,IAAUW,EAAsB,KAAK,EAEjCA,GAAuB,OACzB,MAAMV,IAAYU,GAAuB,IAAI,EACzCT,IACFG,GAAmB,UAAU,EAC7BF,EAAK,MAAM,GAInB,EApBqB,gBAsBrB,OACEN,EAACe,EAAA,CAAM,GAAGT,EACR,SAAAN,EAAC,QACC,GAAIO,EACJ,SAAUD,EAAK,aAAaI,CAAY,EACxC,UAAU,4CAEV,SAAAV,EAACgB,EAAA,CAAqB,OAAQR,GAAmB,QAAU,CAAC,EAAG,EACjE,EACF,CAEJ,CAzCgBG,EAAAV,EAAA","names":["jsx","CostCalculatorForm","onSubmit","onError","onSuccess","shouldResetForm","form","formId","costCalculatorBag","useCostCalculatorContext","handleSubmit","__name","values","cleanedValues","costCalculatorResults","Form","JSONSchemaFormFields"]}
|