@remoteoss/remote-flows 0.1.0 → 0.1.2
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-2DWTIFOU.js +2 -0
- package/dist/chunk-2DWTIFOU.js.map +1 -0
- package/dist/chunk-36UPHOJS.js +2 -0
- package/dist/chunk-36UPHOJS.js.map +1 -0
- package/dist/chunk-37DREOGC.js +2 -0
- package/dist/chunk-37DREOGC.js.map +1 -0
- package/dist/chunk-5DQBY2TR.js +2 -0
- package/dist/chunk-5DQBY2TR.js.map +1 -0
- package/dist/{chunk-VV7RML2Q.js → chunk-5O2L2L25.js} +2 -2
- package/dist/chunk-5PXYSIYN.js +2 -0
- package/dist/chunk-5PXYSIYN.js.map +1 -0
- package/dist/chunk-5YDR5BIG.js +2 -0
- package/dist/chunk-5YDR5BIG.js.map +1 -0
- package/dist/chunk-6DMCAUPE.js +2 -0
- package/dist/chunk-6DMCAUPE.js.map +1 -0
- package/dist/chunk-6HGUGIYJ.js +2 -0
- package/dist/chunk-6HGUGIYJ.js.map +1 -0
- package/dist/chunk-A7ZJQCNU.js +1 -0
- package/dist/chunk-CKGTR44U.js +2 -0
- package/dist/chunk-CKGTR44U.js.map +1 -0
- package/dist/chunk-DZYFSFZ7.js +2 -0
- package/dist/chunk-DZYFSFZ7.js.map +1 -0
- package/dist/chunk-FZ7FWFJX.js +1 -0
- package/dist/chunk-FZ7FWFJX.js.map +1 -0
- package/dist/chunk-G2GI6FEO.js +2 -0
- package/dist/{chunk-5UXOVZY5.js.map → chunk-G2GI6FEO.js.map} +1 -1
- package/dist/chunk-HELGRHUB.js +2 -0
- package/dist/chunk-HELGRHUB.js.map +1 -0
- package/dist/chunk-JRQSZHUU.js +2 -0
- package/dist/chunk-JRQSZHUU.js.map +1 -0
- package/dist/chunk-JWMY3OVH.js +2 -0
- package/dist/chunk-JWMY3OVH.js.map +1 -0
- package/dist/chunk-LUCFM5TE.js +2 -0
- package/dist/chunk-LUCFM5TE.js.map +1 -0
- package/dist/chunk-OCNLZSS7.js +2 -0
- package/dist/chunk-OCNLZSS7.js.map +1 -0
- package/dist/chunk-QWZVBZED.js +2 -0
- package/dist/{chunk-Q6GIPVSE.js.map → chunk-QWZVBZED.js.map} +1 -1
- package/dist/chunk-RL2KU7BM.js +2 -0
- package/dist/chunk-RL2KU7BM.js.map +1 -0
- package/dist/chunk-ROPNMSSM.js +2 -0
- package/dist/{chunk-YNLDKIE4.js.map → chunk-ROPNMSSM.js.map} +1 -1
- package/dist/chunk-TIXDBKBM.js +2 -0
- package/dist/chunk-TIXDBKBM.js.map +1 -0
- package/dist/chunk-TPKAREI4.js +2 -0
- package/dist/chunk-TPKAREI4.js.map +1 -0
- package/dist/{chunk-KQCZ2KSO.js → chunk-WTGUGPHV.js} +2 -2
- package/dist/{chunk-KQCZ2KSO.js.map → chunk-WTGUGPHV.js.map} +1 -1
- package/dist/chunk-XFE56PM4.js +2 -0
- package/dist/chunk-XFE56PM4.js.map +1 -0
- package/dist/chunk-Y5UG6SJJ.js +2 -0
- package/dist/chunk-Y5UG6SJJ.js.map +1 -0
- package/dist/chunk-ZCG5JUUR.js +2 -0
- package/dist/chunk-ZCG5JUUR.js.map +1 -0
- package/dist/flows/ContractAmendment/ContractAmendmentBack.d.ts +5 -0
- package/dist/flows/ContractAmendment/ContractAmendmentBack.js +2 -0
- package/dist/flows/ContractAmendment/ContractAmendmentBack.js.map +1 -0
- package/dist/flows/ContractAmendment/ContractAmendmentConfirmationForm.d.ts +30 -0
- package/dist/flows/ContractAmendment/ContractAmendmentConfirmationForm.js +2 -0
- package/dist/flows/ContractAmendment/ContractAmendmentConfirmationForm.js.map +1 -0
- package/dist/flows/ContractAmendment/ContractAmendmentFlow.d.ts +24 -7
- package/dist/flows/ContractAmendment/ContractAmendmentFlow.js +1 -1
- package/dist/flows/ContractAmendment/ContractAmendmentForm.d.ts +26 -3
- package/dist/flows/ContractAmendment/ContractAmendmentForm.js +1 -1
- package/dist/flows/ContractAmendment/ContractAmendmentSubmit.d.ts +1 -1
- package/dist/flows/ContractAmendment/ContractAmendmentSubmit.js +1 -1
- package/dist/flows/ContractAmendment/context.d.ts +26 -24
- package/dist/flows/ContractAmendment/context.js +1 -1
- package/dist/flows/ContractAmendment/hooks.d.ts +94 -6
- package/dist/flows/ContractAmendment/hooks.js +1 -1
- package/dist/flows/ContractAmendment/index.d.ts +8 -5
- package/dist/flows/ContractAmendment/index.js +1 -1
- package/dist/flows/ContractAmendment/utils.d.ts +11 -0
- package/dist/flows/ContractAmendment/utils.js +2 -0
- package/dist/flows/ContractAmendment/utils.js.map +1 -0
- package/dist/flows/CostCalculator/CostCalculatorFlow.d.ts +2 -2
- package/dist/flows/CostCalculator/CostCalculatorFlow.js +1 -1
- package/dist/flows/CostCalculator/CostCalculatorForm.d.ts +1 -1
- package/dist/flows/CostCalculator/CostCalculatorForm.js +1 -1
- package/dist/flows/CostCalculator/CostCalculatorResetButton.d.ts +1 -1
- package/dist/flows/CostCalculator/CostCalculatorResetButton.js +1 -1
- package/dist/flows/CostCalculator/Results/CostCalculatorResults.d.ts +1 -1
- package/dist/flows/CostCalculator/Results/CostCalculatorResults.js +1 -1
- package/dist/flows/CostCalculator/context.d.ts +1 -1
- package/dist/flows/CostCalculator/hooks.d.ts +1 -1
- package/dist/flows/CostCalculator/hooks.js +1 -1
- package/dist/flows/CostCalculator/index.d.ts +1 -1
- package/dist/flows/CostCalculator/index.js +1 -1
- package/dist/flows/CostCalculator/types.d.ts +1 -1
- package/dist/flows/CostCalculator/utils.d.ts +1 -1
- package/dist/flows/CostCalculator/utils.js +1 -1
- package/dist/flows/Termination/TerminationFlow.d.ts +20 -0
- package/dist/flows/Termination/TerminationFlow.js +2 -0
- package/dist/flows/Termination/TerminationFlow.js.map +1 -0
- package/dist/flows/Termination/TerminationForm.d.ts +13 -0
- package/dist/flows/Termination/TerminationForm.js +2 -0
- package/dist/flows/Termination/TerminationForm.js.map +1 -0
- package/dist/flows/Termination/TerminationSubmit.d.ts +5 -0
- package/dist/flows/Termination/TerminationSubmit.js +2 -0
- package/dist/flows/Termination/TerminationSubmit.js.map +1 -0
- package/dist/flows/Termination/context.d.ts +43 -0
- package/dist/flows/Termination/context.js +2 -0
- package/dist/flows/Termination/context.js.map +1 -0
- package/dist/flows/Termination/hooks.d.ts +40 -0
- package/dist/flows/Termination/hooks.js +2 -0
- package/dist/flows/Termination/hooks.js.map +1 -0
- package/dist/flows/Termination/index.d.ts +10 -0
- package/dist/flows/Termination/index.js +2 -0
- package/dist/flows/Termination/index.js.map +1 -0
- package/dist/flows/Termination/jsonSchema.d.ts +297 -0
- package/dist/flows/Termination/jsonSchema.js +2 -0
- package/dist/flows/Termination/jsonSchema.js.map +1 -0
- package/dist/flows/Termination/types.d.ts +23 -0
- package/dist/flows/Termination/types.js +1 -0
- package/dist/flows/Termination/types.js.map +1 -0
- package/dist/flows/useStepState.d.ts +49 -0
- package/dist/flows/useStepState.js +2 -0
- package/dist/flows/useStepState.js.map +1 -0
- package/dist/flows/utils.d.ts +20 -1
- package/dist/flows/utils.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +40 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mutations-v9H353tz.d.ts +10 -0
- package/dist/{types.gen-DCJSPsGk.d.ts → types.gen-BhkGMC9-.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-4QHHDFB2.js +0 -2
- package/dist/chunk-4QHHDFB2.js.map +0 -1
- package/dist/chunk-5UXOVZY5.js +0 -2
- package/dist/chunk-7V6IPASW.js +0 -2
- package/dist/chunk-7V6IPASW.js.map +0 -1
- package/dist/chunk-ANPGCYMT.js +0 -2
- package/dist/chunk-ANPGCYMT.js.map +0 -1
- package/dist/chunk-GCF5EF2A.js +0 -2
- package/dist/chunk-GCF5EF2A.js.map +0 -1
- package/dist/chunk-GKEURJR4.js +0 -2
- package/dist/chunk-GKEURJR4.js.map +0 -1
- package/dist/chunk-KY7BGW6H.js +0 -2
- package/dist/chunk-KY7BGW6H.js.map +0 -1
- package/dist/chunk-MKJHD77O.js +0 -1
- package/dist/chunk-Q6GIPVSE.js +0 -2
- package/dist/chunk-UTCIIPYZ.js +0 -2
- package/dist/chunk-UTCIIPYZ.js.map +0 -1
- package/dist/chunk-VTAHQOKR.js +0 -2
- package/dist/chunk-VTAHQOKR.js.map +0 -1
- package/dist/chunk-YGP3O2VJ.js +0 -2
- package/dist/chunk-YGP3O2VJ.js.map +0 -1
- package/dist/chunk-YNLDKIE4.js +0 -2
- package/dist/hooks-BQWrl9Bj.d.ts +0 -50
- /package/dist/{chunk-VV7RML2Q.js.map → chunk-5O2L2L25.js.map} +0 -0
- /package/dist/{chunk-MKJHD77O.js.map → chunk-A7ZJQCNU.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/flows/CostCalculator/utils.ts","../src/flows/CostCalculator/hooks.ts"],"sourcesContent":["import type { CostCalculatorEstimateParams } from '@/src/client';\n\nimport { convertToCents } from '@/src/components/form/utils';\nimport { $TSFixMe } from '@remoteoss/json-schema-form';\nimport { AnyObjectSchema, object } from 'yup';\nimport { defaultEstimationOptions } from './hooks';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\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: CostCalculatorEstimationFormValues,\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: convertToCents(values.salary) as number,\n annual_gross_salary_in_employer_currency: convertToCents(\n values.salary,\n ) as number,\n employment_term: values.contract_duration_type ?? 'fixed',\n title: estimationOptions.title,\n regional_to_employer_exchange_rate: '1',\n age: values.age ?? undefined,\n ...(values.benefits && { benefits: formatBenefits(values.benefits) }),\n },\n ],\n };\n}\n","import {\n CostCalculatorEstimateParams,\n CostCalculatorEstimateResponse,\n getIndexCompanyCurrency,\n getIndexCountry,\n getShowRegionField,\n MinimalRegion,\n postCreateEstimation,\n PostCreateEstimationError,\n postCreateEstimationPdf,\n} from '@/src/client';\nimport { jsonSchema } from '@/src/flows/CostCalculator/jsonSchema';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\n JSFModify,\n} from '@/src/flows/CostCalculator/types';\nimport type { Result } from '@/src/flows/types';\n\nimport { parseJSFToValidate } from '@/src/components/form/utils';\nimport { iterateErrors } from '@/src/components/form/yupValidationResolver';\nimport { useClient } from '@/src/context';\nimport { Client } from '@hey-api/client-fetch';\nimport { createHeadlessForm, modify } from '@remoteoss/json-schema-form';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useState } from 'react';\nimport { string, ValidationError } from 'yup';\nimport { buildPayload, buildValidationSchema } from './utils';\n\ntype CostCalculatorCountry = {\n value: string;\n label: string;\n childRegions: MinimalRegion[];\n hasAdditionalFields: boolean | undefined;\n regionSlug: string;\n};\n\ntype JSFValidationError = {\n formErrors: Record<\n string,\n {\n type: string;\n message: string;\n }\n >;\n yupError: ValidationError;\n};\n\n/**\n * Hook to fetch the countries for the cost calculator.\n * @returns\n */\nconst useCostCalculatorCountries = ({\n includePremiumBenefits,\n}: {\n includePremiumBenefits: CostCalculatorEstimationOptions['includePremiumBenefits'];\n}) => {\n const { client } = useClient();\n return useQuery({\n queryKey: ['cost-calculator-countries', includePremiumBenefits],\n queryFn: () => {\n return getIndexCountry({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n query: {\n include_premium_benefits: includePremiumBenefits,\n },\n });\n },\n select: (data) =>\n data.data?.data.map((country) => ({\n value: country.region_slug,\n label: country.name,\n childRegions: country.child_regions,\n hasAdditionalFields: country.has_additional_fields,\n regionSlug: country.region_slug,\n })),\n });\n};\n\n/**\n * Hook to fetch the company currencies.\n * @returns\n */\nconst useCompanyCurrencies = () => {\n const { client } = useClient();\n\n return useQuery({\n queryKey: ['company-currencies'],\n queryFn: () => {\n return getIndexCompanyCurrency({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n });\n },\n select: (data) =>\n data.data?.data?.company_currencies.map((currency) => ({\n value: currency.slug,\n label: currency.code,\n })),\n });\n};\n\n/**\n * Hook to create an estimation.\n * @returns\n */\nconst useCostCalculatorEstimation = () => {\n const { client } = useClient();\n\n return useMutation({\n mutationFn: (payload: CostCalculatorEstimateParams) => {\n return postCreateEstimation({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n body: payload,\n });\n },\n });\n};\n\n/**\n * Custom hook to create a PDF estimation.\n *\n * @returns\n */\nexport const useCostCalculatorEstimationPdf = () => {\n const { client } = useClient();\n\n return useMutation({\n mutationFn: (payload: CostCalculatorEstimateParams) => {\n return postCreateEstimationPdf({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n body: payload,\n });\n },\n });\n};\n\n/**\n * Hook to fetch the region fields.\n * @param region\n * @returns\n */\nconst useRegionFields = (\n region: string | undefined,\n {\n includePremiumBenefits,\n options,\n }: {\n includePremiumBenefits: CostCalculatorEstimationOptions['includePremiumBenefits'];\n options?: {\n jsfModify?: JSFModify;\n };\n },\n) => {\n const { client } = useClient();\n\n return useQuery({\n queryKey: ['cost-calculator-region-fields', region, includePremiumBenefits],\n queryFn: () => {\n return getShowRegionField({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n path: { slug: region as string },\n query: {\n include_premium_benefits: includePremiumBenefits,\n },\n });\n },\n enabled: !!region,\n select: ({ data }) => {\n let jsfSchema = data?.data?.schema || {};\n if (options && options.jsfModify) {\n const { schema } = modify(jsfSchema, options.jsfModify);\n jsfSchema = schema;\n }\n return createHeadlessForm(jsfSchema);\n },\n });\n};\n\nexport const defaultEstimationOptions: CostCalculatorEstimationOptions = {\n title: 'Estimation',\n includeBenefits: false,\n includeCostBreakdowns: false,\n includePremiumBenefits: 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\n/**\n * Hook to use the cost calculator.\n */\nexport const useCostCalculator = (\n { defaultRegion, estimationOptions, options }: UseCostCalculatorParams = {\n estimationOptions: defaultEstimationOptions,\n },\n) => {\n const { schema: jsonSchemaModified } = modify(\n jsonSchema.data.schema,\n options?.jsfModify || {},\n );\n\n const fieldsJSONSchema = createHeadlessForm(jsonSchemaModified);\n\n const [selectedRegion, setSelectedRegion] = useState<string | undefined>(\n defaultRegion,\n );\n const [selectedCountry, setSelectedCountry] =\n useState<CostCalculatorCountry>();\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\n /**\n * Submit the estimation form with the given values.\n * @param values\n */\n async function onSubmit(\n values: CostCalculatorEstimationFormValues,\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 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 }\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 isPartialValidation: false,\n });\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 handleValidation,\n isSubmitting: costCalculatorEstimationMutation.isPending,\n isLoading:\n isLoadingCountries && isLoadingCurrencies && isLoadingRegionFields,\n onSubmit,\n resetForm,\n };\n};\n"],"mappings":"mRAIA,OAA0B,UAAAA,OAAc,MCmBxC,OAAS,sBAAAC,EAAoB,UAAAC,MAAc,8BAC3C,OAAS,eAAAC,EAAa,YAAAC,MAAgB,wBACtC,OAAS,YAAAC,MAAgB,QACzB,OAAS,UAAAC,EAAQ,mBAAAC,MAAuB,MA0BxC,IAAMC,GAA6BC,EAAA,CAAC,CAClC,uBAAAC,CACF,IAEM,CACJ,GAAM,CAAE,OAAAC,CAAO,EAAIC,EAAU,EAC7B,OAAOC,EAAS,CACd,SAAU,CAAC,4BAA6BH,CAAsB,EAC9D,QAASD,EAAA,IACAK,EAAgB,CACrB,OAAQH,EACR,QAAS,CACP,cAAe,EACjB,EACA,MAAO,CACL,yBAA0BD,CAC5B,CACF,CAAC,EATM,WAWT,OAAQD,EAACM,GACPA,EAAK,MAAM,KAAK,IAAKC,IAAa,CAChC,MAAOA,EAAQ,YACf,MAAOA,EAAQ,KACf,aAAcA,EAAQ,cACtB,oBAAqBA,EAAQ,sBAC7B,WAAYA,EAAQ,WACtB,EAAE,EAPI,SAQV,CAAC,CACH,EA5BmC,8BAkC7BC,GAAuBR,EAAA,IAAM,CACjC,GAAM,CAAE,OAAAE,CAAO,EAAIC,EAAU,EAE7B,OAAOC,EAAS,CACd,SAAU,CAAC,oBAAoB,EAC/B,QAASJ,EAAA,IACAS,EAAwB,CAC7B,OAAQP,EACR,QAAS,CACP,cAAe,EACjB,CACF,CAAC,EANM,WAQT,OAAQF,EAACM,GACPA,EAAK,MAAM,MAAM,mBAAmB,IAAKI,IAAc,CACrD,MAAOA,EAAS,KAChB,MAAOA,EAAS,IAClB,EAAE,EAJI,SAKV,CAAC,CACH,EAnB6B,wBAyBvBC,GAA8BX,EAAA,IAAM,CACxC,GAAM,CAAE,O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BAgBhB,SAASO,GAAeC,EAAkC,CACxD,IAAMC,EAAS,WACf,OAAO,OAAO,KAAKD,CAAQ,EAAE,OAE3B,CAACE,EAAKC,IAAQ,CAEd,IAAMC,EAAe,CACnB,mBAFuBD,EAAI,QAAQF,EAAQ,EAAE,EAG7C,kBAAmBD,EAASG,CAAG,CACjC,EACA,MAAO,CAAC,GAAGD,EAAKE,CAAY,CAC9B,EAAG,CAAC,CAAC,CACP,CAZSN,EAAAC,GAAA,kBAoBF,SAASM,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,oBAAqBG,EAAeH,EAAO,MAAM,EACjD,yCAA0CG,EACxCH,EAAO,MACT,EACA,gBAAiBA,EAAO,wBAA0B,QAClD,MAAOC,EAAkB,MACzB,mCAAoC,IACpC,IAAKD,EAAO,KAAO,OACnB,GAAIA,EAAO,UAAY,CAAE,SAAUP,GAAeO,EAAO,QAAQ,CAAE,CACrE,CACF,CACF,CACF,CAxBgBR,EAAAO,EAAA","names":["object","createHeadlessForm","modify","useMutation","useQuery","useState","string","ValidationError","useCostCalculatorCountries","__name","includePremiumBenefits","client","useClient","useQuery","getIndexCountry","data","country","useCompanyCurrencies","getIndexCompanyCurrency","currency","useCostCalculatorEstimation","useMutation","payload","postCreateEstimation","useCostCalculatorEstimationPdf","postCreateEstimationPdf","useRegionFields","region","options","getShowRegionField","jsfSchema","schema","modify","createHeadlessForm","defaultEstimationOptions","useCostCalculator","defaultRegion","estimationOptions","jsonSchemaModified","jsonSchema","fieldsJSONSchema","selectedRegion","setSelectedRegion","useState","selectedCountry","setSelectedCountry","countries","isLoadingCountries","currencies","isLoadingCurrencies","jsonSchemaRegionSlug","jsonSchemaRegionFields","isLoadingRegionFields","costCalculatorEstimationMutation","onSubmit","values","validationSchema","err","resolve","reject","buildPayload","response","error","onCountryChange","currentCountry","value","onRegionChange","regionField","field","regions","string","currencyField","countryField","resetForm","allFields","buildValidationSchema","handleValidation","errors","parsedValues","parseJSFToValidate","ValidationError","iterateResult","iterateErrors","acc","key","handleValidationResult","combinedInnerErrors","combinedValues","buildValidationSchema","fields","fieldsSchema","fieldsSchemaAcc","field","object","__name","formatBenefits","benefits","needle","acc","key","benefitEntry","buildPayload","values","estimationOptions","defaultEstimationOptions","convertToCents"]}
|
|
1
|
+
{"version":3,"sources":["../src/flows/CostCalculator/utils.ts","../src/flows/CostCalculator/hooks.ts"],"sourcesContent":["import type { CostCalculatorEstimateParams } from '@/src/client';\n\nimport { convertToCents } from '@/src/components/form/utils';\nimport { $TSFixMe } from '@remoteoss/json-schema-form';\nimport { AnyObjectSchema, object } from 'yup';\nimport { defaultEstimationOptions } from './hooks';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\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: CostCalculatorEstimationFormValues,\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: convertToCents(values.salary) as number,\n annual_gross_salary_in_employer_currency: convertToCents(\n values.salary,\n ) as number,\n employment_term: values.contract_duration_type ?? 'fixed',\n title: estimationOptions.title,\n regional_to_employer_exchange_rate: '1',\n age: values.age ?? undefined,\n ...(values.benefits && { benefits: formatBenefits(values.benefits) }),\n },\n ],\n };\n}\n","import {\n CostCalculatorEstimateParams,\n CostCalculatorEstimateResponse,\n getIndexCompanyCurrency,\n getIndexCountry,\n getShowRegionField,\n MinimalRegion,\n postCreateEstimation,\n PostCreateEstimationError,\n postCreateEstimationPdf,\n} from '@/src/client';\nimport { jsonSchema } from '@/src/flows/CostCalculator/jsonSchema';\nimport type {\n CostCalculatorEstimationFormValues,\n CostCalculatorEstimationOptions,\n JSFModify,\n} from '@/src/flows/CostCalculator/types';\nimport type { Result } from '@/src/flows/types';\n\nimport { parseJSFToValidate } from '@/src/components/form/utils';\nimport { iterateErrors } from '@/src/components/form/yupValidationResolver';\nimport { useClient } from '@/src/context';\nimport { Client } from '@hey-api/client-fetch';\nimport { createHeadlessForm, modify } from '@remoteoss/json-schema-form';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useState } from 'react';\nimport { string, ValidationError } from 'yup';\nimport { buildPayload, buildValidationSchema } from './utils';\n\ntype CostCalculatorCountry = {\n value: string;\n label: string;\n childRegions: MinimalRegion[];\n hasAdditionalFields: boolean | undefined;\n regionSlug: string;\n};\n\ntype JSFValidationError = {\n formErrors: Record<\n string,\n {\n type: string;\n message: string;\n }\n >;\n yupError: ValidationError;\n};\n\n/**\n * Hook to fetch the countries for the cost calculator.\n * @returns\n */\nconst useCostCalculatorCountries = ({\n includePremiumBenefits,\n}: {\n includePremiumBenefits: CostCalculatorEstimationOptions['includePremiumBenefits'];\n}) => {\n const { client } = useClient();\n return useQuery({\n queryKey: ['cost-calculator-countries', includePremiumBenefits],\n queryFn: () => {\n return getIndexCountry({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n query: {\n include_premium_benefits: includePremiumBenefits,\n },\n });\n },\n select: (data) =>\n data.data?.data.map((country) => ({\n value: country.region_slug,\n label: country.name,\n childRegions: country.child_regions,\n hasAdditionalFields: country.has_additional_fields,\n regionSlug: country.region_slug,\n })),\n });\n};\n\n/**\n * Hook to fetch the company currencies.\n * @returns\n */\nconst useCompanyCurrencies = () => {\n const { client } = useClient();\n\n return useQuery({\n queryKey: ['company-currencies'],\n queryFn: () => {\n return getIndexCompanyCurrency({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n });\n },\n select: (data) =>\n data.data?.data?.company_currencies.map((currency) => ({\n value: currency.slug,\n label: currency.code,\n })),\n });\n};\n\n/**\n * Hook to create an estimation.\n * @returns\n */\nconst useCostCalculatorEstimation = () => {\n const { client } = useClient();\n\n return useMutation({\n mutationFn: (payload: CostCalculatorEstimateParams) => {\n return postCreateEstimation({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n body: payload,\n });\n },\n });\n};\n\n/**\n * Custom hook to create a PDF estimation.\n *\n * @returns\n */\nexport const useCostCalculatorEstimationPdf = () => {\n const { client } = useClient();\n\n return useMutation({\n mutationFn: (payload: CostCalculatorEstimateParams) => {\n return postCreateEstimationPdf({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n body: payload,\n });\n },\n });\n};\n\n/**\n * Hook to fetch the region fields.\n * @param region\n * @returns\n */\nconst useRegionFields = (\n region: string | undefined,\n {\n includePremiumBenefits,\n options,\n }: {\n includePremiumBenefits: CostCalculatorEstimationOptions['includePremiumBenefits'];\n options?: {\n jsfModify?: JSFModify;\n };\n },\n) => {\n const { client } = useClient();\n\n return useQuery({\n queryKey: ['cost-calculator-region-fields', region, includePremiumBenefits],\n queryFn: () => {\n return getShowRegionField({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n path: { slug: region as string },\n query: {\n include_premium_benefits: includePremiumBenefits,\n },\n });\n },\n enabled: !!region,\n select: ({ data }) => {\n let jsfSchema = data?.data?.schema || {};\n if (options && options.jsfModify) {\n const { schema } = modify(jsfSchema, options.jsfModify);\n jsfSchema = schema;\n }\n return createHeadlessForm(jsfSchema);\n },\n });\n};\n\nexport const defaultEstimationOptions: CostCalculatorEstimationOptions = {\n title: 'Estimation',\n includeBenefits: false,\n includeCostBreakdowns: false,\n includePremiumBenefits: 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\n/**\n * Hook to use the cost calculator.\n */\nexport const useCostCalculator = (\n { defaultRegion, estimationOptions, options }: UseCostCalculatorParams = {\n estimationOptions: defaultEstimationOptions,\n },\n) => {\n const { schema: jsonSchemaModified } = modify(\n jsonSchema.data.schema,\n options?.jsfModify || {},\n );\n\n const fieldsJSONSchema = createHeadlessForm(jsonSchemaModified);\n\n const [selectedRegion, setSelectedRegion] = useState<string | undefined>(\n defaultRegion,\n );\n const [selectedCountry, setSelectedCountry] =\n useState<CostCalculatorCountry>();\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\n /**\n * Submit the estimation form with the given values.\n * @param values\n */\n async function onSubmit(\n values: CostCalculatorEstimationFormValues,\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 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 }\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 handleValidation,\n isSubmitting: costCalculatorEstimationMutation.isPending,\n isLoading:\n isLoadingCountries && isLoadingCurrencies && isLoadingRegionFields,\n onSubmit,\n resetForm,\n };\n};\n"],"mappings":"mRAIA,OAA0B,UAAAA,OAAc,MCmBxC,OAAS,sBAAAC,EAAoB,UAAAC,MAAc,8BAC3C,OAAS,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C,CAAC,CACP,CAZSN,EAAAC,GAAA,kBAoBF,SAASM,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,oBAAqBG,EAAeH,EAAO,MAAM,EACjD,yCAA0CG,EACxCH,EAAO,MACT,EACA,gBAAiBA,EAAO,wBAA0B,QAClD,MAAOC,EAAkB,MACzB,mCAAoC,IACpC,IAAKD,EAAO,KAAO,OACnB,GAAIA,EAAO,UAAY,CAAE,SAAUP,GAAeO,EAAO,QAAQ,CAAE,CACrE,CACF,CACF,CACF,CAxBgBR,EAAAO,EAAA","names":["object","createHeadlessForm","modify","useMutation","useQuery","useState","string","ValidationError","useCostCalculatorCountries","__name","includePremiumBenefits","client","useClient","useQuery","getIndexCountry","data","country","useCompanyCurrencies","getIndexCompanyCurrency","currency","useCostCalculatorEstimation","useMutation","payload","postCreateEstimation","useCostCalculatorEstimationPdf","postCreateEstimationPdf","useRegionFields","region","options","getShowRegionField","jsfSchema","schema","modify","createHeadlessForm","defaultEstimationOptions","useCostCalculator","defaultRegion","estimationOptions","jsonSchemaModified","jsonSchema","fieldsJSONSchema","selectedRegion","setSelectedRegion","useState","selectedCountry","setSelectedCountry","countries","isLoadingCountries","currencies","isLoadingCurrencies","jsonSchemaRegionSlug","jsonSchemaRegionFields","isLoadingRegionFields","costCalculatorEstimationMutation","onSubmit","values","validationSchema","err","resolve","reject","buildPayload","response","error","onCountryChange","currentCountry","value","onRegionChange","regionField","field","regions","string","currencyField","countryField","resetForm","allFields","buildValidationSchema","handleValidation","errors","parsedValues","parseJSFToValidate","ValidationError","iterateResult","iterateErrors","acc","key","handleValidationResult","combinedInnerErrors","combinedValues","buildValidationSchema","fields","fieldsSchema","fieldsSchemaAcc","field","object","__name","formatBenefits","benefits","needle","acc","key","benefitEntry","buildPayload","values","estimationOptions","defaultEstimationOptions","convertToCents"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as c}from"./chunk-RL2KU7BM.js";import{b as p}from"./chunk-36UPHOJS.js";import{a as f}from"./chunk-JRQSZHUU.js";import{b as l}from"./chunk-G2GI6FEO.js";import{c as a}from"./chunk-6DMCAUPE.js";import{d as u}from"./chunk-WRDKLT4N.js";import{a as e}from"./chunk-AYDF3IFZ.js";import{createHeadlessForm as P,modify as C}from"@remoteoss/json-schema-form";import{useMutation as M,useQuery as b}from"@tanstack/react-query";import{useState as w}from"react";import j from"lodash/omit";var H=e(()=>{let{client:t}=u();return M({mutationFn:e(r=>l({client:t,headers:{Authorization:""},body:r}),"mutationFn")})},"useCreateTermination"),J=e(({formValues:t,jsfModify:r})=>b({queryKey:["rmt-flows-termination-schema"],queryFn:e(()=>c,"queryFn"),select:e(({data:s})=>{let{schema:m}=C(s.schema,r||{});return P(m||{},{initialValues:t||{}})},"select")}),"useTerminationSchema"),U=e(({employmentId:t,options:r})=>{let[s,m]=w(void 0),{data:o,isLoading:y}=J({formValues:s,jsfModify:r?.jsfModify}),d=H(),{mutateAsync:_}=f(d);async function V(n){if(!t)throw new Error("Employment id is missing");if(o){let i=a(n,o.fields),{customer_informed_employee:F}=i,T=F==="yes"?{employee_awareness:{date:i.customer_informed_employee_date,note:i.customer_informed_employee_description}}:void 0,g=p(i,["agrees_to_pto_amount","confidential","customer_informed_employee","will_challenge_termination"]),h=j(g,"customer_informed_employee_date","customer_informed_employee_description"),S={employment_id:t,termination_details:{...h,...T},type:"termination"};return _(S)}}return e(V,"onSubmit"),{stepState:{current:0,total:1,isLastStep:!0},fields:o?.fields||[],isLoading:y,isSubmitting:d.isPending,initialValues:{},handleValidation:e(n=>{if(o){let i=a(n,o?.fields);return o?.handleValidation(i)}return null},"handleValidation"),checkFieldUpdates:e(n=>{if(o){let i=a(n,o?.fields);m(i)}},"checkFieldUpdates"),onSubmit:V}},"useTermination");export{U as a};
|
|
2
|
+
//# sourceMappingURL=chunk-XFE56PM4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flows/Termination/hooks.ts"],"sourcesContent":["import { CreateOffboardingParams, postCreateOffboarding } from '@/src/client';\nimport { mutationToPromise } from '@/src/lib/mutations';\nimport { Client } from '@hey-api/client-fetch';\nimport { createHeadlessForm, modify } from '@remoteoss/json-schema-form';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { jsonSchema } from './jsonSchema';\nimport { parseJSFToValidate } from '@/src/components/form/utils';\nimport { useState } from 'react';\nimport { JSFModify } from '@/src/flows/CostCalculator/types';\nimport { TerminationFormValues } from '@/src/flows/Termination/types';\nimport { useClient } from '@/src/context';\nimport omit from 'lodash/omit';\nimport { parseFormRadioValues } from '@/src/flows/utils';\n\nconst useCreateTermination = () => {\n const { client } = useClient();\n return useMutation({\n mutationFn: (payload: CreateOffboardingParams) => {\n return postCreateOffboarding({\n client: client as Client,\n headers: {\n Authorization: ``,\n },\n body: payload,\n });\n },\n });\n};\n\nconst useTerminationSchema = ({\n formValues,\n jsfModify,\n}: {\n formValues?: TerminationFormValues;\n jsfModify?: JSFModify;\n}) => {\n return useQuery({\n queryKey: ['rmt-flows-termination-schema'],\n queryFn: () => {\n return jsonSchema;\n },\n select: ({ data }) => {\n const { schema } = modify(data.schema, jsfModify || {});\n const form = createHeadlessForm(schema || {}, {\n initialValues: formValues || {},\n });\n return form;\n },\n });\n};\n\ntype TerminationHookProps = {\n employmentId: string;\n options?: {\n jsfModify?: JSFModify;\n };\n};\n\nexport const useTermination = ({\n employmentId,\n options,\n}: TerminationHookProps) => {\n const [formValues, setFormValues] = useState<\n TerminationFormValues | undefined\n >(undefined);\n\n const { data: terminationHeadlessForm, isLoading: isLoadingTermination } =\n useTerminationSchema({ formValues, jsfModify: options?.jsfModify });\n\n const createTermination = useCreateTermination();\n const { mutateAsync } = mutationToPromise(createTermination);\n\n async function onSubmit(values: TerminationFormValues) {\n if (!employmentId) {\n throw new Error('Employment id is missing');\n }\n\n if (terminationHeadlessForm) {\n const parsedValues = parseJSFToValidate(\n values,\n terminationHeadlessForm.fields,\n );\n\n const { customer_informed_employee: customerInformedEmployee } =\n parsedValues;\n\n const employeeAwareness =\n customerInformedEmployee === 'yes'\n ? {\n employee_awareness: {\n date: parsedValues.customer_informed_employee_date,\n note: parsedValues.customer_informed_employee_description,\n },\n }\n : undefined;\n\n const radioFieldKeys = [\n 'agrees_to_pto_amount',\n 'confidential',\n 'customer_informed_employee',\n 'will_challenge_termination',\n ];\n\n const parsedRadioValues = parseFormRadioValues(\n parsedValues,\n radioFieldKeys,\n );\n\n const normalizedValues = omit(\n parsedRadioValues,\n 'customer_informed_employee_date',\n 'customer_informed_employee_description',\n );\n\n const terminationPayload: CreateOffboardingParams = {\n employment_id: employmentId,\n termination_details: {\n ...normalizedValues,\n ...employeeAwareness,\n } as TerminationFormValues,\n type: 'termination',\n };\n\n return mutateAsync(terminationPayload);\n }\n\n return;\n }\n\n return {\n stepState: {\n current: 0,\n total: 1,\n isLastStep: true,\n },\n fields: terminationHeadlessForm?.fields || [],\n isLoading: isLoadingTermination,\n isSubmitting: createTermination.isPending,\n initialValues: {},\n handleValidation: (values: TerminationFormValues) => {\n if (terminationHeadlessForm) {\n const parsedValues = parseJSFToValidate(\n values,\n terminationHeadlessForm?.fields,\n );\n return terminationHeadlessForm?.handleValidation(parsedValues);\n }\n return null;\n },\n checkFieldUpdates: (values: Partial<TerminationFormValues>) => {\n if (terminationHeadlessForm) {\n const parsedValues = parseJSFToValidate(\n values,\n terminationHeadlessForm?.fields,\n );\n setFormValues(parsedValues as TerminationFormValues);\n }\n },\n onSubmit,\n };\n};\n"],"mappings":"wRAGA,OAAS,sBAAAA,EAAoB,UAAAC,MAAc,8BAC3C,OAAS,eAAAC,EAAa,YAAAC,MAAgB,wBAGtC,OAAS,YAAAC,MAAgB,QAIzB,OAAOC,MAAU,cAGjB,IAAMC,EAA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ACvBH,EACA,kCACA,wCACF,EAEMI,EAA8C,CAClD,cAAenB,EACf,oBAAqB,CACnB,GAAGiB,EACH,GAAGH,CACL,EACA,KAAM,aACR,EAEA,OAAOP,EAAYY,CAAkB,CACvC,CAGF,CAvDe,OAAAnC,EAAAyB,EAAA,YAyDR,CACL,UAAW,CACT,QAAS,EACT,MAAO,EACP,WAAY,EACd,EACA,OAAQL,GAAyB,QAAU,CAAC,EAC5C,UAAWC,EACX,aAAcC,EAAkB,UAChC,cAAe,CAAC,EAChB,iBAAkBtB,EAAC0B,GAAkC,CACnD,GAAIN,EAAyB,CAC3B,IAAMO,EAAeC,EACnBF,EACAN,GAAyB,MAC3B,EACA,OAAOA,GAAyB,iBAAiBO,CAAY,CAC/D,CACA,OAAO,IACT,EATkB,oBAUlB,kBAAmB3B,EAAC0B,GAA2C,CAC7D,GAAIN,EAAyB,CAC3B,IAAMO,EAAeC,EACnBF,EACAN,GAAyB,MAC3B,EACAF,EAAcS,CAAqC,CACrD,CACF,EARmB,qBASnB,SAAAF,CACF,CACF,EAtG8B","names":["createHeadlessForm","modify","useMutation","useQuery","useState","omit","useCreateTermination","__name","client","useClient","useMutation","payload","postCreateOffboarding","useTerminationSchema","formValues","jsfModify","useQuery","jsonSchema","data","schema","modify","createHeadlessForm","useTermination","employmentId","options","setFormValues","useState","terminationHeadlessForm","isLoadingTermination","createTermination","mutateAsync","mutationToPromise","onSubmit","values","parsedValues","parseJSFToValidate","customerInformedEmployee","employeeAwareness","parsedRadioValues","parseFormRadioValues","normalizedValues","omit","terminationPayload"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as l}from"./chunk-DZYFSFZ7.js";import{a as m}from"./chunk-LUCFM5TE.js";import{b as a}from"./chunk-A4RX3KRZ.js";import{a as s}from"./chunk-TIXDBKBM.js";import{a as t}from"./chunk-AYDF3IFZ.js";import n,{useEffect as S}from"react";import{useForm as h}from"react-hook-form";function E({username:d,onSubmit:f,onError:u,onSuccess:c}){let{formId:p,terminationBag:o}=l(),F=a(o.handleValidation),i=h({resolver:F,defaultValues:o?.initialValues,shouldUnregister:!0,mode:"onBlur"});S(()=>{let r=i?.watch(e=>{Object.keys(i.formState.dirtyFields).length>0&&o?.checkFieldUpdates(e)});return()=>r?.unsubscribe()},[]);let b=t(async r=>{await f?.(r);let e=await o?.onSubmit(r);e?.error?u?.(e.error):e?.data&&c?.(e.data)},"handleSubmit"),g=(o?.fields?o.fields:[]).map(r=>r.name==="acknowledge_termination_procedure"?{...r,label:r.label.replace("{{username}}",d)}:r);return n.createElement(s,{...i},n.createElement("form",{id:p,onSubmit:i.handleSubmit(b),className:"space-y-4 RemoteFlows__TerminationForm"},n.createElement(m,{fields:g})))}t(E,"TerminationForm");export{E as a};
|
|
2
|
+
//# sourceMappingURL=chunk-Y5UG6SJJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flows/Termination/TerminationForm.tsx"],"sourcesContent":["import { JSONSchemaFormFields } from '@/src/components/form/JSONSchemaForm';\nimport { Form } from '@/src/components/ui/form';\nimport React, { useEffect } from 'react';\nimport { useTerminationContext } from './context';\nimport { TerminationFormValues } from '@/src/flows/Termination/types';\nimport { OffboardingResponse, PostCreateOffboardingError } from '@/src/client';\nimport { useForm } from 'react-hook-form';\nimport { useJsonSchemasValidationFormResolver } from '@/src/components/form/yupValidationResolver';\n\ntype TerminationFormProps = {\n username: string;\n onSubmit?: (values: TerminationFormValues) => Promise<void>;\n onError?: (error: PostCreateOffboardingError) => void;\n onSuccess?: (data: OffboardingResponse) => void;\n};\n\nexport function TerminationForm({\n username,\n onSubmit,\n onError,\n onSuccess,\n}: TerminationFormProps) {\n const { formId, terminationBag } = useTerminationContext();\n\n const resolver = useJsonSchemasValidationFormResolver(\n // @ts-expect-error no matching type\n terminationBag.handleValidation,\n );\n\n const form = useForm({\n resolver,\n defaultValues: terminationBag?.initialValues,\n shouldUnregister: true,\n mode: 'onBlur',\n });\n\n useEffect(() => {\n const subscription = form?.watch((values) => {\n if (Object.keys(form.formState.dirtyFields).length > 0) {\n // TODO: for some reason isDirty doesn't work the first time we touch the form\n terminationBag?.checkFieldUpdates(\n values as Partial<TerminationFormValues>,\n );\n }\n });\n return () => subscription?.unsubscribe();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleSubmit = async (values: TerminationFormValues) => {\n await onSubmit?.(values);\n\n const terminationResult = await terminationBag?.onSubmit(values);\n\n if (terminationResult?.error) {\n onError?.(terminationResult.error);\n } else {\n if (terminationResult?.data) {\n onSuccess?.(terminationResult.data as OffboardingResponse);\n }\n }\n };\n\n const fields = terminationBag?.fields ? terminationBag.fields : [];\n\n const updatedFields = fields.map((field) => {\n if (field.name === 'acknowledge_termination_procedure') {\n return {\n ...field,\n label: (field.label as string).replace('{{username}}', username),\n };\n }\n return field;\n });\n\n return (\n <Form {...form}>\n <form\n id={formId}\n onSubmit={form.handleSubmit(handleSubmit)}\n className=\"space-y-4 RemoteFlows__TerminationForm\"\n >\n <JSONSchemaFormFields fields={updatedFields} />\n </form>\n </Form>\n );\n}\n"],"mappings":"wMAEA,OAAOA,GAAS,aAAAC,MAAiB,QAIjC,OAAS,WAAAC,MAAe,kBAUjB,SAASC,EAAgB,CAC9B,SAAAC,EACA,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyB,CACvB,GAAM,CAAE,OAAAC,EAAQ,eAAAC,CAAe,EAAIC,EAAsB,EAEnDC,EAAWC,EAEfH,EAAe,gBACjB,EAEMI,EAAOC,EAAQ,CACnB,SAAAH,EACA,cAAeF,GAAgB,cAC/B,iBAAkB,GAClB,KAAM,QACR,CAAC,EAEDM,EAAU,IAAM,CACd,IAAMC,EAAeH,GAAM,MAAOI,GAAW,CACvC,OAAO,KAAKJ,EAAK,UAAU,WAAW,EAAE,OAAS,GAEnDJ,GAAgB,kBACdQ,CACF,CAEJ,CAAC,EACD,MAAO,IAAMD,GAAc,YAAY,CAEzC,EAAG,CAAC,CAAC,EAEL,IAAME,EAAeC,EAAA,MAAOF,GAAkC,CAC5D,MAAMZ,IAAWY,CAAM,EAEvB,IAAMG,EAAoB,MAAMX,GAAgB,SAASQ,CAAM,EAE3DG,GAAmB,MACrBd,IAAUc,EAAkB,KAAK,EAE7BA,GAAmB,MACrBb,IAAYa,EAAkB,IAA2B,CAG/D,EAZqB,gBAgBfC,GAFSZ,GAAgB,OAASA,EAAe,OAAS,CAAC,GAEpC,IAAKa,GAC5BA,EAAM,OAAS,oCACV,CACL,GAAGA,EACH,MAAQA,EAAM,MAAiB,QAAQ,eAAgBlB,CAAQ,CACjE,EAEKkB,CACR,EAED,OACEC,EAAA,cAACC,EAAA,CAAM,GAAGX,GACRU,EAAA,cAAC,QACC,GAAIf,EACJ,SAAUK,EAAK,aAAaK,CAAY,EACxC,UAAU,0CAEVK,EAAA,cAACE,EAAA,CAAqB,OAAQJ,EAAe,CAC/C,CACF,CAEJ,CAtEgBF,EAAAhB,EAAA","names":["React","useEffect","useForm","TerminationForm","username","onSubmit","onError","onSuccess","formId","terminationBag","useTerminationContext","resolver","useJsonSchemasValidationFormResolver","form","useForm","useEffect","subscription","values","handleSubmit","__name","terminationResult","updatedFields","field","React","Form","JSONSchemaFormFields"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as e}from"./chunk-TIXDBKBM.js";import{b as m}from"./chunk-6HGUGIYJ.js";import{a as o}from"./chunk-AYDF3IFZ.js";import a from"react";import{useForm as A}from"react-hook-form";function v({onSubmit:i,onError:s,onSuccess:d}){let{contractAmendment:{values:c,isSubmitting:u,onSubmit:C},formId:f}=m(),n=A({defaultValues:c}),l=o(async r=>{await i?.(r);let t=await C(r);t.error?s?.(t.error):d?.(t.data)},"handleSubmit");return u?null:a.createElement(e,{...n},a.createElement("form",{id:f,onSubmit:n.handleSubmit(l),className:"RemoteFlows__ContractAmendmentConfirmationForm"}))}o(v,"ContractAmendmentConfirmationForm");export{v as a};
|
|
2
|
+
//# sourceMappingURL=chunk-ZCG5JUUR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flows/ContractAmendment/ContractAmendmentConfirmationForm.tsx"],"sourcesContent":["import {\n ContractAmendmentResponse,\n PostCreateContractAmendmentError,\n} from '@/src/client';\nimport { Form } from '@/src/components/ui/form';\nimport React from 'react';\nimport { FieldValues, useForm } from 'react-hook-form';\nimport { useContractAmendmentContext } from './context';\n\ntype ContractAmendmentConfirmationFormProps = {\n /**\n * Callback function to be called when the contract amendment form is submitted.\n * This function is called before the contract amendment is submitted.\n * It can be used to perform any additional validation or processing before\n * the contract amendment is submitted.\n * @param values\n * @returns\n */\n onSubmit?: (values: FieldValues) => Promise<void>;\n /**\n * Callback function to be called when the contract amendment fails.\n * @param error\n * @returns\n */\n onError?: (error: PostCreateContractAmendmentError) => void;\n /**\n * Callback function to be called when the contract amendment is successfully submitted.\n * @param data\n * @returns\n */\n onSuccess?: (data: ContractAmendmentResponse) => void;\n};\n\nexport function ContractAmendmentConfirmationForm({\n onSubmit,\n onError,\n onSuccess,\n}: ContractAmendmentConfirmationFormProps) {\n const {\n contractAmendment: {\n values,\n isSubmitting,\n onSubmit: submitContractAmendment,\n },\n formId,\n } = useContractAmendmentContext();\n const form = useForm({\n defaultValues: values,\n });\n\n const handleSubmit = async (values: FieldValues) => {\n await onSubmit?.(values);\n\n const contractAmendmentResult = await submitContractAmendment(values);\n\n if (contractAmendmentResult.error) {\n onError?.(\n contractAmendmentResult.error as PostCreateContractAmendmentError,\n );\n } else {\n onSuccess?.(contractAmendmentResult.data as ContractAmendmentResponse);\n }\n };\n\n // Ensure that step\n if (isSubmitting) {\n return null;\n }\n\n return (\n <Form {...form}>\n <form\n id={formId}\n onSubmit={form.handleSubmit(handleSubmit)}\n className=\"RemoteFlows__ContractAmendmentConfirmationForm\"\n ></form>\n </Form>\n );\n}\n"],"mappings":"wHAKA,OAAOA,MAAW,QAClB,OAAsB,WAAAC,MAAe,kBA2B9B,SAASC,EAAkC,CAChD,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAA2C,CACzC,GAAM,CACJ,kBAAmB,CACjB,OAAAC,EACA,aAAAC,EACA,SAAUC,CACZ,EACA,OAAAC,CACF,EAAIC,EAA4B,EAC1BC,EAAOC,EAAQ,CACnB,cAAeN,CACjB,CAAC,EAEKO,EAAeC,EAAA,MAAOR,GAAwB,CAClD,MAAMH,IAAWG,CAAM,EAEvB,IAAMS,EAA0B,MAAMP,EAAwBF,CAAM,EAEhES,EAAwB,MAC1BX,IACEW,EAAwB,KAC1B,EAEAV,IAAYU,EAAwB,IAAiC,CAEzE,EAZqB,gBAerB,OAAIR,EACK,KAIPS,EAAA,cAACC,EAAA,CAAM,GAAGN,GACRK,EAAA,cAAC,QACC,GAAIP,EACJ,SAAUE,EAAK,aAAaE,CAAY,EACxC,UAAU,iDACX,CACH,CAEJ,CA7CgBC,EAAAZ,EAAA","names":["React","useForm","ContractAmendmentConfirmationForm","onSubmit","onError","onSuccess","values","isSubmitting","submitContractAmendment","formId","useContractAmendmentContext","form","useForm","handleSubmit","__name","contractAmendmentResult","React","Form"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React__default, { PropsWithChildren, ButtonHTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function ContractAmendmentBack({ children, ...props }: PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>): React__default.JSX.Element;
|
|
4
|
+
|
|
5
|
+
export { ContractAmendmentBack };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { b as PostCreateContractAmendmentError, a as ContractAmendmentResponse } from '../../types.gen-BhkGMC9-.js';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
|
|
5
|
+
type ContractAmendmentConfirmationFormProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Callback function to be called when the contract amendment form is submitted.
|
|
8
|
+
* This function is called before the contract amendment is submitted.
|
|
9
|
+
* It can be used to perform any additional validation or processing before
|
|
10
|
+
* the contract amendment is submitted.
|
|
11
|
+
* @param values
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
onSubmit?: (values: FieldValues) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Callback function to be called when the contract amendment fails.
|
|
17
|
+
* @param error
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
onError?: (error: PostCreateContractAmendmentError) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Callback function to be called when the contract amendment is successfully submitted.
|
|
23
|
+
* @param data
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
onSuccess?: (data: ContractAmendmentResponse) => void;
|
|
27
|
+
};
|
|
28
|
+
declare function ContractAmendmentConfirmationForm({ onSubmit, onError, onSuccess, }: ContractAmendmentConfirmationFormProps): React__default.JSX.Element | null;
|
|
29
|
+
|
|
30
|
+
export { ContractAmendmentConfirmationForm };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a}from"../../chunk-ZCG5JUUR.js";import"../../chunk-TIXDBKBM.js";import"../../chunk-6HGUGIYJ.js";import"../../chunk-SJ56GVNV.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentConfirmationForm};
|
|
2
|
+
//# sourceMappingURL=ContractAmendmentConfirmationForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,19 +1,36 @@
|
|
|
1
|
+
import { ContractAmendmentConfirmationForm } from './ContractAmendmentConfirmationForm.js';
|
|
1
2
|
import React__default from 'react';
|
|
3
|
+
import { ContractAmendmentBack } from './ContractAmendmentBack.js';
|
|
2
4
|
import { ContractAmendmentForm } from './ContractAmendmentForm.js';
|
|
3
5
|
import { ContractAmendmentSubmit } from './ContractAmendmentSubmit.js';
|
|
4
|
-
import {
|
|
6
|
+
import { useContractAmendment } from './hooks.js';
|
|
5
7
|
import { ContractAmendmentParams } from './types.js';
|
|
6
|
-
import '../../types.gen-
|
|
7
|
-
import 'yup';
|
|
8
|
-
import '@remoteoss/json-schema-form';
|
|
8
|
+
import '../../types.gen-BhkGMC9-.js';
|
|
9
9
|
import 'react-hook-form';
|
|
10
|
+
import '../../mutations-v9H353tz.js';
|
|
11
|
+
import '@remoteoss/json-schema-form';
|
|
12
|
+
import '../useStepState.js';
|
|
10
13
|
|
|
11
14
|
type TUseContractAmendment = ReturnType<typeof useContractAmendment>;
|
|
12
15
|
type RenderProps = {
|
|
16
|
+
/**
|
|
17
|
+
* The contract amendment bag returned by the useContractAmendment hook.
|
|
18
|
+
* This bag contains all the methods and properties needed to handle the contract amendment flow.
|
|
19
|
+
* @see {@link useContractAmendment}
|
|
20
|
+
*/
|
|
13
21
|
contractAmendmentBag: TUseContractAmendment;
|
|
22
|
+
/**
|
|
23
|
+
* The components used in the contract amendment flow.
|
|
24
|
+
* This includes the form, submit button, and confirmation form.
|
|
25
|
+
* @see {@link ContractAmendmentForm}
|
|
26
|
+
* @see {@link ContractAmendmentSubmit}
|
|
27
|
+
* @see {@link ContractAmendmentConfirmationForm}
|
|
28
|
+
*/
|
|
14
29
|
components: {
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
Form: typeof ContractAmendmentForm;
|
|
31
|
+
SubmitButton: typeof ContractAmendmentSubmit;
|
|
32
|
+
ConfirmationForm: typeof ContractAmendmentConfirmationForm;
|
|
33
|
+
BackButton: typeof ContractAmendmentBack;
|
|
17
34
|
};
|
|
18
35
|
};
|
|
19
36
|
type ContractAmendmentFlowProps = ContractAmendmentParams & {
|
|
@@ -21,4 +38,4 @@ type ContractAmendmentFlowProps = ContractAmendmentParams & {
|
|
|
21
38
|
};
|
|
22
39
|
declare function ContractAmendmentFlow({ employmentId, countryCode, options, render, }: ContractAmendmentFlowProps): React__default.JSX.Element;
|
|
23
40
|
|
|
24
|
-
export { ContractAmendmentFlow };
|
|
41
|
+
export { ContractAmendmentFlow, type RenderProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../../chunk-
|
|
1
|
+
import{a}from"../../chunk-2DWTIFOU.js";import"../../chunk-5DQBY2TR.js";import"../../chunk-JWMY3OVH.js";import"../../chunk-JRQSZHUU.js";import"../../chunk-TPKAREI4.js";import"../../chunk-G2GI6FEO.js";import"../../chunk-6DMCAUPE.js";import"../../chunk-5PXYSIYN.js";import"../../chunk-37DREOGC.js";import"../../chunk-ZCG5JUUR.js";import"../../chunk-5YDR5BIG.js";import"../../chunk-LUCFM5TE.js";import"../../chunk-A4RX3KRZ.js";import"../../chunk-WRDKLT4N.js";import"../../chunk-FI76EKUS.js";import"../../chunk-TIXDBKBM.js";import"../../chunk-6HGUGIYJ.js";import"../../chunk-SJ56GVNV.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentFlow};
|
|
2
2
|
//# sourceMappingURL=ContractAmendmentFlow.js.map
|
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
import { P as PostAutomatableContractAmendmentError, C as ContractAmendmentAutomatableResponse } from '../../types.gen-BhkGMC9-.js';
|
|
1
2
|
import React__default from 'react';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
2
4
|
|
|
3
5
|
type ContractAmendmentFormProps = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Callback function to be called when the contract amendment form is submitted.
|
|
8
|
+
* This function is called before the contract amendment is submitted.
|
|
9
|
+
* It can be used to perform any additional validation or processing before
|
|
10
|
+
* the contract amendment is submitted.
|
|
11
|
+
* @param values
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
onSubmit?: (values: FieldValues) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Callback function to be called when the contract amendment fails.
|
|
17
|
+
* @param error
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
onError?: (error: PostAutomatableContractAmendmentError | {
|
|
21
|
+
message: 'no_changes_detected_contract_details';
|
|
22
|
+
}) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Callback function to be called when the contract amendment is successfully submitted.
|
|
25
|
+
* This function is called after the contract amendment is submitted.
|
|
26
|
+
* @param data
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
onSuccess?: (data: ContractAmendmentAutomatableResponse) => void;
|
|
7
30
|
};
|
|
8
31
|
declare function ContractAmendmentForm({ onSubmit, onError, onSuccess, }: ContractAmendmentFormProps): React__default.JSX.Element;
|
|
9
32
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../../chunk-
|
|
1
|
+
import{a}from"../../chunk-5YDR5BIG.js";import"../../chunk-LUCFM5TE.js";import"../../chunk-A4RX3KRZ.js";import"../../chunk-WRDKLT4N.js";import"../../chunk-FI76EKUS.js";import"../../chunk-TIXDBKBM.js";import"../../chunk-6HGUGIYJ.js";import"../../chunk-SJ56GVNV.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentForm};
|
|
2
2
|
//# sourceMappingURL=ContractAmendmentForm.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default, { PropsWithChildren, ButtonHTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
|
-
declare function ContractAmendmentSubmit(props: PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>): React__default.JSX.Element;
|
|
3
|
+
declare function ContractAmendmentSubmit({ children, ...props }: PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>): React__default.JSX.Element;
|
|
4
4
|
|
|
5
5
|
export { ContractAmendmentSubmit };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../../chunk-
|
|
1
|
+
import{a}from"../../chunk-5DQBY2TR.js";import"../../chunk-FI76EKUS.js";import"../../chunk-6HGUGIYJ.js";import"../../chunk-SJ56GVNV.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentSubmit};
|
|
2
2
|
//# sourceMappingURL=ContractAmendmentSubmit.js.map
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { C as ContractAmendmentResponse, P as PostCreateContractAmendmentError } from '../../types.gen-DCJSPsGk.js';
|
|
1
|
+
import { S as SuccessResponse, E as ErrorResponse } from '../../mutations-v9H353tz.js';
|
|
2
|
+
import { C as ContractAmendmentAutomatableResponse, P as PostAutomatableContractAmendmentError, a as ContractAmendmentResponse, b as PostCreateContractAmendmentError } from '../../types.gen-BhkGMC9-.js';
|
|
4
3
|
import * as _remoteoss_json_schema_form from '@remoteoss/json-schema-form';
|
|
5
4
|
import * as React from 'react';
|
|
6
5
|
import * as react_hook_form from 'react-hook-form';
|
|
7
|
-
import {
|
|
6
|
+
import { useContractAmendment } from './hooks.js';
|
|
7
|
+
import { Step } from '../useStepState.js';
|
|
8
8
|
import './types.js';
|
|
9
9
|
|
|
10
|
-
type ContractAmendmentFormValues = {
|
|
11
|
-
effective_date: string;
|
|
12
|
-
job_title: string | undefined;
|
|
13
|
-
additional_comments: string;
|
|
14
|
-
};
|
|
15
10
|
declare const ContractAmendmentContext: React.Context<{
|
|
16
|
-
form: UseFormReturn<ContractAmendmentFormValues> | null;
|
|
17
11
|
formId: string | undefined;
|
|
18
12
|
contractAmendmentBag: ReturnType<typeof useContractAmendment> | null;
|
|
19
13
|
}>;
|
|
20
14
|
declare const useContractAmendmentContext: () => {
|
|
21
|
-
readonly form: UseFormReturn<ContractAmendmentFormValues>;
|
|
22
15
|
readonly formId: string | undefined;
|
|
23
16
|
readonly contractAmendment: {
|
|
24
17
|
stepState: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
currentStep: Step;
|
|
19
|
+
totalSteps: number;
|
|
20
|
+
values: {
|
|
21
|
+
form: react_hook_form.FieldValues;
|
|
22
|
+
confirmation_form: react_hook_form.FieldValues;
|
|
23
|
+
} | null;
|
|
28
24
|
};
|
|
29
25
|
fields: _remoteoss_json_schema_form.Fields;
|
|
30
26
|
isLoading: boolean;
|
|
27
|
+
isError: boolean;
|
|
28
|
+
error: Error | null;
|
|
31
29
|
isSubmitting: boolean;
|
|
32
|
-
initialValues: {
|
|
33
|
-
|
|
34
|
-
reason_for_change: string;
|
|
35
|
-
job_title: string | undefined;
|
|
36
|
-
additional_comments: string;
|
|
37
|
-
annual_gross_salary: number | null;
|
|
38
|
-
};
|
|
39
|
-
validationSchema: yup.AnyObjectSchema;
|
|
30
|
+
initialValues: {};
|
|
31
|
+
values: react_hook_form.FieldValues;
|
|
40
32
|
handleValidation: (values: react_hook_form.FieldValues) => {
|
|
41
33
|
yupError: _remoteoss_json_schema_form.$TSFixMe;
|
|
42
34
|
formErrors: _remoteoss_json_schema_form.$TSFixMe;
|
|
43
35
|
} | null;
|
|
44
|
-
checkFieldUpdates:
|
|
36
|
+
checkFieldUpdates: React.Dispatch<React.SetStateAction<react_hook_form.FieldValues>>;
|
|
45
37
|
onSubmit: (values: react_hook_form.FieldValues) => Promise<SuccessResponse<({
|
|
38
|
+
data: ContractAmendmentAutomatableResponse;
|
|
39
|
+
error: undefined;
|
|
40
|
+
} | {
|
|
41
|
+
data: undefined;
|
|
42
|
+
error: PostAutomatableContractAmendmentError;
|
|
43
|
+
}) & {
|
|
44
|
+
request: Request;
|
|
45
|
+
response: Response;
|
|
46
|
+
}> | ErrorResponse<Error> | SuccessResponse<({
|
|
46
47
|
data: ContractAmendmentResponse;
|
|
47
48
|
error: undefined;
|
|
48
49
|
} | {
|
|
@@ -51,7 +52,8 @@ declare const useContractAmendmentContext: () => {
|
|
|
51
52
|
}) & {
|
|
52
53
|
request: Request;
|
|
53
54
|
response: Response;
|
|
54
|
-
}
|
|
55
|
+
}>>;
|
|
56
|
+
back: () => void;
|
|
55
57
|
};
|
|
56
58
|
};
|
|
57
59
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../../chunk-
|
|
1
|
+
import{a,b}from"../../chunk-6HGUGIYJ.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentContext,b as useContractAmendmentContext};
|
|
2
2
|
//# sourceMappingURL=context.js.map
|
|
@@ -1,6 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../types.gen-
|
|
3
|
-
import '
|
|
4
|
-
import '@remoteoss/json-schema-form';
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
1
|
+
import { S as SuccessResponse, E as ErrorResponse } from '../../mutations-v9H353tz.js';
|
|
2
|
+
import { C as ContractAmendmentAutomatableResponse, P as PostAutomatableContractAmendmentError, a as ContractAmendmentResponse, b as PostCreateContractAmendmentError } from '../../types.gen-BhkGMC9-.js';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import * as _remoteoss_json_schema_form from '@remoteoss/json-schema-form';
|
|
5
|
+
import { Step } from '../useStepState.js';
|
|
6
|
+
import { ContractAmendmentParams } from './types.js';
|
|
7
|
+
import { FieldValues } from 'react-hook-form';
|
|
8
|
+
|
|
9
|
+
declare const useContractAmendment: ({ employmentId, countryCode, options, }: ContractAmendmentParams) => {
|
|
10
|
+
/**
|
|
11
|
+
* Current step state containing the current step and total number of steps
|
|
12
|
+
*/
|
|
13
|
+
stepState: {
|
|
14
|
+
currentStep: Step;
|
|
15
|
+
totalSteps: number;
|
|
16
|
+
values: {
|
|
17
|
+
form: FieldValues;
|
|
18
|
+
confirmation_form: FieldValues;
|
|
19
|
+
} | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Array of form fields from the contract amendment schema
|
|
23
|
+
*/
|
|
24
|
+
fields: _remoteoss_json_schema_form.Fields;
|
|
25
|
+
/**
|
|
26
|
+
* Loading state indicating if either employment or contract amendment data is being fetched
|
|
27
|
+
*/
|
|
28
|
+
isLoading: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Error state indicating if there was an error fetching either employment or contract amendment data
|
|
31
|
+
*/
|
|
32
|
+
isError: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Error object containing details about any errors that occurred during data fetching
|
|
35
|
+
*/
|
|
36
|
+
error: Error | null;
|
|
37
|
+
/**
|
|
38
|
+
* Loading state indicating if a contract amendment mutation is in progress
|
|
39
|
+
*/
|
|
40
|
+
isSubmitting: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Initial form values built from employment data and contract amendment fields
|
|
43
|
+
*/
|
|
44
|
+
initialValues: {};
|
|
45
|
+
/**
|
|
46
|
+
* Current form field values
|
|
47
|
+
*/
|
|
48
|
+
values: FieldValues;
|
|
49
|
+
/**
|
|
50
|
+
* Function to validate form values against the contract amendment schema
|
|
51
|
+
* @param values - Form values to validate
|
|
52
|
+
* @returns Validation result or null if no schema is available
|
|
53
|
+
*/
|
|
54
|
+
handleValidation: (values: FieldValues) => {
|
|
55
|
+
yupError: _remoteoss_json_schema_form.$TSFixMe;
|
|
56
|
+
formErrors: _remoteoss_json_schema_form.$TSFixMe;
|
|
57
|
+
} | null;
|
|
58
|
+
/**
|
|
59
|
+
* Function to update the current form field values
|
|
60
|
+
* @param values - New form values to set
|
|
61
|
+
*/
|
|
62
|
+
checkFieldUpdates: React.Dispatch<React.SetStateAction<FieldValues>>;
|
|
63
|
+
/**
|
|
64
|
+
* Function to handle form submission
|
|
65
|
+
* @param values - Form values to submit
|
|
66
|
+
* @returns Promise resolving to the mutation result
|
|
67
|
+
*/
|
|
68
|
+
onSubmit: (values: FieldValues) => Promise<SuccessResponse<({
|
|
69
|
+
data: ContractAmendmentAutomatableResponse;
|
|
70
|
+
error: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
data: undefined;
|
|
73
|
+
error: PostAutomatableContractAmendmentError;
|
|
74
|
+
}) & {
|
|
75
|
+
request: Request;
|
|
76
|
+
response: Response;
|
|
77
|
+
}> | ErrorResponse<Error> | SuccessResponse<({
|
|
78
|
+
data: ContractAmendmentResponse;
|
|
79
|
+
error: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
data: undefined;
|
|
82
|
+
error: PostCreateContractAmendmentError;
|
|
83
|
+
}) & {
|
|
84
|
+
request: Request;
|
|
85
|
+
response: Response;
|
|
86
|
+
}>>;
|
|
87
|
+
/**
|
|
88
|
+
* Function to handle going back to the previous step
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
back: () => void;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { useContractAmendment };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../../chunk-
|
|
1
|
+
import{a}from"../../chunk-JWMY3OVH.js";import"../../chunk-JRQSZHUU.js";import"../../chunk-TPKAREI4.js";import"../../chunk-G2GI6FEO.js";import"../../chunk-6DMCAUPE.js";import"../../chunk-5PXYSIYN.js";import"../../chunk-WRDKLT4N.js";import"../../chunk-AYDF3IFZ.js";export{a as useContractAmendment};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ContractAmendmentConfirmationForm } from './ContractAmendmentConfirmationForm.js';
|
|
2
|
+
export { ContractAmendmentFlow, RenderProps } from './ContractAmendmentFlow.js';
|
|
2
3
|
export { ContractAmendmentForm } from './ContractAmendmentForm.js';
|
|
3
4
|
export { ContractAmendmentSubmit } from './ContractAmendmentSubmit.js';
|
|
4
|
-
export {
|
|
5
|
+
export { useContractAmendment } from './hooks.js';
|
|
6
|
+
import '../../types.gen-BhkGMC9-.js';
|
|
5
7
|
import 'react';
|
|
8
|
+
import 'react-hook-form';
|
|
9
|
+
import './ContractAmendmentBack.js';
|
|
6
10
|
import './types.js';
|
|
7
|
-
import '../../
|
|
8
|
-
import 'yup';
|
|
11
|
+
import '../../mutations-v9H353tz.js';
|
|
9
12
|
import '@remoteoss/json-schema-form';
|
|
10
|
-
import '
|
|
13
|
+
import '../useStepState.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../chunk-
|
|
1
|
+
import"../../chunk-A7ZJQCNU.js";import{a as e}from"../../chunk-2DWTIFOU.js";import{a as c}from"../../chunk-5DQBY2TR.js";import{a as d}from"../../chunk-JWMY3OVH.js";import"../../chunk-JRQSZHUU.js";import"../../chunk-TPKAREI4.js";import"../../chunk-G2GI6FEO.js";import"../../chunk-6DMCAUPE.js";import"../../chunk-5PXYSIYN.js";import"../../chunk-37DREOGC.js";import{a}from"../../chunk-ZCG5JUUR.js";import{a as b}from"../../chunk-5YDR5BIG.js";import"../../chunk-LUCFM5TE.js";import"../../chunk-A4RX3KRZ.js";import"../../chunk-WRDKLT4N.js";import"../../chunk-FI76EKUS.js";import"../../chunk-TIXDBKBM.js";import"../../chunk-6HGUGIYJ.js";import"../../chunk-SJ56GVNV.js";import"../../chunk-AYDF3IFZ.js";export{a as ContractAmendmentConfirmationForm,e as ContractAmendmentFlow,b as ContractAmendmentForm,c as ContractAmendmentSubmit,d as useContractAmendment};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { E as EmploymentShowResponse } from '../../types.gen-BhkGMC9-.js';
|
|
2
|
+
import { Fields } from '@remoteoss/json-schema-form';
|
|
3
|
+
import { Step } from '../useStepState.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
type StepKeys = 'form' | 'confirmation_form';
|
|
8
|
+
declare const STEPS: Record<StepKeys, Step>;
|
|
9
|
+
declare function buildInitialValues(employment: EmploymentShowResponse | undefined, fields?: Fields | undefined): {};
|
|
10
|
+
|
|
11
|
+
export { STEPS, buildInitialValues };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -3,7 +3,7 @@ import { CostCalculatorEstimationOptions, JSFModify } from './types.js';
|
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import 'yup';
|
|
5
5
|
import '@tanstack/react-query';
|
|
6
|
-
import '../../types.gen-
|
|
6
|
+
import '../../types.gen-BhkGMC9-.js';
|
|
7
7
|
import '../types.js';
|
|
8
8
|
import '@remoteoss/json-schema-form';
|
|
9
9
|
|
|
@@ -34,6 +34,6 @@ type CostCalculatorFlowProps = {
|
|
|
34
34
|
};
|
|
35
35
|
render: (costCalculatorBag: ReturnType<typeof useCostCalculator>) => React__default.ReactNode;
|
|
36
36
|
};
|
|
37
|
-
declare const CostCalculatorFlow: ({ estimationOptions, defaultValues, options, render, }: CostCalculatorFlowProps) =>
|
|
37
|
+
declare const CostCalculatorFlow: ({ estimationOptions, defaultValues, options, render, }: CostCalculatorFlowProps) => React__default.JSX.Element;
|
|
38
38
|
|
|
39
39
|
export { CostCalculatorFlow, type CostCalculatorFlowProps };
|