@remoteoss/remote-flows 0.4.0-alpha.21 → 0.4.0-alpha.22

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.
@@ -0,0 +1,2 @@
1
+ import{a as k}from"./chunk-ARYI3WUN.js";import{a as L}from"./chunk-UPRUP24B.js";import{a as x,b as A,c as v,e as T}from"./chunk-Q23DM4O3.js";import{a as J}from"./chunk-CFIJKJXD.js";import{c as g}from"./chunk-MH6KKP6K.js";import{a as o}from"./chunk-P37U34EQ.js";import{object as le}from"yup";import{createHeadlessForm as oe,modify as ie}from"@remoteoss/json-schema-form";import{useMemo as ne,useState as P}from"react";import{string as q,ValidationError as G}from"yup";import{jsx as ae}from"react/jsx-runtime";var j={title:"Estimation",includeBenefits:!1,includeCostBreakdowns:!1,includePremiumBenefits:!1,enableCurrencyConversion:!1},se=o(t=>{let{schema:i}=ie(L.data.schema,t?.jsfModify||{});return oe(i)},"useStaticSchema"),Se=o(({defaultRegion:t,estimationOptions:i,options:a}={estimationOptions:j})=>{let[l,c]=P(t),[f,p]=P(),[M,H]=P(),{data:C,isLoading:I}=x({includePremiumBenefits:i.includePremiumBenefits}),{data:E,isLoading:N}=A(),z=l||f?.value,{data:S,isLoading:D}=T(z,{includePremiumBenefits:i.includePremiumBenefits,options:a}),B=v(),w=f?.currency,u=a?.jsfModify?.fields?.salary,y=u&&typeof u=="object"&&"presentation"in u?u.presentation:void 0,K=ne(()=>({fields:{salary:{...u,presentation:{salary_conversion_properties:{label:y?.salary_conversion_properties?.label,description:y?.salary_conversion_properties?.description},currencies:{from:w,to:M},Component:o(e=>ae(k,{...e}),"Component")}}}}),[w,M,u,y?.salary_conversion_properties?.description,y?.salary_conversion_properties?.label]),d=se({jsfModify:{fields:{...a?.jsfModify?.fields,...K?.fields}}});async function Q(e){try{await b.validate(e,{abortEarly:!1})}catch(r){return{data:null,error:r}}return new Promise((r,n)=>{B.mutate($(e,i),{onSuccess:o(s=>{s.data?r({data:s.data,error:null}):r({data:null,error:new Error("Something went wrong. Please try again later.")})},"onSuccess"),onError:o(s=>{n({data:null,error:s})},"onError")})})}o(Q,"onSubmit");function W(e){let r=C?.find(({value:n})=>n===e);r&&r.childRegions.length===0&&r.hasAdditionalFields?c(r.regionSlug):c(void 0),p(r)}o(W,"onCountryChange");function X(e){c(e)}o(X,"onRegionChange");function Y(e){let r=E?.find(n=>n.value===e)?.label;H(r)}o(Y,"onChangeCurrency");let m=d.fields.find(e=>e.name==="region");if(m){let e=f?.childRegions.map(r=>({value:r.slug,label:r.name}))??[];m.options=e,m.isVisible=e.length>0,m.required=e.length>0,m.onChange=X,m.schema=e.length>0?q().transform(r=>typeof r=="string"?r:"").required("Region is required"):q()}if(E){let e=d.fields.find(r=>r.name==="currency");e&&(e.options=E,e.onChange=Y)}if(C){let e=d.fields.find(r=>r.name==="country");e&&(e.options=C,e.onChange=W)}let Z=o(()=>{p(void 0),c(t)},"resetForm"),O=[...d.fields,...S?.fields||[]],b=U(d.fields);async function ee(e){let r=null,n=g(e,O);try{await b.validate(n,{abortEarly:!1}),r={formErrors:{},yupError:new G([],e)}}catch(F){let V=J(F);r={formErrors:Object.entries(V).reduce((R,[re,te])=>({...R,[re]:te.message}),{}),yupError:F}}let s=S?.handleValidation(n),h=[...r?.yupError.inner||[],...s?.yupError?.inner||[]],_={...r?.yupError?.value||{},...s?.yupError?.value||{}};return{formErrors:{...r?.formErrors||{},...s?.formErrors||{}},yupError:new G(h,_)}}return o(ee,"handleValidation"),{stepState:{current:0,total:1,isLastStep:!0},fields:O,validationSchema:b,parseFormValues:o(e=>{let{country:r,region:n,salary:s,currency:h,..._}=e,V=g({country:r,region:n,salary:s,currency:h},d.fields),R=g(_,S?.fields||[]);return{...V,...R}},"parseFormValues"),handleValidation:ee,isSubmitting:B.isPending,isLoading:I&&N&&D,onSubmit:Q,resetForm:Z}},"useCostCalculator");function U(t){let i=t.reduce((a,l)=>(a[l.name]=l.schema,a),{});return le(i)}o(U,"buildValidationSchema");function ce(t){let i="benefit-";return Object.keys(t).reduce((a,l)=>{let c=t[l];if(c==="none")return a;let p={benefit_group_slug:l.replace(i,""),benefit_tier_slug:c};return[...a,p]},[])}o(ce,"formatBenefits");function $(t,i=j){return{employer_currency_slug:t.currency,include_benefits:i.includeBenefits,include_cost_breakdowns:i.includeCostBreakdowns,include_premium_benefits:i.includePremiumBenefits,employments:[{region_slug:t.region||t.country,annual_gross_salary:t.salary,annual_gross_salary_in_employer_currency:t.salary,employment_term:t.contract_duration_type??"fixed",title:i.title,age:t.age??void 0,...t.benefits&&{benefits:ce(t.benefits)}}]}}o($,"buildPayload");export{U as a,$ as b,j as c,Se as d};
2
+ //# sourceMappingURL=chunk-7NBID3JL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/flows/CostCalculator/utils.ts","../src/flows/CostCalculator/hooks.tsx"],"sourcesContent":["import type { CostCalculatorEstimateParams } from '@/src/client';\n\nimport { $TSFixMe } from '@/src/types/remoteFlows';\nimport { AnyObjectSchema, object } from 'yup';\nimport { defaultEstimationOptions } from './hooks';\nimport type {\n CostCalculatorEstimationOptions,\n CostCalculatorEstimationSubmitValues,\n} from './types';\n\n/**\n * Build the validation schema for the form.\n * @returns\n */\nexport function buildValidationSchema(fields: $TSFixMe[]) {\n const fieldsSchema = fields.reduce<Record<string, AnyObjectSchema>>(\n (fieldsSchemaAcc, field) => {\n fieldsSchemaAcc[field.name] = field.schema as AnyObjectSchema;\n return fieldsSchemaAcc;\n },\n {},\n );\n return object(fieldsSchema) as AnyObjectSchema;\n}\n\n/**\n * Format the benefits to the expected format by the API.\n * @param benefits\n * @returns\n */\nfunction formatBenefits(benefits: Record<string, string>) {\n const needle = 'benefit-';\n return Object.keys(benefits).reduce<\n Array<{ benefit_group_slug: string; benefit_tier_slug: string }>\n >((acc, key) => {\n const benefitTierSlug = benefits[key];\n if (benefitTierSlug === 'none') {\n return acc;\n }\n const benefitGroupSlug = key.replace(needle, '');\n const benefitEntry = {\n benefit_group_slug: benefitGroupSlug,\n benefit_tier_slug: benefitTierSlug,\n };\n return [...acc, benefitEntry];\n }, []);\n}\n\n/**\n * Build the payload for the cost calculator estimation.\n * @param values\n * @param estimationOptions\n * @returns\n */\nexport function buildPayload(\n values: CostCalculatorEstimationSubmitValues,\n estimationOptions: CostCalculatorEstimationOptions = defaultEstimationOptions,\n): CostCalculatorEstimateParams {\n return {\n employer_currency_slug: values.currency,\n include_benefits: estimationOptions.includeBenefits,\n include_cost_breakdowns: estimationOptions.includeCostBreakdowns,\n include_premium_benefits: estimationOptions.includePremiumBenefits,\n employments: [\n {\n region_slug: values.region || values.country,\n annual_gross_salary: values.salary,\n annual_gross_salary_in_employer_currency: values.salary,\n employment_term: values.contract_duration_type ?? 'fixed',\n title: estimationOptions.title,\n age: values.age ?? undefined,\n ...(values.benefits && { benefits: formatBenefits(values.benefits) }),\n },\n ],\n };\n}\n","import {\n CostCalculatorEstimateResponse,\n MinimalRegion,\n PostCreateEstimationError,\n} from '@/src/client';\nimport { jsonSchema } from '@/src/flows/CostCalculator/jsonSchema';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\n CostCalculatorEstimationSubmitValues,\n} from '@/src/flows/CostCalculator/types';\nimport type { JSFModify, Result } from '@/src/flows/types';\n\nimport { parseJSFToValidate } from '@/src/components/form/utils';\nimport { iterateErrors } from '@/src/components/form/yupValidationResolver';\nimport { createHeadlessForm, modify } from '@remoteoss/json-schema-form';\nimport { useMemo, useState } from 'react';\nimport { string, ValidationError } from 'yup';\nimport { buildPayload, buildValidationSchema } from './utils';\nimport {\n useCompanyCurrencies,\n useCostCalculatorCountries,\n useCostCalculatorEstimation,\n useRegionFields,\n} from '@/src/flows/CostCalculator/api';\nimport { JSFField } from '@/src/types/remoteFlows';\nimport { SalaryField } from '@/src/flows/CostCalculator/components/SalaryField';\n\ntype CostCalculatorCountry = {\n value: string;\n label: string;\n childRegions: MinimalRegion[];\n hasAdditionalFields: boolean | undefined;\n regionSlug: string;\n currency: string;\n};\n\ntype JSFValidationError = {\n formErrors: Record<\n string,\n {\n type: string;\n message: string;\n }\n >;\n yupError: ValidationError;\n};\n\nexport const defaultEstimationOptions: CostCalculatorEstimationOptions = {\n title: 'Estimation',\n includeBenefits: false,\n includeCostBreakdowns: false,\n includePremiumBenefits: false,\n enableCurrencyConversion: false,\n};\n\ntype UseCostCalculatorParams = {\n /**\n * The default region slug to preselect a country and a region.\n */\n defaultRegion?: string;\n /**\n * The estimation options.\n */\n estimationOptions: CostCalculatorEstimationOptions;\n options?: {\n jsfModify?: JSFModify;\n };\n};\n\nexport type EstimationError = PostCreateEstimationError | ValidationError;\n\nconst useStaticSchema = (options?: { jsfModify?: JSFModify }) => {\n const { schema: jsonSchemaModified } = modify(\n jsonSchema.data.schema,\n options?.jsfModify || {},\n );\n\n return createHeadlessForm(jsonSchemaModified);\n};\n\n/**\n * Hook to use the cost calculator.\n */\nexport const useCostCalculator = (\n { defaultRegion, estimationOptions, options }: UseCostCalculatorParams = {\n estimationOptions: defaultEstimationOptions,\n },\n) => {\n const [selectedRegion, setSelectedRegion] = useState<string | undefined>(\n defaultRegion,\n );\n const [selectedCountry, setSelectedCountry] =\n useState<CostCalculatorCountry>();\n const [employerBillingCurrency, setEmployerBillingCurrency] = useState<\n string | undefined\n >();\n const { data: countries, isLoading: isLoadingCountries } =\n useCostCalculatorCountries({\n includePremiumBenefits: estimationOptions.includePremiumBenefits,\n });\n const { data: currencies, isLoading: isLoadingCurrencies } =\n useCompanyCurrencies();\n\n const jsonSchemaRegionSlug = selectedRegion || selectedCountry?.value;\n\n const { data: jsonSchemaRegionFields, isLoading: isLoadingRegionFields } =\n useRegionFields(jsonSchemaRegionSlug, {\n includePremiumBenefits: estimationOptions.includePremiumBenefits,\n options,\n });\n const costCalculatorEstimationMutation = useCostCalculatorEstimation();\n const employeeBillingCurrency = selectedCountry?.currency;\n\n const salaryField = options?.jsfModify?.fields?.salary;\n const salaryFieldPresentation =\n salaryField &&\n typeof salaryField === 'object' &&\n 'presentation' in salaryField\n ? (\n salaryField as {\n presentation?: {\n salary_conversion_properties?: {\n label?: string;\n description?: string;\n };\n };\n }\n ).presentation\n : undefined;\n\n const customFields = useMemo(() => {\n return {\n fields: {\n salary: {\n ...salaryField,\n presentation: {\n salary_conversion_properties: {\n label:\n salaryFieldPresentation?.salary_conversion_properties?.label,\n description:\n salaryFieldPresentation?.salary_conversion_properties\n ?.description,\n },\n currencies: {\n from: employeeBillingCurrency,\n to: employerBillingCurrency,\n },\n Component: (\n props: JSFField & { currencies: { from: string; to: string } },\n ) => {\n return <SalaryField {...props} />;\n },\n },\n },\n },\n };\n }, [\n employeeBillingCurrency,\n employerBillingCurrency,\n salaryField,\n salaryFieldPresentation?.salary_conversion_properties?.description,\n salaryFieldPresentation?.salary_conversion_properties?.label,\n ]);\n\n const fieldsJSONSchema = useStaticSchema({\n jsfModify: {\n fields: {\n ...options?.jsfModify?.fields,\n ...customFields?.fields,\n },\n },\n });\n\n /**\n * Submit the estimation form with the given values.\n * @param values\n */\n async function onSubmit(\n values: CostCalculatorEstimationSubmitValues,\n ): Promise<Result<CostCalculatorEstimateResponse, EstimationError>> {\n try {\n await validationSchema.validate(values, { abortEarly: false });\n } catch (err) {\n return {\n data: null,\n error: err as ValidationError,\n };\n }\n\n return new Promise((resolve, reject) => {\n costCalculatorEstimationMutation.mutate(\n buildPayload(values, estimationOptions),\n {\n onSuccess: (response) => {\n if (response.data) {\n resolve({\n data: response.data,\n error: null,\n });\n } else {\n resolve({\n data: null,\n error: new Error(\n 'Something went wrong. Please try again later.',\n ),\n });\n }\n },\n onError: (error) => {\n reject({\n data: null,\n error: error as PostCreateEstimationError,\n });\n },\n },\n );\n });\n }\n\n /**\n * If the selected country has no child regions and has additional fields,\n * set the current region to the country's region slug and fetch the region fields.\n * @param country\n */\n function onCountryChange(country: string) {\n const currentCountry = countries?.find(({ value }) => value === country);\n\n if (\n currentCountry &&\n currentCountry.childRegions.length === 0 &&\n currentCountry.hasAdditionalFields\n ) {\n setSelectedRegion(currentCountry.regionSlug);\n } else {\n setSelectedRegion(undefined);\n }\n setSelectedCountry(currentCountry);\n }\n\n /**\n * Update the selected region and fetch the region fields.\n * @param region\n */\n function onRegionChange(region: string) {\n setSelectedRegion(region);\n }\n\n function onChangeCurrency(currency: string) {\n const selectedCurrency = currencies?.find(\n (c) => c.value === currency,\n )?.label;\n setEmployerBillingCurrency(selectedCurrency);\n }\n\n const regionField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'region',\n );\n\n if (regionField) {\n const regions =\n selectedCountry?.childRegions.map((region) => ({\n value: region.slug,\n label: region.name,\n })) ?? [];\n regionField.options = regions;\n regionField.isVisible = regions.length > 0;\n regionField.required = regions.length > 0;\n regionField.onChange = onRegionChange;\n regionField.schema =\n regions.length > 0\n ? string()\n .transform((value) => (typeof value === 'string' ? value : ''))\n .required('Region is required')\n : string();\n }\n\n if (currencies) {\n const currencyField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'currency',\n );\n if (currencyField) {\n currencyField.options = currencies;\n currencyField.onChange = onChangeCurrency;\n }\n }\n\n if (countries) {\n const countryField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'country',\n );\n if (countryField) {\n countryField.options = countries;\n countryField.onChange = onCountryChange;\n }\n }\n\n const resetForm = () => {\n setSelectedCountry(undefined);\n setSelectedRegion(defaultRegion);\n };\n\n const allFields = [\n ...fieldsJSONSchema.fields,\n ...(jsonSchemaRegionFields?.fields || []),\n ];\n\n const validationSchema = buildValidationSchema(fieldsJSONSchema.fields);\n\n async function handleValidation(values: CostCalculatorEstimationFormValues) {\n let errors: JSFValidationError | null = null;\n\n const parsedValues = parseJSFToValidate(values, allFields);\n\n // 1. validate static fields first using Yup validate function\n try {\n await validationSchema.validate(parsedValues, {\n abortEarly: false,\n });\n errors = {\n formErrors: {},\n yupError: new ValidationError([], values),\n };\n } catch (error) {\n const iterateResult = iterateErrors(error as ValidationError);\n\n errors = {\n // convert the errors to a format that can be used in the form\n formErrors: Object.entries(iterateResult).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: value.message }),\n {},\n ),\n yupError: error as ValidationError,\n };\n }\n\n // 2. validate json schema fields using the handleValidation (from json-schema-form)\n const handleValidationResult =\n jsonSchemaRegionFields?.handleValidation(parsedValues);\n\n // 3. combine the errors from both validations\n const combinedInnerErrors = [\n ...(errors?.yupError.inner || []),\n ...(handleValidationResult?.yupError?.inner || []),\n ];\n const combinedValues = {\n ...(errors?.yupError?.value || {}),\n ...(handleValidationResult?.yupError?.value || {}),\n };\n\n return {\n formErrors: {\n ...(errors?.formErrors || {}),\n ...(handleValidationResult?.formErrors || {}),\n },\n yupError: new ValidationError(combinedInnerErrors, combinedValues),\n };\n }\n\n return {\n stepState: {\n current: 0,\n total: 1,\n isLastStep: true,\n },\n fields: allFields,\n validationSchema,\n parseFormValues: (\n values: CostCalculatorEstimationFormValues,\n ): CostCalculatorEstimationSubmitValues => {\n const { country, region, salary, currency, ...rest } = values;\n const jsonSchemaStaticFieldValues = {\n country,\n region,\n salary,\n currency,\n };\n const parsedStaticFields = parseJSFToValidate(\n jsonSchemaStaticFieldValues,\n fieldsJSONSchema.fields,\n );\n\n const parsedRegionFields = parseJSFToValidate(\n rest,\n jsonSchemaRegionFields?.fields || [],\n );\n\n return {\n ...parsedStaticFields,\n ...parsedRegionFields,\n } as CostCalculatorEstimationSubmitValues;\n },\n handleValidation,\n isSubmitting: costCalculatorEstimationMutation.isPending,\n isLoading:\n isLoadingCountries && isLoadingCurrencies && isLoadingRegionFields,\n onSubmit,\n resetForm,\n };\n};\n"],"mappings":"qQAGA,OAA0B,UAAAA,OAAc,MCYxC,OAAS,sBAAAC,GAAoB,UAAAC,OAAc,8BAC3C,OAAS,WAAAC,GAAS,YAAAC,MAAgB,QAClC,OAAS,UAAAC,EAAQ,mBAAAC,MAAuB,MAsInB,cAAAC,OAAA,oBAvGd,IAAMC,EAA4D,CACvE,MAAO,aACP,gBAAiB,GACjB,sBAAuB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EAAIA,EAAM,OAC7BD,GAET,CAAC,CACH,EACA,OAAOE,GAAOH,CAAY,CAC5B,CATgBI,EAAAN,EAAA,yBAgBhB,SAASO,GAAeC,EAAkC,CACxD,IAAMC,EAAS,WACf,OAAO,OAAO,KAAKD,CAAQ,EAAE,OAE3B,CAACE,EAAKC,IAAQ,CACd,IAAMC,EAAkBJ,EAASG,CAAG,EACpC,GAAIC,IAAoB,OACtB,OAAOF,EAGT,IAAMG,EAAe,CACnB,mBAFuBF,EAAI,QAAQF,EAAQ,EAAE,EAG7C,kBAAmBG,CACrB,EACA,MAAO,CAAC,GAAGF,EAAKG,CAAY,CAC9B,EAAG,CAAC,CAAC,CACP,CAhBSP,EAAAC,GAAA,kBAwBF,SAASO,EACdC,EACAC,EAAqDC,EACvB,CAC9B,MAAO,CACL,uBAAwBF,EAAO,SAC/B,iBAAkBC,EAAkB,gBACpC,wBAAyBA,EAAkB,sBAC3C,yBAA0BA,EAAkB,uBAC5C,YAAa,CACX,CACE,YAAaD,EAAO,QAAUA,EAAO,QACrC,oBAAqBA,EAAO,OAC5B,yCAA0CA,EAAO,OACjD,gBAAiBA,EAAO,wBAA0B,QAClD,MAAOC,EAAkB,MACzB,IAAKD,EAAO,KAAO,OACnB,GAAIA,EAAO,UAAY,CAAE,SAAUR,GAAeQ,EAAO,QAAQ,CAAE,CACrE,CACF,CACF,CACF,CArBgBT,EAAAQ,EAAA","names":["object","createHeadlessForm","modify","useMemo","useState","string","ValidationError","jsx","defaultEstimationOptions","useStaticSchema","__name","options","jsonSchemaModified","modify","jsonSchema","createHeadlessForm","useCostCalculator","defaultRegion","estimationOptions","selectedRegion","setSelectedRegion","useState","selectedCountry","setSelectedCountry","employerBillingCurrency","setEmployerBillingCurrency","countries","isLoadingCountries","useCostCalculatorCountries","currencies","isLoadingCurrencies","useCompanyCurrencies","jsonSchemaRegionSlug","jsonSchemaRegionFields","isLoadingRegionFields","useRegionFields","costCalculatorEstimationMutation","useCostCalculatorEstimation","employeeBillingCurrency","salaryField","salaryFieldPresentation","customFields","useMemo","props","SalaryField","fieldsJSONSchema","onSubmit","values","validationSchema","err","resolve","reject","buildPayload","response","error","onCountryChange","country","currentCountry","value","onRegionChange","region","onChangeCurrency","currency","selectedCurrency","c","regionField","field","regions","string","currencyField","countryField","resetForm","allFields","buildValidationSchema","handleValidation","errors","parsedValues","parseJSFToValidate","ValidationError","iterateResult","iterateErrors","acc","key","handleValidationResult","combinedInnerErrors","combinedValues","salary","rest","parsedStaticFields","parsedRegionFields","buildValidationSchema","fields","fieldsSchema","fieldsSchemaAcc","field","object","__name","formatBenefits","benefits","needle","acc","key","benefitTierSlug","benefitEntry","buildPayload","values","estimationOptions","defaultEstimationOptions"]}
@@ -1,2 +1,2 @@
1
- import{a as l}from"./chunk-KSHK3ZPX.js";import{c as s,d as e}from"./chunk-3IE2B2UE.js";import{b as a}from"./chunk-CFIJKJXD.js";import{a as r}from"./chunk-P37U34EQ.js";import{useId as g}from"react";import{useForm as p}from"react-hook-form";import{jsx as y}from"react/jsx-runtime";var P=r(({estimationOptions:n=s,defaultValues:o={countryRegionSlug:"",currencySlug:"",salary:""},options:i,render:u})=>{let c=g(),t=e({defaultRegion:o.countryRegionSlug,estimationOptions:n,options:i}),m=a(t.handleValidation),C=p({resolver:m,defaultValues:{country:o?.countryRegionSlug,currency:o?.currencySlug,region:"",salary:o?.salary},shouldUnregister:!1,mode:"onBlur"});return y(l.Provider,{value:{form:C,formId:c,costCalculatorBag:t},children:u(t)})},"CostCalculatorFlow");export{P as a};
2
- //# sourceMappingURL=chunk-6653VQAG.js.map
1
+ import{a as l}from"./chunk-KSHK3ZPX.js";import{c as s,d as e}from"./chunk-7NBID3JL.js";import{b as a}from"./chunk-CFIJKJXD.js";import{a as r}from"./chunk-P37U34EQ.js";import{useId as g}from"react";import{useForm as p}from"react-hook-form";import{jsx as y}from"react/jsx-runtime";var P=r(({estimationOptions:n=s,defaultValues:o={countryRegionSlug:"",currencySlug:"",salary:""},options:i,render:u})=>{let c=g(),t=e({defaultRegion:o.countryRegionSlug,estimationOptions:n,options:i}),m=a(t.handleValidation),C=p({resolver:m,defaultValues:{country:o?.countryRegionSlug,currency:o?.currencySlug,region:"",salary:o?.salary},shouldUnregister:!1,mode:"onBlur"});return y(l.Provider,{value:{form:C,formId:c,costCalculatorBag:t},children:u(t)})},"CostCalculatorFlow");export{P as a};
2
+ //# sourceMappingURL=chunk-LFLO2IJA.js.map
@@ -1,2 +1,2 @@
1
- import{a}from"../../chunk-6653VQAG.js";import"../../chunk-KSHK3ZPX.js";import"../../chunk-3IE2B2UE.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{a as CostCalculatorFlow};
1
+ import{a}from"../../chunk-LFLO2IJA.js";import"../../chunk-KSHK3ZPX.js";import"../../chunk-7NBID3JL.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{a as CostCalculatorFlow};
2
2
  //# sourceMappingURL=CostCalculatorFlow.js.map
@@ -1,2 +1,2 @@
1
- import{c as a,d as b}from"../../chunk-3IE2B2UE.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{a as defaultEstimationOptions,b as useCostCalculator};
1
+ import{c as a,d as b}from"../../chunk-7NBID3JL.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{a as defaultEstimationOptions,b as useCostCalculator};
2
2
  //# sourceMappingURL=hooks.js.map
@@ -1,2 +1,2 @@
1
- import"../../chunk-YJXRJTOH.js";import{a as j}from"../../chunk-MNO47WC2.js";import"../../chunk-WIRFNWEU.js";import"../../chunk-3NZ6PO4D.js";import"../../chunk-YO4OQIFP.js";import"../../chunk-32RYPLZK.js";import"../../chunk-PJCUSCO4.js";import"../../chunk-EEAMZPP6.js";import"../../chunk-FB5J7SRP.js";import{a as e}from"../../chunk-DOLJU76M.js";import{a as g}from"../../chunk-3HPG2L62.js";import{a as f}from"../../chunk-KM4XVL2X.js";import{a as i}from"../../chunk-EV5YPN4F.js";import{a as h}from"../../chunk-DYB3RWP7.js";import{a as d}from"../../chunk-6653VQAG.js";import"../../chunk-KSHK3ZPX.js";import{b as a,d as c}from"../../chunk-3IE2B2UE.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import{d as b}from"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-3BIRQAED.js";import"../../chunk-XO3JWN33.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-GEYFQVQI.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.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};
1
+ import"../../chunk-YJXRJTOH.js";import{a as j}from"../../chunk-MNO47WC2.js";import"../../chunk-WIRFNWEU.js";import"../../chunk-3NZ6PO4D.js";import"../../chunk-YO4OQIFP.js";import"../../chunk-32RYPLZK.js";import"../../chunk-PJCUSCO4.js";import"../../chunk-EEAMZPP6.js";import"../../chunk-FB5J7SRP.js";import{a as e}from"../../chunk-DOLJU76M.js";import{a as g}from"../../chunk-3HPG2L62.js";import{a as f}from"../../chunk-KM4XVL2X.js";import{a as i}from"../../chunk-EV5YPN4F.js";import{a as h}from"../../chunk-DYB3RWP7.js";import{a as d}from"../../chunk-LFLO2IJA.js";import"../../chunk-KSHK3ZPX.js";import{b as a,d as c}from"../../chunk-7NBID3JL.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import{d as b}from"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-3BIRQAED.js";import"../../chunk-XO3JWN33.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-GEYFQVQI.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.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
@@ -1,2 +1,2 @@
1
- import{a,b}from"../../chunk-3IE2B2UE.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{b as buildPayload,a as buildValidationSchema};
1
+ import{a,b}from"../../chunk-7NBID3JL.js";import"../../chunk-ARYI3WUN.js";import"../../chunk-UPRUP24B.js";import"../../chunk-XMDNHTKE.js";import"../../chunk-XKSOWDLS.js";import"../../chunk-WVJDCDGZ.js";import"../../chunk-Q23DM4O3.js";import"../../chunk-PWUYHFON.js";import"../../chunk-WKK63LAY.js";import"../../chunk-CFIJKJXD.js";import"../../chunk-N6NYXAXH.js";import"../../chunk-3ZWDIEEM.js";import"../../chunk-VNSF5IOL.js";import"../../chunk-MH6KKP6K.js";import"../../chunk-KPHSEIR3.js";import"../../chunk-P37U34EQ.js";export{b as buildPayload,a as buildValidationSchema};
2
2
  //# sourceMappingURL=utils.js.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import"./chunk-M22FKNEY.js";import{a as tr}from"./chunk-ETMTVNOU.js";import"./chunk-LLIGZSYY.js";import"./chunk-JXCJLQRA.js";import"./chunk-WASEFJAE.js";import"./chunk-HSW5HMHH.js";import"./chunk-VX2UC3HG.js";import"./chunk-XSHHMBMT.js";import"./chunk-XFD3ULUF.js";import"./chunk-JODJFARP.js";import"./chunk-WWANHPT7.js";import"./chunk-W5DG5WWJ.js";import"./chunk-S4XU4SE7.js";import"./chunk-LFIQVLFK.js";import"./chunk-TNF6DNGM.js";import"./chunk-FCHRSRS6.js";import"./chunk-BF7QENCN.js";import"./chunk-O53436KO.js";import"./chunk-SIC7BRJ2.js";import"./chunk-MRYRNB7Y.js";import"./chunk-GULCZWSK.js";import{a as or}from"./chunk-YNQVZYFG.js";import"./chunk-7TOZZQQJ.js";import"./chunk-CEIK7DGY.js";import"./chunk-3R33SVSF.js";import"./chunk-ISOKYXYN.js";import"./chunk-LPR2D3EY.js";import"./chunk-MSBG52WO.js";import"./chunk-63BYEK44.js";import"./chunk-7ZH23EMZ.js";import"./chunk-FUIQ7D6L.js";import"./chunk-KFVOK5X5.js";import"./chunk-PGWKJ6FK.js";import"./chunk-MNFM2TNK.js";import"./chunk-MO7KC4HE.js";import"./chunk-XIPPSRO6.js";import"./chunk-YJXRJTOH.js";import{a as E}from"./chunk-MNO47WC2.js";import"./chunk-WIRFNWEU.js";import"./chunk-3NZ6PO4D.js";import"./chunk-YO4OQIFP.js";import"./chunk-32RYPLZK.js";import"./chunk-PJCUSCO4.js";import"./chunk-EEAMZPP6.js";import"./chunk-FB5J7SRP.js";import{a as R}from"./chunk-DOLJU76M.js";import{a as z}from"./chunk-3HPG2L62.js";import{a as T}from"./chunk-KM4XVL2X.js";import"./chunk-A7ZJQCNU.js";import{a as B}from"./chunk-EV5YPN4F.js";import{a as _}from"./chunk-DYB3RWP7.js";import{a as F}from"./chunk-6653VQAG.js";import"./chunk-KSHK3ZPX.js";import{b as y,d as P}from"./chunk-3IE2B2UE.js";import"./chunk-ARYI3WUN.js";import"./chunk-UPRUP24B.js";import"./chunk-XMDNHTKE.js";import"./chunk-XKSOWDLS.js";import"./chunk-WVJDCDGZ.js";import{d as k}from"./chunk-Q23DM4O3.js";import"./chunk-PWUYHFON.js";import{a as er}from"./chunk-EPLIVM3Y.js";import{a as H}from"./chunk-RXK4RLF6.js";import{a as ar}from"./chunk-AIEAUPO6.js";import{a as J,b as rr}from"./chunk-LX7QBDSF.js";import"./chunk-QW4JPW6J.js";import"./chunk-5SMMQQXP.js";import{a as p}from"./chunk-WKK63LAY.js";import"./chunk-PJBAQZ6G.js";import"./chunk-CTTXXEWI.js";import{a as G}from"./chunk-CSU6IQX3.js";import{a as Z}from"./chunk-3QGKRPQ6.js";import"./chunk-3BIRQAED.js";import"./chunk-XO3JWN33.js";import"./chunk-CFIJKJXD.js";import"./chunk-N6NYXAXH.js";import"./chunk-GEYFQVQI.js";import{a as g,c as v}from"./chunk-3ZWDIEEM.js";import"./chunk-VNSF5IOL.js";import"./chunk-MH6KKP6K.js";import"./chunk-TVZAFTPT.js";import{c as C}from"./chunk-KPHSEIR3.js";import{a as e}from"./chunk-P37U34EQ.js";import{QueryClient as L,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 S(r){let a={};return Object.keys(r).forEach(t=>{a[`--${t}`]=r[t]}),a}e(S,"mapThemeColors");function N(r){return{"--spacing":r}}e(N,"mapThemeSpacing");function O(r){return{"--radius":r}}e(O,"mapThemeBorderRadius");function j(r){return{"--fontSizeBase":r.fontSizeBase}}e(j,"mapThemeFont");function h(r){r?.colors&&l(S(r.colors)),r?.spacing&&l(N(r.spacing)),r?.borderRadius&&l(O(r.borderRadius)),r?.font&&l(j(r.font))}e(h,"applyTheme");import{createContext as D,useEffect as I,useMemo as A}from"react";import{jsx as V}from"react/jsx-runtime";var K=D({theme:{}});function u(r){I(()=>{r.theme&&Object.keys(r.theme).length>0&&h(r.theme)},[r.theme]);let a=A(()=>({theme:r.theme}),[r.theme]);return V(K.Provider,{value:a,children:r.children})}e(u,"ThemeProvider");var m={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 U}from"@hey-api/client-fetch";import{useQuery as W}from"@tanstack/react-query";import{useRef as w}from"react";function M(r){try{return new URL(r),!0}catch{return!1}}e(M,"isValidUrl");var f=e(({auth:r,options:a})=>{let t=w(null),{refetch:o}=W({queryKey:["auth"],queryFn:r,enabled:!1}),c=a?.environment?m[a?.environment]:"https://gateway.remote.com",s=p.getConfig(),x="0.4.0-alpha.21",d=!!a?.proxy&&M(a.proxy.url);return a?.proxy&&!d&&console.error("Invalid proxy URL provided. Using default base URL."),w(U({...s,headers:{...s.headers,...d?a?.proxy?.headers:{},"X-Client-Name":"remote-flows-sdk","X-Client-Version":x},baseUrl:d?a.proxy?.url:c,auth:e(async()=>{function b(i){return!i||Date.now()+6e4>i}if(e(b,"hasTokenExpired"),!t.current||b(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 Q=new L;function X({children:r,auth:a,proxy:t,environment:o}){let c=f({auth:a,options:{proxy:t,environment:o}});return n(v.Provider,{value:{client:c.current},children:r})}e(X,"RemoteFlowContextWrapper");function Y({children:r,components:a}){return n(g.Provider,{value:a?{components:a}:{components:{}},children:r})}e(Y,"FormFieldsProvider");function $({auth:r,children:a,components:t,theme:o,proxy:c,environment:s}){return n(q,{client:Q,children:n(Y,{components:t,children:n(X,{auth:r,proxy:c,environment:s,children:n(u,{theme:o,children:a})})})})}e($,"RemoteFlows");export{G as ContractAmendmentConfirmationForm,er as ContractAmendmentFlow,Z as ContractAmendmentForm,H as ContractAmendmentSubmit,B as CostCalculatorDisclaimer,F as CostCalculatorFlow,R as CostCalculatorForm,z as CostCalculatorResetButton,E as CostCalculatorResults,T as CostCalculatorSubmitButton,or as OnboardingFlow,$ as RemoteFlows,tr as TerminationFlow,y as buildCostCalculatorEstimationPayload,_ as disclaimerData,C as transformYupErrorsIntoObject,ar as useContractAmendment,P as useCostCalculator,k as useCostCalculatorEstimationPdf,J as useEmploymentQuery,rr as useTimeOffQuery};
1
+ import"./chunk-M22FKNEY.js";import{a as tr}from"./chunk-ETMTVNOU.js";import"./chunk-LLIGZSYY.js";import"./chunk-JXCJLQRA.js";import"./chunk-WASEFJAE.js";import"./chunk-HSW5HMHH.js";import"./chunk-VX2UC3HG.js";import"./chunk-XSHHMBMT.js";import"./chunk-XFD3ULUF.js";import"./chunk-JODJFARP.js";import"./chunk-WWANHPT7.js";import"./chunk-W5DG5WWJ.js";import"./chunk-S4XU4SE7.js";import"./chunk-LFIQVLFK.js";import"./chunk-TNF6DNGM.js";import"./chunk-FCHRSRS6.js";import"./chunk-BF7QENCN.js";import"./chunk-O53436KO.js";import"./chunk-SIC7BRJ2.js";import"./chunk-MRYRNB7Y.js";import"./chunk-GULCZWSK.js";import{a as or}from"./chunk-YNQVZYFG.js";import"./chunk-7TOZZQQJ.js";import"./chunk-CEIK7DGY.js";import"./chunk-3R33SVSF.js";import"./chunk-ISOKYXYN.js";import"./chunk-LPR2D3EY.js";import"./chunk-MSBG52WO.js";import"./chunk-63BYEK44.js";import"./chunk-7ZH23EMZ.js";import"./chunk-FUIQ7D6L.js";import"./chunk-KFVOK5X5.js";import"./chunk-PGWKJ6FK.js";import"./chunk-MNFM2TNK.js";import"./chunk-MO7KC4HE.js";import"./chunk-XIPPSRO6.js";import"./chunk-YJXRJTOH.js";import{a as E}from"./chunk-MNO47WC2.js";import"./chunk-WIRFNWEU.js";import"./chunk-3NZ6PO4D.js";import"./chunk-YO4OQIFP.js";import"./chunk-32RYPLZK.js";import"./chunk-PJCUSCO4.js";import"./chunk-EEAMZPP6.js";import"./chunk-FB5J7SRP.js";import{a as R}from"./chunk-DOLJU76M.js";import{a as z}from"./chunk-3HPG2L62.js";import{a as T}from"./chunk-KM4XVL2X.js";import"./chunk-A7ZJQCNU.js";import{a as B}from"./chunk-EV5YPN4F.js";import{a as _}from"./chunk-DYB3RWP7.js";import{a as F}from"./chunk-LFLO2IJA.js";import"./chunk-KSHK3ZPX.js";import{b as y,d as P}from"./chunk-7NBID3JL.js";import"./chunk-ARYI3WUN.js";import"./chunk-UPRUP24B.js";import"./chunk-XMDNHTKE.js";import"./chunk-XKSOWDLS.js";import"./chunk-WVJDCDGZ.js";import{d as k}from"./chunk-Q23DM4O3.js";import"./chunk-PWUYHFON.js";import{a as er}from"./chunk-EPLIVM3Y.js";import{a as H}from"./chunk-RXK4RLF6.js";import{a as ar}from"./chunk-AIEAUPO6.js";import{a as J,b as rr}from"./chunk-LX7QBDSF.js";import"./chunk-QW4JPW6J.js";import"./chunk-5SMMQQXP.js";import{a as p}from"./chunk-WKK63LAY.js";import"./chunk-PJBAQZ6G.js";import"./chunk-CTTXXEWI.js";import{a as G}from"./chunk-CSU6IQX3.js";import{a as Z}from"./chunk-3QGKRPQ6.js";import"./chunk-3BIRQAED.js";import"./chunk-XO3JWN33.js";import"./chunk-CFIJKJXD.js";import"./chunk-N6NYXAXH.js";import"./chunk-GEYFQVQI.js";import{a as g,c as v}from"./chunk-3ZWDIEEM.js";import"./chunk-VNSF5IOL.js";import"./chunk-MH6KKP6K.js";import"./chunk-TVZAFTPT.js";import{c as C}from"./chunk-KPHSEIR3.js";import{a as e}from"./chunk-P37U34EQ.js";import{QueryClient as L,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 S(r){let a={};return Object.keys(r).forEach(t=>{a[`--${t}`]=r[t]}),a}e(S,"mapThemeColors");function N(r){return{"--spacing":r}}e(N,"mapThemeSpacing");function O(r){return{"--radius":r}}e(O,"mapThemeBorderRadius");function j(r){return{"--fontSizeBase":r.fontSizeBase}}e(j,"mapThemeFont");function h(r){r?.colors&&l(S(r.colors)),r?.spacing&&l(N(r.spacing)),r?.borderRadius&&l(O(r.borderRadius)),r?.font&&l(j(r.font))}e(h,"applyTheme");import{createContext as D,useEffect as I,useMemo as A}from"react";import{jsx as V}from"react/jsx-runtime";var K=D({theme:{}});function u(r){I(()=>{r.theme&&Object.keys(r.theme).length>0&&h(r.theme)},[r.theme]);let a=A(()=>({theme:r.theme}),[r.theme]);return V(K.Provider,{value:a,children:r.children})}e(u,"ThemeProvider");var m={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 U}from"@hey-api/client-fetch";import{useQuery as W}from"@tanstack/react-query";import{useRef as w}from"react";function M(r){try{return new URL(r),!0}catch{return!1}}e(M,"isValidUrl");var f=e(({auth:r,options:a})=>{let t=w(null),{refetch:o}=W({queryKey:["auth"],queryFn:r,enabled:!1}),c=a?.environment?m[a?.environment]:"https://gateway.remote.com",s=p.getConfig(),x="0.4.0-alpha.22",d=!!a?.proxy&&M(a.proxy.url);return a?.proxy&&!d&&console.error("Invalid proxy URL provided. Using default base URL."),w(U({...s,headers:{...s.headers,...d?a?.proxy?.headers:{},"X-Client-Name":"remote-flows-sdk","X-Client-Version":x},baseUrl:d?a.proxy?.url:c,auth:e(async()=>{function b(i){return!i||Date.now()+6e4>i}if(e(b,"hasTokenExpired"),!t.current||b(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 Q=new L;function X({children:r,auth:a,proxy:t,environment:o}){let c=f({auth:a,options:{proxy:t,environment:o}});return n(v.Provider,{value:{client:c.current},children:r})}e(X,"RemoteFlowContextWrapper");function Y({children:r,components:a}){return n(g.Provider,{value:a?{components:a}:{components:{}},children:r})}e(Y,"FormFieldsProvider");function $({auth:r,children:a,components:t,theme:o,proxy:c,environment:s}){return n(q,{client:Q,children:n(Y,{components:t,children:n(X,{auth:r,proxy:c,environment:s,children:n(u,{theme:o,children:a})})})})}e($,"RemoteFlows");export{G as ContractAmendmentConfirmationForm,er as ContractAmendmentFlow,Z as ContractAmendmentForm,H as ContractAmendmentSubmit,B as CostCalculatorDisclaimer,F as CostCalculatorFlow,R as CostCalculatorForm,z as CostCalculatorResetButton,E as CostCalculatorResults,T as CostCalculatorSubmitButton,or as OnboardingFlow,$ as RemoteFlows,tr as TerminationFlow,y as buildCostCalculatorEstimationPayload,_ as disclaimerData,C as transformYupErrorsIntoObject,ar as useContractAmendment,P as useCostCalculator,k as useCostCalculatorEstimationPdf,J as useEmploymentQuery,rr as useTimeOffQuery};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/remote-flows",
3
- "version": "0.4.0-alpha.21",
3
+ "version": "0.4.0-alpha.22",
4
4
  "scripts": {
5
5
  "build": "NODE_ENV=production tsup",
6
6
  "ci": "npm run build && npm run check-format && npm run check-exports && npm run lint && npm run test",
@@ -1,2 +0,0 @@
1
- import{a as q}from"./chunk-ARYI3WUN.js";import{a as L}from"./chunk-UPRUP24B.js";import{a as x,b as A,c as v,e as k}from"./chunk-Q23DM4O3.js";import{a as J}from"./chunk-CFIJKJXD.js";import{c as y}from"./chunk-MH6KKP6K.js";import{a as o}from"./chunk-P37U34EQ.js";import{object as le}from"yup";import{createHeadlessForm as oe,modify as ie}from"@remoteoss/json-schema-form";import{useMemo as ne,useState as R}from"react";import{string as T,ValidationError as G}from"yup";import{jsx as ae}from"react/jsx-runtime";var P={title:"Estimation",includeBenefits:!1,includeCostBreakdowns:!1,includePremiumBenefits:!1,enableCurrencyConversion:!1},se=o(t=>{let{schema:i}=ie(L.data.schema,t?.jsfModify||{});return oe(i)},"useStaticSchema"),Se=o(({defaultRegion:t,estimationOptions:i,options:a}={estimationOptions:P})=>{let[l,m]=R(t),[f,j]=R(),[M,H]=R(),{data:g,isLoading:I}=x({includePremiumBenefits:i.includePremiumBenefits}),{data:C,isLoading:N}=A(),z=l||f?.value,{data:E,isLoading:D}=k(z,{includePremiumBenefits:i.includePremiumBenefits,options:a}),B=v(),w=f?.currency,c=a?.jsfModify?.fields?.salary,p=c&&typeof c=="object"&&"presentation"in c?c.presentation:void 0,K=ne(()=>({fields:{salary:{...c,presentation:{salary_conversion_properties:{label:p?.salary_conversion_properties?.label,description:p?.salary_conversion_properties?.description},currencies:{from:w,to:M},Component:o(e=>ae(q,{...e}),"Component")}}}}),[w,M,c,p?.salary_conversion_properties?.description,p?.salary_conversion_properties?.label]),u=se({jsfModify:{fields:{...a?.jsfModify?.fields,...K?.fields}}});async function Q(e){try{await S.validate(e,{abortEarly:!1})}catch(r){return{data:null,error:r}}return new Promise((r,n)=>{B.mutate($(e,i),{onSuccess:o(s=>{s.data?r({data:s.data,error:null}):r({data:null,error:new Error("Something went wrong. Please try again later.")})},"onSuccess"),onError:o(s=>{n({data:null,error:s})},"onError")})})}o(Q,"onSubmit");function W(e){let r=g?.find(({value:n})=>n===e);r&&r.childRegions.length===0&&r.hasAdditionalFields?m(r.regionSlug):m(void 0),j(r)}o(W,"onCountryChange");function X(e){m(e)}o(X,"onRegionChange");function Y(e){let r=C?.find(n=>n.value===e)?.label;H(r)}o(Y,"onChangeCurrency");let d=u.fields.find(e=>e.name==="region");if(d){let e=f?.childRegions.map(r=>({value:r.slug,label:r.name}))??[];d.options=e,d.isVisible=e.length>0,d.required=e.length>0,d.onChange=X,d.schema=e.length>0?T().transform(r=>typeof r=="string"?r:"").required("Region is required"):T()}if(C){let e=u.fields.find(r=>r.name==="currency");e&&(e.options=C,e.onChange=Y)}if(g){let e=u.fields.find(r=>r.name==="country");e&&(e.options=g,e.onChange=W)}let Z=o(()=>{j(void 0),m(t)},"resetForm"),O=[...u.fields,...E?.fields||[]],S=U(u.fields);async function ee(e){let r=null,n=y(e,O);try{await S.validate(n,{abortEarly:!1}),r={formErrors:{},yupError:new G([],e)}}catch(_){let F=J(_);r={formErrors:Object.entries(F).reduce((V,[re,te])=>({...V,[re]:te.message}),{}),yupError:_}}let s=E?.handleValidation(n),b=[...r?.yupError.inner||[],...s?.yupError?.inner||[]],h={...r?.yupError?.value||{},...s?.yupError?.value||{}};return{formErrors:{...r?.formErrors||{},...s?.formErrors||{}},yupError:new G(b,h)}}return o(ee,"handleValidation"),{stepState:{current:0,total:1,isLastStep:!0},fields:O,validationSchema:S,parseFormValues:o(e=>{let{country:r,region:n,salary:s,currency:b,...h}=e,F=y({country:r,region:n,salary:s,currency:b},u.fields),V=y(h,E?.fields||[]);return{...F,...V}},"parseFormValues"),handleValidation:ee,isSubmitting:B.isPending,isLoading:I&&N&&D,onSubmit:Q,resetForm:Z}},"useCostCalculator");function U(t){let i=t.reduce((a,l)=>(a[l.name]=l.schema,a),{});return le(i)}o(U,"buildValidationSchema");function ce(t){let i="benefit-";return Object.keys(t).reduce((a,l)=>{let f={benefit_group_slug:l.replace(i,""),benefit_tier_slug:t[l]};return[...a,f]},[])}o(ce,"formatBenefits");function $(t,i=P){return{employer_currency_slug:t.currency,include_benefits:i.includeBenefits,include_cost_breakdowns:i.includeCostBreakdowns,include_premium_benefits:i.includePremiumBenefits,employments:[{region_slug:t.region||t.country,annual_gross_salary:t.salary,annual_gross_salary_in_employer_currency:t.salary,employment_term:t.contract_duration_type??"fixed",title:i.title,age:t.age??void 0,...t.benefits&&{benefits:ce(t.benefits)}}]}}o($,"buildPayload");export{U as a,$ as b,P as c,Se as d};
2
- //# sourceMappingURL=chunk-3IE2B2UE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/flows/CostCalculator/utils.ts","../src/flows/CostCalculator/hooks.tsx"],"sourcesContent":["import type { CostCalculatorEstimateParams } from '@/src/client';\n\nimport { $TSFixMe } from '@/src/types/remoteFlows';\nimport { AnyObjectSchema, object } from 'yup';\nimport { defaultEstimationOptions } from './hooks';\nimport type {\n CostCalculatorEstimationOptions,\n CostCalculatorEstimationSubmitValues,\n} from './types';\n\n/**\n * Build the validation schema for the form.\n * @returns\n */\nexport function buildValidationSchema(fields: $TSFixMe[]) {\n const fieldsSchema = fields.reduce<Record<string, AnyObjectSchema>>(\n (fieldsSchemaAcc, field) => {\n fieldsSchemaAcc[field.name] = field.schema as AnyObjectSchema;\n return fieldsSchemaAcc;\n },\n {},\n );\n return object(fieldsSchema) as AnyObjectSchema;\n}\n\n/**\n * Format the benefits to the expected format by the API.\n * @param benefits\n * @returns\n */\nfunction formatBenefits(benefits: Record<string, string>) {\n const needle = 'benefit-';\n return Object.keys(benefits).reduce<\n Array<{ benefit_group_slug: string; benefit_tier_slug: string }>\n >((acc, key) => {\n const benefitGroupSlug = key.replace(needle, '');\n const benefitEntry = {\n benefit_group_slug: benefitGroupSlug,\n benefit_tier_slug: benefits[key],\n };\n return [...acc, benefitEntry];\n }, []);\n}\n\n/**\n * Build the payload for the cost calculator estimation.\n * @param values\n * @param estimationOptions\n * @returns\n */\nexport function buildPayload(\n values: CostCalculatorEstimationSubmitValues,\n estimationOptions: CostCalculatorEstimationOptions = defaultEstimationOptions,\n): CostCalculatorEstimateParams {\n return {\n employer_currency_slug: values.currency,\n include_benefits: estimationOptions.includeBenefits,\n include_cost_breakdowns: estimationOptions.includeCostBreakdowns,\n include_premium_benefits: estimationOptions.includePremiumBenefits,\n employments: [\n {\n region_slug: values.region || values.country,\n annual_gross_salary: values.salary,\n annual_gross_salary_in_employer_currency: values.salary,\n employment_term: values.contract_duration_type ?? 'fixed',\n title: estimationOptions.title,\n age: values.age ?? undefined,\n ...(values.benefits && { benefits: formatBenefits(values.benefits) }),\n },\n ],\n };\n}\n","import {\n CostCalculatorEstimateResponse,\n MinimalRegion,\n PostCreateEstimationError,\n} from '@/src/client';\nimport { jsonSchema } from '@/src/flows/CostCalculator/jsonSchema';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\n CostCalculatorEstimationSubmitValues,\n} from '@/src/flows/CostCalculator/types';\nimport type { JSFModify, Result } from '@/src/flows/types';\n\nimport { parseJSFToValidate } from '@/src/components/form/utils';\nimport { iterateErrors } from '@/src/components/form/yupValidationResolver';\nimport { createHeadlessForm, modify } from '@remoteoss/json-schema-form';\nimport { useMemo, useState } from 'react';\nimport { string, ValidationError } from 'yup';\nimport { buildPayload, buildValidationSchema } from './utils';\nimport {\n useCompanyCurrencies,\n useCostCalculatorCountries,\n useCostCalculatorEstimation,\n useRegionFields,\n} from '@/src/flows/CostCalculator/api';\nimport { JSFField } from '@/src/types/remoteFlows';\nimport { SalaryField } from '@/src/flows/CostCalculator/components/SalaryField';\n\ntype CostCalculatorCountry = {\n value: string;\n label: string;\n childRegions: MinimalRegion[];\n hasAdditionalFields: boolean | undefined;\n regionSlug: string;\n currency: string;\n};\n\ntype JSFValidationError = {\n formErrors: Record<\n string,\n {\n type: string;\n message: string;\n }\n >;\n yupError: ValidationError;\n};\n\nexport const defaultEstimationOptions: CostCalculatorEstimationOptions = {\n title: 'Estimation',\n includeBenefits: false,\n includeCostBreakdowns: false,\n includePremiumBenefits: false,\n enableCurrencyConversion: false,\n};\n\ntype UseCostCalculatorParams = {\n /**\n * The default region slug to preselect a country and a region.\n */\n defaultRegion?: string;\n /**\n * The estimation options.\n */\n estimationOptions: CostCalculatorEstimationOptions;\n options?: {\n jsfModify?: JSFModify;\n };\n};\n\nexport type EstimationError = PostCreateEstimationError | ValidationError;\n\nconst useStaticSchema = (options?: { jsfModify?: JSFModify }) => {\n const { schema: jsonSchemaModified } = modify(\n jsonSchema.data.schema,\n options?.jsfModify || {},\n );\n\n return createHeadlessForm(jsonSchemaModified);\n};\n\n/**\n * Hook to use the cost calculator.\n */\nexport const useCostCalculator = (\n { defaultRegion, estimationOptions, options }: UseCostCalculatorParams = {\n estimationOptions: defaultEstimationOptions,\n },\n) => {\n const [selectedRegion, setSelectedRegion] = useState<string | undefined>(\n defaultRegion,\n );\n const [selectedCountry, setSelectedCountry] =\n useState<CostCalculatorCountry>();\n const [employerBillingCurrency, setEmployerBillingCurrency] = useState<\n string | undefined\n >();\n const { data: countries, isLoading: isLoadingCountries } =\n useCostCalculatorCountries({\n includePremiumBenefits: estimationOptions.includePremiumBenefits,\n });\n const { data: currencies, isLoading: isLoadingCurrencies } =\n useCompanyCurrencies();\n\n const jsonSchemaRegionSlug = selectedRegion || selectedCountry?.value;\n\n const { data: jsonSchemaRegionFields, isLoading: isLoadingRegionFields } =\n useRegionFields(jsonSchemaRegionSlug, {\n includePremiumBenefits: estimationOptions.includePremiumBenefits,\n options,\n });\n const costCalculatorEstimationMutation = useCostCalculatorEstimation();\n const employeeBillingCurrency = selectedCountry?.currency;\n\n const salaryField = options?.jsfModify?.fields?.salary;\n const salaryFieldPresentation =\n salaryField &&\n typeof salaryField === 'object' &&\n 'presentation' in salaryField\n ? (\n salaryField as {\n presentation?: {\n salary_conversion_properties?: {\n label?: string;\n description?: string;\n };\n };\n }\n ).presentation\n : undefined;\n\n const customFields = useMemo(() => {\n return {\n fields: {\n salary: {\n ...salaryField,\n presentation: {\n salary_conversion_properties: {\n label:\n salaryFieldPresentation?.salary_conversion_properties?.label,\n description:\n salaryFieldPresentation?.salary_conversion_properties\n ?.description,\n },\n currencies: {\n from: employeeBillingCurrency,\n to: employerBillingCurrency,\n },\n Component: (\n props: JSFField & { currencies: { from: string; to: string } },\n ) => {\n return <SalaryField {...props} />;\n },\n },\n },\n },\n };\n }, [\n employeeBillingCurrency,\n employerBillingCurrency,\n salaryField,\n salaryFieldPresentation?.salary_conversion_properties?.description,\n salaryFieldPresentation?.salary_conversion_properties?.label,\n ]);\n\n const fieldsJSONSchema = useStaticSchema({\n jsfModify: {\n fields: {\n ...options?.jsfModify?.fields,\n ...customFields?.fields,\n },\n },\n });\n\n /**\n * Submit the estimation form with the given values.\n * @param values\n */\n async function onSubmit(\n values: CostCalculatorEstimationSubmitValues,\n ): Promise<Result<CostCalculatorEstimateResponse, EstimationError>> {\n try {\n await validationSchema.validate(values, { abortEarly: false });\n } catch (err) {\n return {\n data: null,\n error: err as ValidationError,\n };\n }\n\n return new Promise((resolve, reject) => {\n costCalculatorEstimationMutation.mutate(\n buildPayload(values, estimationOptions),\n {\n onSuccess: (response) => {\n if (response.data) {\n resolve({\n data: response.data,\n error: null,\n });\n } else {\n resolve({\n data: null,\n error: new Error(\n 'Something went wrong. Please try again later.',\n ),\n });\n }\n },\n onError: (error) => {\n reject({\n data: null,\n error: error as PostCreateEstimationError,\n });\n },\n },\n );\n });\n }\n\n /**\n * If the selected country has no child regions and has additional fields,\n * set the current region to the country's region slug and fetch the region fields.\n * @param country\n */\n function onCountryChange(country: string) {\n const currentCountry = countries?.find(({ value }) => value === country);\n\n if (\n currentCountry &&\n currentCountry.childRegions.length === 0 &&\n currentCountry.hasAdditionalFields\n ) {\n setSelectedRegion(currentCountry.regionSlug);\n } else {\n setSelectedRegion(undefined);\n }\n setSelectedCountry(currentCountry);\n }\n\n /**\n * Update the selected region and fetch the region fields.\n * @param region\n */\n function onRegionChange(region: string) {\n setSelectedRegion(region);\n }\n\n function onChangeCurrency(currency: string) {\n const selectedCurrency = currencies?.find(\n (c) => c.value === currency,\n )?.label;\n setEmployerBillingCurrency(selectedCurrency);\n }\n\n const regionField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'region',\n );\n\n if (regionField) {\n const regions =\n selectedCountry?.childRegions.map((region) => ({\n value: region.slug,\n label: region.name,\n })) ?? [];\n regionField.options = regions;\n regionField.isVisible = regions.length > 0;\n regionField.required = regions.length > 0;\n regionField.onChange = onRegionChange;\n regionField.schema =\n regions.length > 0\n ? string()\n .transform((value) => (typeof value === 'string' ? value : ''))\n .required('Region is required')\n : string();\n }\n\n if (currencies) {\n const currencyField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'currency',\n );\n if (currencyField) {\n currencyField.options = currencies;\n currencyField.onChange = onChangeCurrency;\n }\n }\n\n if (countries) {\n const countryField = fieldsJSONSchema.fields.find(\n (field) => field.name === 'country',\n );\n if (countryField) {\n countryField.options = countries;\n countryField.onChange = onCountryChange;\n }\n }\n\n const resetForm = () => {\n setSelectedCountry(undefined);\n setSelectedRegion(defaultRegion);\n };\n\n const allFields = [\n ...fieldsJSONSchema.fields,\n ...(jsonSchemaRegionFields?.fields || []),\n ];\n\n const validationSchema = buildValidationSchema(fieldsJSONSchema.fields);\n\n async function handleValidation(values: CostCalculatorEstimationFormValues) {\n let errors: JSFValidationError | null = null;\n\n const parsedValues = parseJSFToValidate(values, allFields);\n\n // 1. validate static fields first using Yup validate function\n try {\n await validationSchema.validate(parsedValues, {\n abortEarly: false,\n });\n errors = {\n formErrors: {},\n yupError: new ValidationError([], values),\n };\n } catch (error) {\n const iterateResult = iterateErrors(error as ValidationError);\n\n errors = {\n // convert the errors to a format that can be used in the form\n formErrors: Object.entries(iterateResult).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: value.message }),\n {},\n ),\n yupError: error as ValidationError,\n };\n }\n\n // 2. validate json schema fields using the handleValidation (from json-schema-form)\n const handleValidationResult =\n jsonSchemaRegionFields?.handleValidation(parsedValues);\n\n // 3. combine the errors from both validations\n const combinedInnerErrors = [\n ...(errors?.yupError.inner || []),\n ...(handleValidationResult?.yupError?.inner || []),\n ];\n const combinedValues = {\n ...(errors?.yupError?.value || {}),\n ...(handleValidationResult?.yupError?.value || {}),\n };\n\n return {\n formErrors: {\n ...(errors?.formErrors || {}),\n ...(handleValidationResult?.formErrors || {}),\n },\n yupError: new ValidationError(combinedInnerErrors, combinedValues),\n };\n }\n\n return {\n stepState: {\n current: 0,\n total: 1,\n isLastStep: true,\n },\n fields: allFields,\n validationSchema,\n parseFormValues: (\n values: CostCalculatorEstimationFormValues,\n ): CostCalculatorEstimationSubmitValues => {\n const { country, region, salary, currency, ...rest } = values;\n const jsonSchemaStaticFieldValues = {\n country,\n region,\n salary,\n currency,\n };\n const parsedStaticFields = parseJSFToValidate(\n jsonSchemaStaticFieldValues,\n fieldsJSONSchema.fields,\n );\n\n const parsedRegionFields = parseJSFToValidate(\n rest,\n jsonSchemaRegionFields?.fields || [],\n );\n\n return {\n ...parsedStaticFields,\n ...parsedRegionFields,\n } as CostCalculatorEstimationSubmitValues;\n },\n handleValidation,\n isSubmitting: costCalculatorEstimationMutation.isPending,\n isLoading:\n isLoadingCountries && isLoadingCurrencies && isLoadingRegionFields,\n onSubmit,\n resetForm,\n };\n};\n"],"mappings":"qQAGA,OAA0B,UAAAA,OAAc,MCYxC,OAAS,sBAAAC,GAAoB,UAAAC,OAAc,8BAC3C,OAAS,WAAAC,GAAS,YAAAC,MAAgB,QAClC,OAAS,UAAAC,EAAQ,mBAAAC,MAAuB,MAsInB,cAAAC,OAAA,oBAvGd,IAAMC,EAA4D,CACvE,MAAO,aACP,gBAAiB,GACjB,sBAAuB,GACvB,uBAAwB,GACxB,yBAA0B,EAC5B,EAkBMC,GAAkBC,EAACC,GAAwC,CAC/D,GAAM,CAAE,OAAQC,CAAmB,EAAIC,GACrCC,EAAW,KAAK,OAChBH,GAAS,WAAa,CAAC,CACzB,EAEA,OAAOI,GAAmBH,CAAkB,CAC9C,EAPwB,mBAYXI,GAAoBN,EAAA,CAC/B,CAAE,cAAAO,EAAe,kBAAAC,EAAmB,QAAAP,CAAQ,EAA6B,CACvE,kBAAmBH,CACrB,IACG,CACH,GAAM,CAACW,EAAgBC,CAAiB,EAAIC,EAC1CJ,CACF,EACM,CAACK,EAAiBC,CAAkB,EACxCF,EAAgC,EAC5B,CAACG,EAAyBC,CAA0B,EAAIJ,EAE5D,EACI,CAAE,KAAMK,EAAW,UAAWC,CAAmB,EACrDC,EAA2B,CACzB,uBAAwBV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AA0BA,EAAkB,uBAC5C,YAAa,CACX,CACE,YAAaD,EAAO,QAAUA,EAAO,QACrC,oBAAqBA,EAAO,OAC5B,yCAA0CA,EAAO,OACjD,gBAAiBA,EAAO,wBAA0B,QAClD,MAAOC,EAAkB,MACzB,IAAKD,EAAO,KAAO,OACnB,GAAIA,EAAO,UAAY,CAAE,SAAUP,GAAeO,EAAO,QAAQ,CAAE,CACrE,CACF,CACF,CACF,CArBgBR,EAAAO,EAAA","names":["object","createHeadlessForm","modify","useMemo","useState","string","ValidationError","jsx","defaultEstimationOptions","useStaticSchema","__name","options","jsonSchemaModified","modify","jsonSchema","createHeadlessForm","useCostCalculator","defaultRegion","estimationOptions","selectedRegion","setSelectedRegion","useState","selectedCountry","setSelectedCountry","employerBillingCurrency","setEmployerBillingCurrency","countries","isLoadingCountries","useCostCalculatorCountries","currencies","isLoadingCurrencies","useCompanyCurrencies","jsonSchemaRegionSlug","jsonSchemaRegionFields","isLoadingRegionFields","useRegionFields","costCalculatorEstimationMutation","useCostCalculatorEstimation","employeeBillingCurrency","salaryField","salaryFieldPresentation","customFields","useMemo","props","SalaryField","fieldsJSONSchema","onSubmit","values","validationSchema","err","resolve","reject","buildPayload","response","error","onCountryChange","country","currentCountry","value","onRegionChange","region","onChangeCurrency","currency","selectedCurrency","c","regionField","field","regions","string","currencyField","countryField","resetForm","allFields","buildValidationSchema","handleValidation","errors","parsedValues","parseJSFToValidate","ValidationError","iterateResult","iterateErrors","acc","key","handleValidationResult","combinedInnerErrors","combinedValues","salary","rest","parsedStaticFields","parsedRegionFields","buildValidationSchema","fields","fieldsSchema","fieldsSchemaAcc","field","object","__name","formatBenefits","benefits","needle","acc","key","benefitEntry","buildPayload","values","estimationOptions","defaultEstimationOptions"]}