@gusto/embedded-react-sdk 0.55.3 → 0.55.5

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/components/Common/DataView/DataCards/DataCards.d.ts +2 -1
  3. package/dist/components/Common/DataView/DataCards/DataCards.js +63 -54
  4. package/dist/components/Common/DataView/DataCards/DataCards.js.map +1 -1
  5. package/dist/components/Common/DataView/DataCards/DataCards.module.scss.js +14 -12
  6. package/dist/components/Common/DataView/DataCards/DataCards.module.scss.js.map +1 -1
  7. package/dist/components/Common/DataView/DataTable/DataTable.d.ts +2 -1
  8. package/dist/components/Common/DataView/DataTable/DataTable.js +75 -66
  9. package/dist/components/Common/DataView/DataTable/DataTable.js.map +1 -1
  10. package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js +8 -4
  11. package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js.map +1 -1
  12. package/dist/components/Common/DataView/DataView.js +18 -17
  13. package/dist/components/Common/DataView/DataView.js.map +1 -1
  14. package/dist/components/Company/Locations/LocationsList/List.js +27 -25
  15. package/dist/components/Company/Locations/LocationsList/List.js.map +1 -1
  16. package/dist/components/Company/Locations/LocationsList/LocationsList.js +41 -36
  17. package/dist/components/Company/Locations/LocationsList/LocationsList.js.map +1 -1
  18. package/dist/components/Company/Locations/LocationsList/useLocationsList.d.ts +1 -0
  19. package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
  20. package/dist/components/Company/StateTaxes/StateTaxesForm/Form.d.ts +9 -2
  21. package/dist/components/Company/StateTaxes/StateTaxesForm/Form.js +19 -18
  22. package/dist/components/Company/StateTaxes/StateTaxesForm/Form.js.map +1 -1
  23. package/dist/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.js +63 -62
  24. package/dist/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.js.map +1 -1
  25. package/dist/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.js +69 -65
  26. package/dist/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.js.map +1 -1
  27. package/dist/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.js +30 -23
  28. package/dist/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.js.map +1 -1
  29. package/dist/components/Company/StateTaxes/shared/RequirementFields.d.ts +8 -4
  30. package/dist/components/Company/StateTaxes/shared/RequirementFields.js +13 -12
  31. package/dist/components/Company/StateTaxes/shared/RequirementFields.js.map +1 -1
  32. package/dist/components/Company/StateTaxes/shared/prepareRequirements.d.ts +29 -0
  33. package/dist/components/Company/StateTaxes/shared/prepareRequirements.js +24 -0
  34. package/dist/components/Company/StateTaxes/shared/prepareRequirements.js.map +1 -0
  35. package/dist/components/Company/StateTaxes/shared/prepareRequirements.test.d.ts +1 -0
  36. package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js +68 -55
  37. package/dist/components/Contractor/Payments/PaymentsList/PaymentsList.js.map +1 -1
  38. package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js +36 -35
  39. package/dist/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.js.map +1 -1
  40. package/dist/components/Employee/Paystubs/management/PaystubsCard/PaystubsCard.js +84 -96
  41. package/dist/components/Employee/Paystubs/management/PaystubsCard/PaystubsCard.js.map +1 -1
  42. package/dist/components/Flow/Flow.js +22 -22
  43. package/dist/components/Flow/Flow.js.map +1 -1
  44. package/dist/components/Flow/useFlow.js +3 -3
  45. package/dist/components/InformationRequests/InformationRequests.d.ts +1 -1
  46. package/dist/components/InformationRequests/InformationRequests.js +66 -52
  47. package/dist/components/InformationRequests/InformationRequests.js.map +1 -1
  48. package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +52 -50
  49. package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
  50. package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.d.ts +1 -1
  51. package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js +86 -67
  52. package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js.map +1 -1
  53. package/dist/components/Payroll/OffCycleCreation/OffCycleCreationTypes.d.ts +4 -0
  54. package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.d.ts +1 -1
  55. package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.js +26 -21
  56. package/dist/components/Payroll/OffCycleDeductionsSetting/OffCycleDeductionsSetting.js.map +1 -1
  57. package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.d.ts +8 -1
  58. package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.js +29 -17
  59. package/dist/components/Payroll/OffCyclePayPeriodDateForm/OffCyclePayPeriodDateFormPresentation.js.map +1 -1
  60. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.js +21 -18
  61. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.js.map +1 -1
  62. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.module.scss.js +9 -7
  63. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTable.module.scss.js.map +1 -1
  64. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTableTypes.d.ts +2 -0
  65. package/dist/components/Payroll/OffCycleTaxWithholdingTable/OffCycleTaxWithholdingTableTypes.js.map +1 -1
  66. package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +193 -191
  67. package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
  68. package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.d.ts +3 -2
  69. package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +31 -31
  70. package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
  71. package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.js +254 -243
  72. package/dist/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.js.map +1 -1
  73. package/dist/components/Payroll/PayrollHistory/PayrollHistory.js +83 -76
  74. package/dist/components/Payroll/PayrollHistory/PayrollHistory.js.map +1 -1
  75. package/dist/components/Payroll/PayrollHistory/PayrollHistoryPresentation.js +23 -22
  76. package/dist/components/Payroll/PayrollHistory/PayrollHistoryPresentation.js.map +1 -1
  77. package/dist/components/Payroll/PayrollList/PayrollList.js +108 -97
  78. package/dist/components/Payroll/PayrollList/PayrollList.js.map +1 -1
  79. package/dist/components/Payroll/PayrollList/PayrollListPresentation.js +38 -37
  80. package/dist/components/Payroll/PayrollList/PayrollListPresentation.js.map +1 -1
  81. package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +176 -167
  82. package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
  83. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.d.ts +2 -1
  84. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js +173 -164
  85. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js.map +1 -1
  86. package/dist/helpers/openPdfInNewTab.d.ts +15 -0
  87. package/dist/helpers/openPdfInNewTab.js +28 -0
  88. package/dist/helpers/openPdfInNewTab.js.map +1 -0
  89. package/dist/i18n/en/Company.StateTaxes.json.js +1 -1
  90. package/dist/i18n/en/Payroll.OffCycleCreation.json.js +11 -9
  91. package/dist/i18n/en/Payroll.OffCycleCreation.json.js.map +1 -1
  92. package/dist/i18n/en/Payroll.OffCycleTaxWithholding.json.js +7 -7
  93. package/dist/i18n/en/Payroll.PayrollEditEmployee.json.js +29 -27
  94. package/dist/i18n/en/Payroll.PayrollEditEmployee.json.js.map +1 -1
  95. package/dist/i18n/en/Payroll.PayrollOverview.json.js +43 -41
  96. package/dist/i18n/en/Payroll.PayrollOverview.json.js.map +1 -1
  97. package/dist/i18n/types.d.ts +20 -0
  98. package/dist/style.css +1 -1
  99. package/package.json +17 -17
@@ -1 +1 @@
1
- {"version":3,"file":"StateTaxesForm.js","sources":["../../../../../src/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.tsx"],"sourcesContent":["import { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useTaxRequirementsUpdateStateMutation } from '@gusto/embedded-api/react-query/taxRequirementsUpdateState'\nimport { useTaxRequirementsGetSuspense } from '@gusto/embedded-api/react-query/taxRequirementsGet'\nimport { z } from 'zod'\nimport { useMemo } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { Head } from './Head'\nimport { StateTaxesFormProvider } from './context'\nimport { Form } from './Form'\nimport { Actions } from './Actions'\nimport type { BaseComponentInterface } from '@/components/Base/Base'\nimport { BaseComponent } from '@/components/Base/Base'\nimport { useI18n } from '@/i18n/I18n'\nimport { Flex } from '@/components/Common/Flex/Flex'\nimport { Form as HtmlForm } from '@/components/Common/Form'\nimport { componentEvents } from '@/shared/constants'\nimport { useBase } from '@/components/Base'\n\n/**\n * Props for {@link StateTaxesForm}.\n *\n * @public\n */\nexport interface StateTaxesFormProps extends BaseComponentInterface<'Company.StateTaxes'> {\n /** The associated company identifier. */\n companyId: string\n /** Two-letter code of the state whose tax requirements are edited. */\n state: string\n}\n\n/**\n * Standalone form for editing a company's state tax requirements for a single state.\n *\n * @remarks\n * Lower-level building block used by {@link StateTaxes} for its edit view. Use directly when\n * you need full control over navigation between the list and edit views.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `company/stateTaxes/updated` | State tax requirements were saved successfully | Response from the update state tax requirements API |\n * | `CANCEL` | The user cancelled editing | — |\n *\n * @param props - {@link StateTaxesFormProps}\n * @returns The rendered state taxes edit form.\n * @public\n *\n * @example\n * ```tsx\n * import { CompanyOnboarding } from '@gusto/embedded-react-sdk'\n *\n * function MyComponent() {\n * return (\n * <CompanyOnboarding.StateTaxesForm\n * companyId=\"a007e1ab-3595-43c2-ab4b-af7a5af2e365\"\n * state=\"CA\"\n * onEvent={() => {}}\n * />\n * )\n * }\n * ```\n */\nexport function StateTaxesForm(props: StateTaxesFormProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nfunction Root({ companyId, state, className, children }: StateTaxesFormProps) {\n useI18n('Company.StateTaxes')\n const { onEvent, baseSubmitHandler } = useBase()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { data } = useTaxRequirementsGetSuspense({ companyUuid: companyId, state })\n const stateTaxRequirements = data.taxRequirementsState!\n\n const { mutateAsync: updateStateTax, isPending: isPendingUpdate } =\n useTaxRequirementsUpdateStateMutation()\n\n // Schema and default value generation\n const { dynamicSchema, defaultValues } = useMemo(() => {\n const schemaShape: Record<string, z.ZodObject> = {}\n const values: Partial<Record<string, Record<string, string | boolean | number | undefined>>> =\n {}\n const requirementSets = stateTaxRequirements.requirementSets ?? []\n\n //Looping through each requirement set. A single key (e.g. \"taxrates\") can appear more than\n //once when a future-dated set is already scheduled alongside the current one, so each set\n //needs its own disambiguated path — otherwise two visually distinct sections would silently\n //share one underlying form field.\n requirementSets.forEach((requirementSet, index) => {\n if (!requirementSet.key) return\n\n const requirementSetPath = getUniqueRhfKey(requirementSet, index, requirementSets)\n const { shape, defaults } = buildRequirementSchema(requirementSet.requirements, t)\n\n if (Object.keys(shape).length > 0) {\n schemaShape[requirementSetPath] = z.object(shape)\n values[requirementSetPath] = defaults\n }\n })\n\n const finalSchema = z.object(schemaShape)\n\n // Return both the schema and the default values\n return {\n dynamicSchema: finalSchema,\n defaultValues: values as z.infer<typeof finalSchema>,\n }\n }, [stateTaxRequirements, t])\n\n // Infer the type from the schema\n type InferredFormInputs = z.infer<typeof dynamicSchema>\n\n const { control, ...methods } = useForm({\n resolver: zodResolver(dynamicSchema),\n defaultValues,\n })\n\n const onSubmit = async (formData: InferredFormInputs) => {\n await baseSubmitHandler(formData, async payload => {\n const formValues = payload as StateTaxesFormValues\n const allRequirementSets = stateTaxRequirements.requirementSets ?? []\n const requirementSets = allRequirementSets\n .map((requirementSet, setIndex) => ({ requirementSet, setIndex }))\n .filter(({ requirementSet, setIndex }) => {\n if (!requirementSet.key) return false\n const requirementSetPath = getUniqueRhfKey(requirementSet, setIndex, allRequirementSets)\n return Boolean(payload[requirementSetPath])\n })\n .map(({ requirementSet, setIndex }) => {\n const requirementSetKey = requirementSet.key as string\n const requirementSetPath = getUniqueRhfKey(requirementSet, setIndex, allRequirementSets)\n const payloadSet = payload[requirementSetPath] as Record<string, unknown>\n const requirements = requirementSet.requirements ?? []\n\n const applicableRequirements = requirements\n .map((req, index) => ({ req, index }))\n .filter(({ req }) => req.editable !== false)\n .filter(({ req }) => isRequirementApplicable(req, requirementSetPath, formValues))\n\n return {\n state,\n key: requirementSetKey,\n effectiveFrom: requirementSet.effectiveFrom,\n requirements: applicableRequirements.map(({ req, index }) => ({\n key: req.key as string,\n value: stringifyRequirementValue(\n payloadSet[getUniqueRhfKey(req, index, requirements)],\n ),\n })),\n }\n })\n await updateStateTax({\n request: {\n companyUuid: companyId,\n requestBody: { requirementSets },\n state,\n },\n })\n onEvent(componentEvents.COMPANY_STATE_TAX_UPDATED)\n })\n }\n\n const handleCancel = () => {\n onEvent(componentEvents.CANCEL)\n }\n\n return (\n <section className={className}>\n <FormProvider {...methods} control={control}>\n <HtmlForm onSubmit={methods.handleSubmit(onSubmit)}>\n <StateTaxesFormProvider\n value={{ stateTaxRequirements, isPending: isPendingUpdate, state, handleCancel }}\n >\n <Flex flexDirection=\"column\" gap={32}>\n {children ? (\n children\n ) : (\n <>\n <Head />\n <Form />\n <Actions />\n </>\n )}\n </Flex>\n </StateTaxesFormProvider>\n </HtmlForm>\n </FormProvider>\n </section>\n )\n}\n"],"names":["StateTaxesForm","props","jsx","BaseComponent","Root","companyId","state","className","children","useI18n","onEvent","baseSubmitHandler","useBase","t","useTranslation","data","useTaxRequirementsGetSuspense","stateTaxRequirements","updateStateTax","isPendingUpdate","useTaxRequirementsUpdateStateMutation","dynamicSchema","defaultValues","useMemo","schemaShape","values","requirementSets","requirementSet","index","requirementSetPath","getUniqueRhfKey","shape","defaults","buildRequirementSchema","z","control","methods","useForm","zodResolver","onSubmit","formData","payload","formValues","allRequirementSets","setIndex","requirementSetKey","payloadSet","requirements","applicableRequirements","req","isRequirementApplicable","stringifyRequirementValue","componentEvents","handleCancel","FormProvider","HtmlForm","StateTaxesFormProvider","Flex","jsxs","Fragment","Head","Form","Actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmEO,SAASA,GAAeC,GAA4B;AACzD,SACE,gBAAAC,EAACC,GAAA,EAAe,GAAGF,GACjB,UAAA,gBAAAC,EAACE,MAAM,GAAGH,GAAQ,UAAAA,EAAM,SAAA,CAAS,EAAA,CACnC;AAEJ;AAEA,SAASG,GAAK,EAAE,WAAAC,GAAW,OAAAC,GAAO,WAAAC,GAAW,UAAAC,KAAiC;AAC5E,EAAAC,EAAQ,oBAAoB;AAC5B,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAA,IAAsBC,GAAA,GACjC,EAAE,GAAAC,MAAMC,EAAe,sBAAsB,EAAE,WAAW,QAAQ,GAClE,EAAE,MAAAC,MAASC,EAA8B,EAAE,aAAaX,GAAW,OAAAC,GAAO,GAC1EW,IAAuBF,EAAK,sBAE5B,EAAE,aAAaG,GAAgB,WAAWC,EAAA,IAC9CC,EAAA,GAGI,EAAE,eAAAC,GAAe,eAAAC,EAAA,IAAkBC,EAAQ,MAAM;AACrD,UAAMC,IAA2C,CAAA,GAC3CC,IACJ,CAAA,GACIC,IAAkBT,EAAqB,mBAAmB,CAAA;AAMhE,WAAA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AAC0D,GAAA,EAAK;AAAA,0BACLC,GAAA,EAAK;AAAA,0BACLC,GAAA,CAAA,CAAQ;AAAA,MAAA,EAAA,CACX,EAAA,CAEJ;AAAA,IAAA;AAAA,EAAA,EACF,CACF,GACF,GACF;AAEJ;"}
1
+ {"version":3,"file":"StateTaxesForm.js","sources":["../../../../../src/components/Company/StateTaxes/StateTaxesForm/StateTaxesForm.tsx"],"sourcesContent":["import { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useTaxRequirementsUpdateStateMutation } from '@gusto/embedded-api/react-query/taxRequirementsUpdateState'\nimport { useTaxRequirementsGetSuspense } from '@gusto/embedded-api/react-query/taxRequirementsGet'\nimport { z } from 'zod'\nimport { useMemo } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { prepareRequirements } from '../shared/prepareRequirements'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { Head } from './Head'\nimport { StateTaxesFormProvider } from './context'\nimport { Form } from './Form'\nimport { Actions } from './Actions'\nimport type { BaseComponentInterface } from '@/components/Base/Base'\nimport { BaseComponent } from '@/components/Base/Base'\nimport { useI18n } from '@/i18n/I18n'\nimport { Flex } from '@/components/Common/Flex/Flex'\nimport { Form as HtmlForm } from '@/components/Common/Form'\nimport { componentEvents } from '@/shared/constants'\nimport { useBase } from '@/components/Base'\n\n/**\n * Props for {@link StateTaxesForm}.\n *\n * @public\n */\nexport interface StateTaxesFormProps extends BaseComponentInterface<'Company.StateTaxes'> {\n /** The associated company identifier. */\n companyId: string\n /** Two-letter code of the state whose tax requirements are edited. */\n state: string\n}\n\n/**\n * Standalone form for editing a company's state tax requirements for a single state.\n *\n * @remarks\n * Lower-level building block used by {@link StateTaxes} for its edit view. Use directly when\n * you need full control over navigation between the list and edit views.\n *\n * @events\n * | Event | Description | Data |\n * | ----- | ----------- | ---- |\n * | `company/stateTaxes/updated` | State tax requirements were saved successfully | Response from the update state tax requirements API |\n * | `CANCEL` | The user cancelled editing | — |\n *\n * @param props - {@link StateTaxesFormProps}\n * @returns The rendered state taxes edit form.\n * @public\n *\n * @example\n * ```tsx\n * import { CompanyOnboarding } from '@gusto/embedded-react-sdk'\n *\n * function MyComponent() {\n * return (\n * <CompanyOnboarding.StateTaxesForm\n * companyId=\"a007e1ab-3595-43c2-ab4b-af7a5af2e365\"\n * state=\"CA\"\n * onEvent={() => {}}\n * />\n * )\n * }\n * ```\n */\nexport function StateTaxesForm(props: StateTaxesFormProps) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nfunction Root({ companyId, state, className, children }: StateTaxesFormProps) {\n useI18n('Company.StateTaxes')\n const { onEvent, baseSubmitHandler } = useBase()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { data } = useTaxRequirementsGetSuspense({ companyUuid: companyId, state })\n const stateTaxRequirements = data.taxRequirementsState!\n\n const { mutateAsync: updateStateTax, isPending: isPendingUpdate } =\n useTaxRequirementsUpdateStateMutation()\n\n // Schema and default value generation\n const { dynamicSchema, defaultValues } = useMemo(() => {\n const schemaShape: Record<string, z.ZodObject> = {}\n const values: Partial<Record<string, Record<string, string | boolean | number | undefined>>> =\n {}\n const requirementSets = stateTaxRequirements.requirementSets ?? []\n\n //Looping through each requirement set. A single key (e.g. \"taxrates\") can appear more than\n //once when a future-dated set is already scheduled alongside the current one, so each set\n //needs its own disambiguated path — otherwise two visually distinct sections would silently\n //share one underlying form field.\n requirementSets.forEach((requirementSet, index) => {\n if (!requirementSet.key) return\n\n const requirementSetPath = getUniqueRhfKey(requirementSet, index, requirementSets)\n const preparedRequirements = prepareRequirements(requirementSet.requirements ?? [])\n const { shape, defaults } = buildRequirementSchema(preparedRequirements, t)\n\n if (Object.keys(shape).length > 0) {\n schemaShape[requirementSetPath] = z.object(shape)\n values[requirementSetPath] = defaults\n }\n })\n\n const finalSchema = z.object(schemaShape)\n\n // Return both the schema and the default values\n return {\n dynamicSchema: finalSchema,\n defaultValues: values as z.infer<typeof finalSchema>,\n }\n }, [stateTaxRequirements, t])\n\n // Infer the type from the schema\n type InferredFormInputs = z.infer<typeof dynamicSchema>\n\n const { control, ...methods } = useForm({\n resolver: zodResolver(dynamicSchema),\n defaultValues,\n })\n\n const onSubmit = async (formData: InferredFormInputs) => {\n await baseSubmitHandler(formData, async payload => {\n const formValues = payload as StateTaxesFormValues\n const allRequirementSets = stateTaxRequirements.requirementSets ?? []\n const requirementSets = allRequirementSets\n .map((requirementSet, setIndex) => ({ requirementSet, setIndex }))\n .filter(({ requirementSet, setIndex }) => {\n if (!requirementSet.key) return false\n const requirementSetPath = getUniqueRhfKey(requirementSet, setIndex, allRequirementSets)\n return Boolean(payload[requirementSetPath])\n })\n .map(({ requirementSet, setIndex }) => {\n const requirementSetKey = requirementSet.key as string\n const requirementSetPath = getUniqueRhfKey(requirementSet, setIndex, allRequirementSets)\n const payloadSet = payload[requirementSetPath] as Record<string, unknown>\n const preparedRequirements = prepareRequirements(requirementSet.requirements ?? [])\n\n const applicableRequirements = preparedRequirements\n .map((req, index) => ({ req, index }))\n .filter(({ req }) => isRequirementApplicable(req, requirementSetPath, formValues))\n\n return {\n state,\n key: requirementSetKey,\n effectiveFrom: requirementSet.effectiveFrom,\n requirements: applicableRequirements.map(({ req, index }) => ({\n key: req.key as string,\n value: stringifyRequirementValue(\n payloadSet[getUniqueRhfKey(req, index, preparedRequirements)],\n ),\n })),\n }\n })\n await updateStateTax({\n request: {\n companyUuid: companyId,\n requestBody: { requirementSets },\n state,\n },\n })\n onEvent(componentEvents.COMPANY_STATE_TAX_UPDATED)\n })\n }\n\n const handleCancel = () => {\n onEvent(componentEvents.CANCEL)\n }\n\n return (\n <section className={className}>\n <FormProvider {...methods} control={control}>\n <HtmlForm onSubmit={methods.handleSubmit(onSubmit)}>\n <StateTaxesFormProvider\n value={{ stateTaxRequirements, isPending: isPendingUpdate, state, handleCancel }}\n >\n <Flex flexDirection=\"column\" gap={32}>\n {children ? (\n children\n ) : (\n <>\n <Head />\n <Form />\n <Actions />\n </>\n )}\n </Flex>\n </StateTaxesFormProvider>\n </HtmlForm>\n </FormProvider>\n </section>\n )\n}\n"],"names":["StateTaxesForm","props","jsx","BaseComponent","Root","companyId","state","className","children","useI18n","onEvent","baseSubmitHandler","useBase","t","useTranslation","data","useTaxRequirementsGetSuspense","stateTaxRequirements","updateStateTax","isPendingUpdate","useTaxRequirementsUpdateStateMutation","dynamicSchema","defaultValues","useMemo","schemaShape","values","requirementSets","requirementSet","index","requirementSetPath","getUniqueRhfKey","preparedRequirements","prepareRequirements","shape","defaults","buildRequirementSchema","z","control","methods","useForm","zodResolver","onSubmit","formData","payload","formValues","allRequirementSets","setIndex","requirementSetKey","payloadSet","applicableRequirements","req","isRequirementApplicable","stringifyRequirementValue","componentEvents","handleCancel","FormProvider","HtmlForm","StateTaxesFormProvider","Flex","jsxs","Fragment","Head","Form","Actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoEO,SAASA,GAAeC,GAA4B;AACzD,SACE,gBAAAC,EAACC,GAAA,EAAe,GAAGF,GACjB,UAAA,gBAAAC,EAACE,MAAM,GAAGH,GAAQ,UAAAA,EAAM,SAAA,CAAS,EAAA,CACnC;AAEJ;AAEA,SAASG,GAAK,EAAE,WAAAC,GAAW,OAAAC,GAAO,WAAAC,GAAW,UAAAC,KAAiC;AAC5E,EAAAC,EAAQ,oBAAoB;AAC5B,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAA,IAAsBC,GAAA,GACjC,EAAE,GAAAC,MAAMC,EAAe,sBAAsB,EAAE,WAAW,QAAQ,GAClE,EAAE,MAAAC,MAASC,EAA8B,EAAE,aAAaX,GAAW,OAAAC,GAAO,GAC1EW,IAAuBF,EAAK,sBAE5B,EAAE,aAAaG,GAAgB,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xC,GAAsB,WAAWE,GAAiB,OAAAb,GAAO,cAAAgD,EAAA;AAAA,MAElE,UAAA,gBAAApD,EAACwD,MAAK,eAAc,UAAS,KAAK,IAC/B,UAAAlD,KAGC,gBAAAmD,EAAAC,GAAA,EACE,UAAA;AAAA,QAAA,gBAAA1D,EAAC2D,GAAA,EAAK;AAAA,0BACLC,GAAA,EAAK;AAAA,0BACLC,GAAA,CAAA,CAAQ;AAAA,MAAA,EAAA,CACX,EAAA,CAEJ;AAAA,IAAA;AAAA,EAAA,EACF,CACF,GACF,GACF;AAEJ;"}
@@ -1,110 +1,114 @@
1
- import { jsx as s, jsxs as E } from "react/jsx-runtime";
2
- import { useState as z, useMemo as n, useEffect as V } from "react";
1
+ import { jsx as a, jsxs as j } from "react/jsx-runtime";
2
+ import { useState as z, useMemo as s, useEffect as V } from "react";
3
3
  import { useForm as H, FormProvider as I } from "react-hook-form";
4
4
  import { zodResolver as K } from "@hookform/resolvers/zod";
5
- import { z as h } from "zod";
6
- import { useTranslation as b } from "react-i18next";
5
+ import { z as b } from "zod";
6
+ import { useTranslation as y } from "react-i18next";
7
7
  import { buildRequirementSchema as M } from "../shared/buildRequirementSchema.js";
8
8
  import { RequirementFields as U } from "../shared/RequirementFields.js";
9
9
  import { getUniqueRhfKey as w } from "../shared/rhfKey.js";
10
10
  import { isRequirementApplicable as W } from "../shared/applicableIf.js";
11
- import { stringifyRequirementValue as Y } from "../shared/requirementValue.js";
12
- import { useTaxRateManagement as B } from "./context.js";
13
- import { Flex as G } from "../../../Common/Flex/Flex.js";
14
- import { useComponentContext as J } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
15
- import { useDateFormatter as N } from "../../../../hooks/useDateFormatter.js";
16
- import { SelectField as Q } from "../../../Common/Fields/SelectField/SelectField.js";
17
- function X(r) {
11
+ import { prepareRequirements as Y, isRequirementSetEditable as B } from "../shared/prepareRequirements.js";
12
+ import { stringifyRequirementValue as G } from "../shared/requirementValue.js";
13
+ import { useTaxRateManagement as J } from "./context.js";
14
+ import { Flex as N } from "../../../Common/Flex/Flex.js";
15
+ import { useComponentContext as Q } from "../../../../contexts/ComponentAdapter/useComponentContext.js";
16
+ import { useDateFormatter as X } from "../../../../hooks/useDateFormatter.js";
17
+ import { SelectField as Z } from "../../../Common/Fields/SelectField/SelectField.js";
18
+ function _(r) {
18
19
  if (r.length === 0) return null;
19
- const m = [...r].sort(
20
- (o, l) => (o.effectiveFrom ?? "").localeCompare(l.effectiveFrom ?? "")
20
+ const n = [...r].sort(
21
+ (o, m) => (o.effectiveFrom ?? "").localeCompare(m.effectiveFrom ?? "")
21
22
  );
22
- return m[m.length - 1] ?? null;
23
+ return n[n.length - 1] ?? null;
23
24
  }
24
- function de({ isOpen: r, state: m, group: o, onClose: l }) {
25
- const d = J(), R = N(), { t: i } = b("Company.StateTaxes", { keyPrefix: "manageRates" }), { t: y } = b("Company.StateTaxes", { keyPrefix: "form" }), { t: x } = b("common", { keyPrefix: "statesHash" }), { handleAddRate: q, isPendingUpdate: D } = B(), [k, F] = z(!1), t = n(() => X(o.candidateSets), [o.candidateSets]), c = n(
25
+ function he({ isOpen: r, state: n, group: o, onClose: m }) {
26
+ const u = Q(), g = X(), { t } = y("Company.StateTaxes", { keyPrefix: "manageRates" }), { t: F } = y("Company.StateTaxes", { keyPrefix: "form" }), { t: q } = y("common", { keyPrefix: "statesHash" }), { handleAddRate: x, isPendingUpdate: D } = J(), [k, v] = z(!1), i = s(() => _(o.candidateSets), [o.candidateSets]), l = s(
26
27
  () => o.candidateSets.map((e) => e.effectiveFrom).filter((e) => typeof e == "string").sort(),
27
28
  [o.candidateSets]
28
- ), { shape: v, defaults: g } = n(
29
- () => M(t?.requirements, y),
30
- [t, y]
31
- ), A = n(
32
- () => h.object({
33
- effectiveFrom: h.string().min(1),
34
- fields: h.object(v)
29
+ ), c = s(
30
+ () => Y(i?.requirements ?? []),
31
+ [i]
32
+ ), { shape: R, defaults: S } = s(
33
+ () => M(c, F),
34
+ [c, F]
35
+ ), A = s(
36
+ () => b.object({
37
+ effectiveFrom: b.string().min(1),
38
+ fields: b.object(R)
35
39
  }),
36
- [v]
37
- ), u = n(
40
+ [R]
41
+ ), p = s(
38
42
  () => ({
39
- effectiveFrom: t?.effectiveFrom ?? c[0] ?? "",
40
- fields: g
43
+ effectiveFrom: i?.effectiveFrom ?? l[0] ?? "",
44
+ fields: S
41
45
  }),
42
- [t, c, g]
43
- ), p = H({ resolver: K(A), defaultValues: u });
46
+ [i, l, S]
47
+ ), h = H({ resolver: K(A), defaultValues: p });
44
48
  V(() => {
45
- r && p.reset(u);
46
- }, [r, u]);
47
- const C = p.handleSubmit(async (e) => {
48
- if (!t?.key) return;
49
- const T = { fields: e.fields }, S = t.requirements ?? [], L = S.map((a, f) => ({ req: a, index: f })).filter(({ req: a }) => a.editable !== !1).filter(({ req: a }) => W(a, "fields", T));
50
- F(!0);
49
+ r && h.reset(p);
50
+ }, [r, p]);
51
+ const C = h.handleSubmit(async (e) => {
52
+ if (!i?.key) return;
53
+ const T = { fields: e.fields }, E = c.map((f, d) => ({ req: f, index: d })).filter(({ req: f }) => W(f, "fields", T));
54
+ v(!0);
51
55
  try {
52
- await q(
53
- t.key,
56
+ await x(
57
+ i.key,
54
58
  e.effectiveFrom,
55
- L.map(({ req: f, index: j }) => ({
56
- key: f.key,
57
- value: Y(e.fields[w(f, j, S)])
59
+ E.map(({ req: d, index: L }) => ({
60
+ key: d.key,
61
+ value: G(
62
+ e.fields[w(d, L, c)]
63
+ )
58
64
  }))
59
- ) && l();
65
+ ) && m();
60
66
  } finally {
61
- F(!1);
67
+ v(!1);
62
68
  }
63
- }), P = (t?.requirements ?? []).some(
64
- (e) => e.editable !== !1
65
- );
66
- return /* @__PURE__ */ s(
67
- d.Dialog,
69
+ }), P = B(i?.requirements ?? []);
70
+ return /* @__PURE__ */ a(
71
+ u.Dialog,
68
72
  {
69
73
  isOpen: r,
70
- onClose: l,
74
+ onClose: m,
71
75
  onPrimaryActionClick: () => {
72
76
  C();
73
77
  },
74
78
  isPrimaryActionLoading: k || D,
75
- primaryActionLabel: i("saveRateCta"),
76
- closeActionLabel: i("cancelCta"),
77
- title: i("addRateDialogTitle", {
78
- state: x(m)
79
+ primaryActionLabel: t("saveRateCta"),
80
+ closeActionLabel: t("cancelCta"),
81
+ title: t("addRateDialogTitle", {
82
+ state: q(n)
79
83
  }),
80
- children: /* @__PURE__ */ s(I, { ...p, children: /* @__PURE__ */ E(G, { flexDirection: "column", gap: 20, alignItems: "stretch", children: [
81
- /* @__PURE__ */ s(d.Text, { size: "sm", children: i("addRateDialogDescription") }),
82
- /* @__PURE__ */ s(
83
- Q,
84
+ children: /* @__PURE__ */ a(I, { ...h, children: /* @__PURE__ */ j(N, { flexDirection: "column", gap: 20, alignItems: "stretch", children: [
85
+ /* @__PURE__ */ a(u.Text, { size: "sm", children: t("addRateDialogDescription") }),
86
+ /* @__PURE__ */ a(
87
+ Z,
84
88
  {
85
89
  name: "effectiveFrom",
86
- label: i("effectiveDateLabel"),
87
- placeholder: i("effectiveDatePlaceholder"),
90
+ label: t("effectiveDateLabel"),
91
+ placeholder: t("effectiveDatePlaceholder"),
88
92
  isRequired: !0,
89
- isDisabled: c.length === 0,
90
- options: c.map((e) => ({
93
+ isDisabled: l.length === 0,
94
+ options: l.map((e) => ({
91
95
  value: e,
92
- label: R.formatLongWithYear(e)
96
+ label: g.formatLongWithYear(e)
93
97
  }))
94
98
  }
95
99
  ),
96
- P ? /* @__PURE__ */ s(
100
+ P ? /* @__PURE__ */ a(
97
101
  U,
98
102
  {
99
- requirements: t?.requirements,
103
+ requirements: i?.requirements,
100
104
  requirementSetKey: "fields"
101
105
  }
102
- ) : /* @__PURE__ */ s(d.Alert, { status: "info", label: i("noEditableFieldsTitle"), children: i("noEditableFieldsDescription") })
106
+ ) : /* @__PURE__ */ a(u.Alert, { status: "info", label: t("noEditableFieldsTitle"), children: t("noEditableFieldsDescription") })
103
107
  ] }) })
104
108
  }
105
109
  );
106
110
  }
107
111
  export {
108
- de as AddTaxRateDialog
112
+ he as AddTaxRateDialog
109
113
  };
110
114
  //# sourceMappingURL=AddTaxRateDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AddTaxRateDialog.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { z } from 'zod'\nimport { useTranslation } from 'react-i18next'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { RequirementFields } from '../shared/RequirementFields'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { useTaxRateManagement, type TaxRateKeyGroup } from './context'\nimport { Flex, SelectField } from '@/components/Common'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useDateFormatter } from '@/hooks/useDateFormatter'\nimport type { STATES_ABBR } from '@/shared/constants'\n\ninterface AddTaxRateDialogProps {\n isOpen: boolean\n state: string\n group: TaxRateKeyGroup\n onClose: () => void\n}\n\nfunction latestSet(sets: TaxRateKeyGroup['candidateSets']) {\n if (sets.length === 0) return null\n const sorted = [...sets].sort((a, b) =>\n (a.effectiveFrom ?? '').localeCompare(b.effectiveFrom ?? ''),\n )\n return sorted[sorted.length - 1] ?? null\n}\n\n/** @internal */\nexport function AddTaxRateDialog({ isOpen, state, group, onClose }: AddTaxRateDialogProps) {\n const Components = useComponentContext()\n const dateFormatter = useDateFormatter()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'manageRates' })\n const { t: tForm } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { t: statesHash } = useTranslation('common', { keyPrefix: 'statesHash' })\n const { handleAddRate, isPendingUpdate } = useTaxRateManagement()\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const templateSet = useMemo(() => latestSet(group.candidateSets), [group.candidateSets])\n\n const availableDates = useMemo(\n () =>\n group.candidateSets\n .map(candidate => candidate.effectiveFrom)\n .filter((date): date is string => typeof date === 'string')\n .sort(),\n [group.candidateSets],\n )\n\n const { shape, defaults } = useMemo(\n () => buildRequirementSchema(templateSet?.requirements, tForm),\n [templateSet, tForm],\n )\n\n const dynamicSchema = useMemo(\n () =>\n z.object({\n effectiveFrom: z.string().min(1),\n fields: z.object(shape),\n }),\n [shape],\n )\n\n type FormShape = z.infer<typeof dynamicSchema>\n\n const defaultValues = useMemo<FormShape>(\n () => ({\n effectiveFrom: templateSet?.effectiveFrom ?? availableDates[0] ?? '',\n fields: defaults,\n }),\n [templateSet, availableDates, defaults],\n )\n\n const methods = useForm<FormShape>({ resolver: zodResolver(dynamicSchema), defaultValues })\n\n useEffect(() => {\n if (isOpen) methods.reset(defaultValues)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, defaultValues])\n\n const handleSubmit = methods.handleSubmit(async data => {\n if (!templateSet?.key) return\n const formValues: StateTaxesFormValues = { fields: data.fields }\n const requirements = templateSet.requirements ?? []\n const applicableRequirements = requirements\n .map((req, index) => ({ req, index }))\n .filter(({ req }) => req.editable !== false)\n .filter(({ req }) => isRequirementApplicable(req, 'fields', formValues))\n\n setIsSubmitting(true)\n try {\n const success = await handleAddRate(\n templateSet.key,\n data.effectiveFrom,\n applicableRequirements.map(({ req, index }) => ({\n key: req.key as string,\n value: stringifyRequirementValue(data.fields[getUniqueRhfKey(req, index, requirements)]),\n })),\n )\n if (success) onClose()\n } finally {\n setIsSubmitting(false)\n }\n })\n\n const hasEditableFields = (templateSet?.requirements ?? []).some(\n requirement => requirement.editable !== false,\n )\n\n return (\n <Components.Dialog\n isOpen={isOpen}\n onClose={onClose}\n onPrimaryActionClick={() => {\n void handleSubmit()\n }}\n isPrimaryActionLoading={isSubmitting || isPendingUpdate}\n primaryActionLabel={t('saveRateCta')}\n closeActionLabel={t('cancelCta')}\n title={t('addRateDialogTitle', {\n state: statesHash(state as (typeof STATES_ABBR)[number]),\n })}\n >\n <FormProvider {...methods}>\n <Flex flexDirection=\"column\" gap={20} alignItems=\"stretch\">\n <Components.Text size=\"sm\">{t('addRateDialogDescription')}</Components.Text>\n <SelectField\n name=\"effectiveFrom\"\n label={t('effectiveDateLabel')}\n placeholder={t('effectiveDatePlaceholder')}\n isRequired\n isDisabled={availableDates.length === 0}\n options={availableDates.map(date => ({\n value: date,\n label: dateFormatter.formatLongWithYear(date),\n }))}\n />\n {hasEditableFields ? (\n <RequirementFields\n requirements={templateSet?.requirements}\n requirementSetKey=\"fields\"\n />\n ) : (\n <Components.Alert status=\"info\" label={t('noEditableFieldsTitle')}>\n {t('noEditableFieldsDescription')}\n </Components.Alert>\n )}\n </Flex>\n </FormProvider>\n </Components.Dialog>\n )\n}\n"],"names":["latestSet","sets","sorted","a","b","AddTaxRateDialog","isOpen","state","group","onClose","Components","useComponentContext","dateFormatter","useDateFormatter","t","useTranslation","tForm","statesHash","handleAddRate","isPendingUpdate","useTaxRateManagement","isSubmitting","setIsSubmitting","useState","templateSet","useMemo","availableDates","candidate","date","shape","defaults","buildRequirementSchema","dynamicSchema","z","defaultValues","methods","useForm","zodResolver","useEffect","handleSubmit","data","formValues","requirements","applicableRequirements","req","index","isRequirementApplicable","stringifyRequirementValue","getUniqueRhfKey","hasEditableFields","requirement","jsx","FormProvider","jsxs","Flex","SelectField","RequirementFields"],"mappings":";;;;;;;;;;;;;;;;AAuBA,SAASA,EAAUC,GAAwC;AACzD,MAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAMC,IAAS,CAAC,GAAGD,CAAI,EAAE;AAAA,IAAK,CAACE,GAAGC,OAC/BD,EAAE,iBAAiB,IAAI,cAAcC,EAAE,iBAAiB,EAAE;AAAA,EAAA;AAE7D,SAAOF,EAAOA,EAAO,SAAS,CAAC,KAAK;AACtC;AAGO,SAASG,GAAiB,EAAE,QAAAC,GAAQ,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,QAC7B,OAAOG,EAAWV,CAAqC;AAAA,MAAA,CACxD;AAAA,MAED,UAAA,gBAAA4C,EAACC,GAAA,EAAc,GAAGjB,GAChB,UAAA,gBAAAkB,EAACC,GAAA,EAAK,eAAc,UAAS,KAAK,IAAI,YAAW,WAC/C,UAAA;AAAA,QAAA,gBAAAH,EAACzC,EAAW,MAAX,EAAgB,MAAK,MAAM,UAAAI,EAAE,0BAA0B,GAAE;AAAA,QAC1D,gBAAAqC;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,OAAOzC,EAAE,oBAAoB;AAAA,YAC7B,aAAaA,EAAE,0BAA0B;AAAA,YACzC,YAAU;AAAA,YACV,YAAYY,EAAe,WAAW;AAAA,YACtC,SAASA,EAAe,IAAI,CAAAE,OAAS;AAAA,cACnC,OAAOA;AAAA,cACP,OAAOhB,EAAc,mBAAmBgB,CAAI;AAAA,YAAA,EAC5C;AAAA,UAAA;AAAA,QAAA;AAAA,QAEHqB,IACC,gBAAAE;AAAA,UAACK;AAAA,UAAA;AAAA,YACC,cAAchC,GAAa;AAAA,YAC3B,mBAAkB;AAAA,UAAA;AAAA,QAAA,IAGpB,gBAAA2B,EAACzC,EAAW,OAAX,EAAiB,QAAO,QAAO,OAAOI,EAAE,uBAAuB,GAC7D,UAAAA,EAAE,6BAA6B,EAAA,CAClC;AAAA,MAAA,EAAA,CAEJ,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
1
+ {"version":3,"file":"AddTaxRateDialog.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/AddTaxRateDialog.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { z } from 'zod'\nimport { useTranslation } from 'react-i18next'\nimport { buildRequirementSchema } from '../shared/buildRequirementSchema'\nimport { RequirementFields } from '../shared/RequirementFields'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from '../shared/applicableIf'\nimport { isRequirementSetEditable, prepareRequirements } from '../shared/prepareRequirements'\nimport { stringifyRequirementValue } from '../shared/requirementValue'\nimport { useTaxRateManagement, type TaxRateKeyGroup } from './context'\nimport { Flex, SelectField } from '@/components/Common'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport { useDateFormatter } from '@/hooks/useDateFormatter'\nimport type { STATES_ABBR } from '@/shared/constants'\n\ninterface AddTaxRateDialogProps {\n isOpen: boolean\n state: string\n group: TaxRateKeyGroup\n onClose: () => void\n}\n\nfunction latestSet(sets: TaxRateKeyGroup['candidateSets']) {\n if (sets.length === 0) return null\n const sorted = [...sets].sort((a, b) =>\n (a.effectiveFrom ?? '').localeCompare(b.effectiveFrom ?? ''),\n )\n return sorted[sorted.length - 1] ?? null\n}\n\n/** @internal */\nexport function AddTaxRateDialog({ isOpen, state, group, onClose }: AddTaxRateDialogProps) {\n const Components = useComponentContext()\n const dateFormatter = useDateFormatter()\n const { t } = useTranslation('Company.StateTaxes', { keyPrefix: 'manageRates' })\n const { t: tForm } = useTranslation('Company.StateTaxes', { keyPrefix: 'form' })\n const { t: statesHash } = useTranslation('common', { keyPrefix: 'statesHash' })\n const { handleAddRate, isPendingUpdate } = useTaxRateManagement()\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const templateSet = useMemo(() => latestSet(group.candidateSets), [group.candidateSets])\n\n const availableDates = useMemo(\n () =>\n group.candidateSets\n .map(candidate => candidate.effectiveFrom)\n .filter((date): date is string => typeof date === 'string')\n .sort(),\n [group.candidateSets],\n )\n\n const preparedRequirements = useMemo(\n () => prepareRequirements(templateSet?.requirements ?? []),\n [templateSet],\n )\n\n const { shape, defaults } = useMemo(\n () => buildRequirementSchema(preparedRequirements, tForm),\n [preparedRequirements, tForm],\n )\n\n const dynamicSchema = useMemo(\n () =>\n z.object({\n effectiveFrom: z.string().min(1),\n fields: z.object(shape),\n }),\n [shape],\n )\n\n type FormShape = z.infer<typeof dynamicSchema>\n\n const defaultValues = useMemo<FormShape>(\n () => ({\n effectiveFrom: templateSet?.effectiveFrom ?? availableDates[0] ?? '',\n fields: defaults,\n }),\n [templateSet, availableDates, defaults],\n )\n\n const methods = useForm<FormShape>({ resolver: zodResolver(dynamicSchema), defaultValues })\n\n useEffect(() => {\n if (isOpen) methods.reset(defaultValues)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, defaultValues])\n\n const handleSubmit = methods.handleSubmit(async data => {\n if (!templateSet?.key) return\n const formValues: StateTaxesFormValues = { fields: data.fields }\n const applicableRequirements = preparedRequirements\n .map((req, index) => ({ req, index }))\n .filter(({ req }) => isRequirementApplicable(req, 'fields', formValues))\n\n setIsSubmitting(true)\n try {\n const success = await handleAddRate(\n templateSet.key,\n data.effectiveFrom,\n applicableRequirements.map(({ req, index }) => ({\n key: req.key as string,\n value: stringifyRequirementValue(\n data.fields[getUniqueRhfKey(req, index, preparedRequirements)],\n ),\n })),\n )\n if (success) onClose()\n } finally {\n setIsSubmitting(false)\n }\n })\n\n const hasEditableFields = isRequirementSetEditable(templateSet?.requirements ?? [])\n\n return (\n <Components.Dialog\n isOpen={isOpen}\n onClose={onClose}\n onPrimaryActionClick={() => {\n void handleSubmit()\n }}\n isPrimaryActionLoading={isSubmitting || isPendingUpdate}\n primaryActionLabel={t('saveRateCta')}\n closeActionLabel={t('cancelCta')}\n title={t('addRateDialogTitle', {\n state: statesHash(state as (typeof STATES_ABBR)[number]),\n })}\n >\n <FormProvider {...methods}>\n <Flex flexDirection=\"column\" gap={20} alignItems=\"stretch\">\n <Components.Text size=\"sm\">{t('addRateDialogDescription')}</Components.Text>\n <SelectField\n name=\"effectiveFrom\"\n label={t('effectiveDateLabel')}\n placeholder={t('effectiveDatePlaceholder')}\n isRequired\n isDisabled={availableDates.length === 0}\n options={availableDates.map(date => ({\n value: date,\n label: dateFormatter.formatLongWithYear(date),\n }))}\n />\n {hasEditableFields ? (\n <RequirementFields\n requirements={templateSet?.requirements}\n requirementSetKey=\"fields\"\n />\n ) : (\n <Components.Alert status=\"info\" label={t('noEditableFieldsTitle')}>\n {t('noEditableFieldsDescription')}\n </Components.Alert>\n )}\n </Flex>\n </FormProvider>\n </Components.Dialog>\n )\n}\n"],"names":["latestSet","sets","sorted","a","b","AddTaxRateDialog","isOpen","state","group","onClose","Components","useComponentContext","dateFormatter","useDateFormatter","useTranslation","tForm","statesHash","handleAddRate","isPendingUpdate","useTaxRateManagement","isSubmitting","setIsSubmitting","useState","templateSet","useMemo","availableDates","candidate","date","preparedRequirements","prepareRequirements","shape","defaults","buildRequirementSchema","dynamicSchema","z","defaultValues","methods","useForm","zodResolver","useEffect","handleSubmit","data","formValues","applicableRequirements","req","index","isRequirementApplicable","stringifyRequirementValue","getUniqueRhfKey","hasEditableFields","isRequirementSetEditable","jsx","FormProvider","jsxs","Flex","SelectField","RequirementFields"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAASA,EAAUC,GAAwC;AACzD,MAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAMC,IAAS,CAAC,GAAGD,CAAI,EAAE;AAAA,IAAK,CAACE,GAAGC,OAC/BD,EAAE,iBAAiB,IAAI,cAAcC,EAAE,iBAAiB,EAAE;AAAA,EAAA;AAE7D,SAAOF,EAAOA,EAAO,SAAS,CAAC,KAAK;AACtC;AAGO,SAASG,GAAiB,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAAC,GAAO,SAAAC,KAAkC;AACzF,QAAMC,IAAaC,EAAA,GACbC,IAAgBC,EAAA,GAChB,EAAE,MAAMC,EAAe,sBAAsB,EAAE,WAAW,eAAe,GACzE,EAAE,GAAGC,MAAUD,EAAe,sBAAsB,EAAE,WAAW,QAAQ,GACzE,EAAE,GAAGE,MAAeF,EAAe,UAAU,EAAE,WAAW,cAAc,GACxE,EAAE,eAAAG,GAAe,iBAAAC,EAAA,IAAoBC,EAAA,GACrC,CAACC,GAAcC,CAAe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AAa,EAAE,0BAA0B;AAAA,YACzC,YAAU;AAAA,YACV,YAAY9B,EAAe,WAAW;AAAA,YACtC,SAASA,EAAe,IAAI,CAAAE,OAAS;AAAA,cACnC,OAAOA;AAAA,cACP,OAAOf,EAAc,mBAAmBe,CAAI;AAAA,YAAA,EAC5C;AAAA,UAAA;AAAA,QAAA;AAAA,QAEHsB,IACC,gBAAAE;AAAA,UAACK;AAAA,UAAA;AAAA,YACC,cAAcjC,GAAa;AAAA,YAC3B,mBAAkB;AAAA,UAAA;AAAA,QAAA,IAGpB,gBAAA4B,EAACzC,EAAW,OAAX,EAAiB,QAAO,QAAO,OAAO,EAAE,uBAAuB,GAC7D,UAAA,EAAE,6BAA6B,EAAA,CAClC;AAAA,MAAA,EAAA,CAEJ,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
@@ -1,34 +1,41 @@
1
- import { formatDateToStringDate as a } from "../../../../helpers/dateFormatting.js";
2
- function u(o) {
3
- return typeof o.effectiveFrom == "string" && o.effectiveFrom.length > 0;
1
+ import { getUniqueRhfKey as i } from "../shared/rhfKey.js";
2
+ import { formatDateToStringDate as m } from "../../../../helpers/dateFormatting.js";
3
+ function v(r) {
4
+ return typeof r.effectiveFrom == "string" && r.effectiveFrom.length > 0;
4
5
  }
5
- function m(o) {
6
- const f = a(/* @__PURE__ */ new Date()) ?? "", i = o.filter(u).sort((t, r) => t.effectiveFrom.localeCompare(r.effectiveFrom)), e = i.reduce(
7
- (t, r, c) => r.effectiveFrom <= f ? c : t,
6
+ function F(r) {
7
+ const n = m(/* @__PURE__ */ new Date()) ?? "", s = r.filter(v).sort((e, t) => e.effectiveFrom.localeCompare(t.effectiveFrom)), c = s.reduce(
8
+ (e, t, o) => t.effectiveFrom <= n ? o : e,
8
9
  -1
9
10
  );
10
- return i.map((t, r) => {
11
- const c = {};
12
- for (const n of t.requirements ?? [])
13
- !n.key || n.editable === !1 || (c[n.key] = n.value === null || n.value === void 0 ? "" : String(n.value));
14
- const s = r === e ? "current" : r > e ? "scheduled" : "historical";
11
+ return s.map((e, t) => {
12
+ const o = {}, a = e.requirements ?? [];
13
+ a.forEach((f, u) => {
14
+ !f.key || f.editable === !1 || (o[i(f, u, a)] = f.value === null || f.value === void 0 ? "" : String(f.value));
15
+ });
16
+ const l = t === c ? "current" : t > c ? "scheduled" : "historical";
15
17
  return {
16
- id: `${t.key ?? "set"}-${t.effectiveFrom}-${r}`,
17
- effectiveFrom: t.effectiveFrom,
18
- status: s,
19
- values: c
18
+ id: `${e.key ?? "set"}-${e.effectiveFrom}-${t}`,
19
+ effectiveFrom: e.effectiveFrom,
20
+ status: l,
21
+ values: o
20
22
  };
21
23
  });
22
24
  }
23
- function v(o) {
24
- const f = /* @__PURE__ */ new Map();
25
- for (const i of o)
26
- for (const e of i.requirements ?? [])
27
- e.key && e.editable !== !1 && !f.has(e.key) && f.set(e.key, { key: e.key, label: e.label });
28
- return Array.from(f.values());
25
+ function h(r) {
26
+ const n = /* @__PURE__ */ new Map();
27
+ for (const s of r) {
28
+ const c = s.requirements ?? [];
29
+ c.forEach((e, t) => {
30
+ if (!e.key || e.editable === !1) return;
31
+ const o = i(e, t, c);
32
+ n.has(o) || n.set(o, { key: o, label: e.label });
33
+ });
34
+ }
35
+ return Array.from(n.values());
29
36
  }
30
37
  export {
31
- v as extractRequirementColumns,
32
- m as toHistoryRows
38
+ h as extractRequirementColumns,
39
+ F as toHistoryRows
33
40
  };
34
41
  //# sourceMappingURL=toHistoryRows.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toHistoryRows.js","sources":["../../../../../src/components/Company/StateTaxes/TaxRateManagement/toHistoryRows.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\n/** @internal */\nexport type HistoryRowStatus = 'current' | 'scheduled' | 'historical'\n\n/** @internal */\nexport interface HistoryRow {\n id: string\n effectiveFrom: string\n status: HistoryRowStatus\n values: Record<string, string>\n}\n\n/** @internal */\nexport interface RequirementColumn {\n key: string\n label?: string\n}\n\nfunction isEffectiveDated(\n set: TaxRequirementSet,\n): set is TaxRequirementSet & { effectiveFrom: string } {\n return typeof set.effectiveFrom === 'string' && set.effectiveFrom.length > 0\n}\n\n/**\n * Tags each effective-dated requirement set for a key as current, scheduled (future), or\n * historical (past), relative to today.\n *\n * @internal\n */\nexport function toHistoryRows(sets: TaxRequirementSet[]): HistoryRow[] {\n const today = formatDateToStringDate(new Date()) ?? ''\n const sorted = sets\n .filter(isEffectiveDated)\n .sort((a, b) => a.effectiveFrom.localeCompare(b.effectiveFrom))\n\n const currentIndex = sorted.reduce(\n (acc, set, idx) => (set.effectiveFrom <= today ? idx : acc),\n -1,\n )\n\n return sorted.map((set, idx) => {\n const values: Record<string, string> = {}\n for (const requirement of set.requirements ?? []) {\n if (!requirement.key || requirement.editable === false) continue\n values[requirement.key] =\n requirement.value === null || requirement.value === undefined\n ? ''\n : String(requirement.value)\n }\n const status: HistoryRowStatus =\n idx === currentIndex ? 'current' : idx > currentIndex ? 'scheduled' : 'historical'\n return {\n id: `${set.key ?? 'set'}-${set.effectiveFrom}-${idx}`,\n effectiveFrom: set.effectiveFrom,\n status,\n values,\n }\n })\n}\n\n/**\n * Builds the union of editable requirement keys/labels across a set of requirement sets,\n * in first-seen order, for use as dynamic table columns.\n *\n * @internal\n */\nexport function extractRequirementColumns(sets: TaxRequirementSet[]): RequirementColumn[] {\n const seen = new Map<string, RequirementColumn>()\n for (const set of sets) {\n for (const requirement of set.requirements ?? []) {\n if (requirement.key && requirement.editable !== false && !seen.has(requirement.key)) {\n seen.set(requirement.key, { key: requirement.key, label: requirement.label })\n }\n }\n }\n return Array.from(seen.values())\n}\n"],"names":["isEffectiveDated","set","toHistoryRows","sets","today","formatDateToStringDate","sorted","a","b","currentIndex","acc","idx","values","requirement","status","extractRequirementColumns","seen"],"mappings":";AAoBA,SAASA,EACPC,GACsD;AACtD,SAAO,OAAOA,EAAI,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TaxRateManagement/toHistoryRows.ts"],"sourcesContent":["import type { TaxRequirementSet } from '@gusto/embedded-api/models/components/taxrequirementset'\nimport { getUniqueRhfKey } from '../shared/rhfKey'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\n\n/** @internal */\nexport type HistoryRowStatus = 'current' | 'scheduled' | 'historical'\n\n/** @internal */\nexport interface HistoryRow {\n id: string\n effectiveFrom: string\n status: HistoryRowStatus\n values: Record<string, string>\n}\n\n/** @internal */\nexport interface RequirementColumn {\n key: string\n label?: string\n}\n\nfunction isEffectiveDated(\n set: TaxRequirementSet,\n): set is TaxRequirementSet & { effectiveFrom: string } {\n return typeof set.effectiveFrom === 'string' && set.effectiveFrom.length > 0\n}\n\n/**\n * Tags each effective-dated requirement set for a key as current, scheduled (future), or\n * historical (past), relative to today.\n *\n * @internal\n */\nexport function toHistoryRows(sets: TaxRequirementSet[]): HistoryRow[] {\n const today = formatDateToStringDate(new Date()) ?? ''\n const sorted = sets\n .filter(isEffectiveDated)\n .sort((a, b) => a.effectiveFrom.localeCompare(b.effectiveFrom))\n\n const currentIndex = sorted.reduce(\n (acc, set, idx) => (set.effectiveFrom <= today ? idx : acc),\n -1,\n )\n\n return sorted.map((set, idx) => {\n const values: Record<string, string> = {}\n const requirements = set.requirements ?? []\n requirements.forEach((requirement, reqIndex) => {\n if (!requirement.key || requirement.editable === false) return\n values[getUniqueRhfKey(requirement, reqIndex, requirements)] =\n requirement.value === null || requirement.value === undefined\n ? ''\n : String(requirement.value)\n })\n const status: HistoryRowStatus =\n idx === currentIndex ? 'current' : idx > currentIndex ? 'scheduled' : 'historical'\n return {\n id: `${set.key ?? 'set'}-${set.effectiveFrom}-${idx}`,\n effectiveFrom: set.effectiveFrom,\n status,\n values,\n }\n })\n}\n\n/**\n * Builds the union of editable requirement keys/labels across a set of requirement sets,\n * in first-seen order, for use as dynamic table columns.\n *\n * @internal\n */\nexport function extractRequirementColumns(sets: TaxRequirementSet[]): RequirementColumn[] {\n const seen = new Map<string, RequirementColumn>()\n for (const set of sets) {\n const requirements = set.requirements ?? []\n requirements.forEach((requirement, index) => {\n if (!requirement.key || requirement.editable === false) return\n const columnKey = getUniqueRhfKey(requirement, index, requirements)\n if (!seen.has(columnKey)) {\n seen.set(columnKey, { key: columnKey, label: requirement.label })\n }\n })\n }\n return Array.from(seen.values())\n}\n"],"names":["isEffectiveDated","set","toHistoryRows","sets","today","formatDateToStringDate","sorted","a","b","currentIndex","acc","idx","values","requirements","requirement","reqIndex","getUniqueRhfKey","status","extractRequirementColumns","seen","index","columnKey"],"mappings":";;AAqBA,SAASA,EACPC,GACsD;AACtD,SAAO,OAAOA,EAAI,iBAAkB,YAAYA,EAAI,cAAc,SAAS;AAC7E;AAQO,SAASC,EAAcC,GAAyC;AACrE,QAAMC,IAAQC,EAAuB,oBAAI,KAAA,CAAM,KAAK,IAC9CC,IAASH,EACZ,OAAOH,CAAgB,EACvB,KAAK,CAACO,GAAGC,MAAMD,EAAE,cAAc,cAAcC,EAAE,aAAa,CAAC,GAE1DC,IAAeH,EAAO;AAAA,IAC1B,CAACI,GAAKT,GAAKU,MAASV,EAAI,iBAAiBG,IAAQO,IAAMD;AAAA,IACvD;AAAA,EAAA;AAGF,SAAOJ,EAAO,IAAI,CAACL,GAAKU,MAAQ;AAC9B,UAAMC,IAAiC,CAAA,GACjCC,IAAeZ,EAAI,gBAAgB,CAAA;AACzC,IAAAY,EAAa,QAAQ,CAACC,GAAaC,MAAa;AAC9C,MAAI,CAACD,EAAY,OAAOA,EAAY,aAAa,OACjDF,EAAOI,EAAgBF,GAAaC,GAAUF,CAAY,CAAC,IACzDC,EAAY,UAAU,QAAQA,EAAY,UAAU,SAChD,KACA,OAAOA,EAAY,KAAK;AAAA,IAChC,CAAC;AACD,UAAMG,IACJN,MAAQF,IAAe,YAAYE,IAAMF,IAAe,cAAc;AACxE,WAAO;AAAA,MACL,IAAI,GAAGR,EAAI,OAAO,KAAK,IAAIA,EAAI,aAAa,IAAIU,CAAG;AAAA,MACnD,eAAeV,EAAI;AAAA,MACnB,QAAAgB;AAAA,MACA,QAAAL;AAAA,IAAA;AAAA,EAEJ,CAAC;AACH;AAQO,SAASM,EAA0Bf,GAAgD;AACxF,QAAMgB,wBAAW,IAAA;AACjB,aAAWlB,KAAOE,GAAM;AACtB,UAAMU,IAAeZ,EAAI,gBAAgB,CAAA;AACzC,IAAAY,EAAa,QAAQ,CAACC,GAAaM,MAAU;AAC3C,UAAI,CAACN,EAAY,OAAOA,EAAY,aAAa,GAAO;AACxD,YAAMO,IAAYL,EAAgBF,GAAaM,GAAOP,CAAY;AAClE,MAAKM,EAAK,IAAIE,CAAS,KACrBF,EAAK,IAAIE,GAAW,EAAE,KAAKA,GAAW,OAAOP,EAAY,OAAO;AAAA,IAEpE,CAAC;AAAA,EACH;AACA,SAAO,MAAM,KAAKK,EAAK,OAAA,CAAQ;AACjC;"}
@@ -1,15 +1,19 @@
1
1
  import { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement';
2
2
  interface RequirementFieldsProps {
3
- /** Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path. */
3
+ /**
4
+ * Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path.
5
+ * Non-editable requirements, and requirements resolved as never-applicable against a
6
+ * non-editable sibling, are dropped via {@link prepareRequirements} before rendering.
7
+ */
4
8
  requirements: TaxRequirement[] | undefined;
5
9
  /** RHF path segment the requirements are nested under, e.g. `taxrates` or `fields`. */
6
10
  requirementSetKey: string;
7
11
  }
8
12
  /**
9
13
  * Renders one form field per editable, currently-applicable requirement, filtering
10
- * out non-editable requirements, requirements with no `key` (the API doesn't guarantee one, and
11
- * without it there's no stable form path to register), and requirements whose `applicableIf`
12
- * constraints aren't satisfied by the form's current values.
14
+ * out requirements with no `key` (the API doesn't guarantee one, and without it there's no stable
15
+ * form path to register) and requirements whose `applicableIf` constraints aren't satisfied by
16
+ * the form's current values.
13
17
  *
14
18
  * @internal
15
19
  */
@@ -1,24 +1,25 @@
1
- import { jsx as o, Fragment as f } from "react/jsx-runtime";
2
- import { useFormContext as p, useWatch as l } from "react-hook-form";
3
- import { getUniqueRhfKey as s } from "./rhfKey.js";
1
+ import { jsx as e, Fragment as n } from "react/jsx-runtime";
2
+ import { useFormContext as a, useWatch as f } from "react-hook-form";
3
+ import { getUniqueRhfKey as u } from "./rhfKey.js";
4
4
  import { isRequirementApplicable as c } from "./applicableIf.js";
5
- import { QuestionInput as m } from "../../../Common/TaxInputs/TaxInputs.js";
6
- function k({ requirements: r, requirementSetKey: e }) {
7
- const { control: i } = p(), n = l({ control: i });
8
- return /* @__PURE__ */ o(f, { children: r?.flatMap((t, a) => t.key ? t.editable === !1 ? [] : c(t, e, n) ? [
9
- /* @__PURE__ */ o(f, { children: /* @__PURE__ */ o(
10
- m,
5
+ import { prepareRequirements as l } from "./prepareRequirements.js";
6
+ import { QuestionInput as d } from "../../../Common/TaxInputs/TaxInputs.js";
7
+ function F({ requirements: i, requirementSetKey: r }) {
8
+ const { control: m } = a(), s = f({ control: m }), o = l(i ?? []);
9
+ return /* @__PURE__ */ e(n, { children: o.flatMap((t, p) => t.key ? c(t, r, s) ? [
10
+ /* @__PURE__ */ e(n, { children: /* @__PURE__ */ e(
11
+ d,
11
12
  {
12
13
  requirement: {
13
14
  ...t,
14
- key: `${e}.${s(t, a, r)}`
15
+ key: `${r}.${u(t, p, o)}`
15
16
  },
16
17
  questionType: t.metadata?.type ?? "Text"
17
18
  }
18
- ) }, `${t.key}-${a}`)
19
+ ) }, `${t.key}-${p}`)
19
20
  ] : [] : []) });
20
21
  }
21
22
  export {
22
- k as RequirementFields
23
+ F as RequirementFields
23
24
  };
24
25
  //# sourceMappingURL=RequirementFields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequirementFields.js","sources":["../../../../../src/components/Company/StateTaxes/shared/RequirementFields.tsx"],"sourcesContent":["import { Fragment } from 'react/jsx-runtime'\nimport { useFormContext, useWatch } from 'react-hook-form'\nimport type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\nimport { getUniqueRhfKey } from './rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from './applicableIf'\nimport { QuestionInput } from '@/components/Common/TaxInputs/TaxInputs'\n\ninterface RequirementFieldsProps {\n /** Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path. */\n requirements: TaxRequirement[] | undefined\n /** RHF path segment the requirements are nested under, e.g. `taxrates` or `fields`. */\n requirementSetKey: string\n}\n\n/**\n * Renders one form field per editable, currently-applicable requirement, filtering\n * out non-editable requirements, requirements with no `key` (the API doesn't guarantee one, and\n * without it there's no stable form path to register), and requirements whose `applicableIf`\n * constraints aren't satisfied by the form's current values.\n *\n * @internal\n */\nexport function RequirementFields({ requirements, requirementSetKey }: RequirementFieldsProps) {\n const { control } = useFormContext()\n const watchedValues = useWatch({ control }) as StateTaxesFormValues\n\n return (\n <>\n {requirements?.flatMap((requirement, index) => {\n if (!requirement.key) return []\n if (requirement.editable === false) return []\n if (!isRequirementApplicable(requirement, requirementSetKey, watchedValues)) return []\n return [\n <Fragment key={`${requirement.key}-${index}`}>\n <QuestionInput\n requirement={{\n ...requirement,\n key: `${requirementSetKey}.${getUniqueRhfKey(requirement, index, requirements)}`,\n }}\n questionType={requirement.metadata?.type ?? 'Text'}\n />\n </Fragment>,\n ]\n })}\n </>\n )\n}\n"],"names":["RequirementFields","requirements","requirementSetKey","control","useFormContext","watchedValues","useWatch","jsx","Fragment","requirement","index","isRequirementApplicable","QuestionInput","getUniqueRhfKey"],"mappings":";;;;;AAsBO,SAASA,EAAkB,EAAE,cAAAC,GAAc,mBAAAC,KAA6C;AAC7F,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GACdC,IAAgBC,EAAS,EAAE,SAAAH,GAAS;AAE1C,SACE,gBAAAI,EAAAC,GAAA,EACG,UAAAP,GAAc,QAAQ,CAACQ,GAAaC,MAC9BD,EAAY,MACbA,EAAY,aAAa,KAAc,CAAA,IACtCE,EAAwBF,GAAaP,GAAmBG,CAAa,IACnE;AAAA,IACL,gBAAAE,EAACC,GAAA,EACC,UAAA,gBAAAD;AAAA,MAACK;AAAA,MAAA;AAAA,QACC,aAAa;AAAA,UACX,GAAGH;AAAA,UACH,KAAK,GAAGP,CAAiB,IAAIW,EAAgBJ,GAAaC,GAAOT,CAAY,CAAC;AAAA,QAAA;AAAA,QAEhF,cAAcQ,EAAY,UAAU,QAAQ;AAAA,MAAA;AAAA,IAAA,KANjC,GAAGA,EAAY,GAAG,IAAIC,CAAK,EAQ1C;AAAA,EAAA,IAVkF,CAAA,IAFvD,CAAA,CAc9B,EAAA,CACH;AAEJ;"}
1
+ {"version":3,"file":"RequirementFields.js","sources":["../../../../../src/components/Company/StateTaxes/shared/RequirementFields.tsx"],"sourcesContent":["import { Fragment } from 'react/jsx-runtime'\nimport { useFormContext, useWatch } from 'react-hook-form'\nimport type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\nimport { getUniqueRhfKey } from './rhfKey'\nimport { isRequirementApplicable, type StateTaxesFormValues } from './applicableIf'\nimport { prepareRequirements } from './prepareRequirements'\nimport { QuestionInput } from '@/components/Common/TaxInputs/TaxInputs'\n\ninterface RequirementFieldsProps {\n /**\n * Requirements to render as inputs, nested under `requirementSetKey` in the form's RHF path.\n * Non-editable requirements, and requirements resolved as never-applicable against a\n * non-editable sibling, are dropped via {@link prepareRequirements} before rendering.\n */\n requirements: TaxRequirement[] | undefined\n /** RHF path segment the requirements are nested under, e.g. `taxrates` or `fields`. */\n requirementSetKey: string\n}\n\n/**\n * Renders one form field per editable, currently-applicable requirement, filtering\n * out requirements with no `key` (the API doesn't guarantee one, and without it there's no stable\n * form path to register) and requirements whose `applicableIf` constraints aren't satisfied by\n * the form's current values.\n *\n * @internal\n */\nexport function RequirementFields({ requirements, requirementSetKey }: RequirementFieldsProps) {\n const { control } = useFormContext()\n const watchedValues = useWatch({ control }) as StateTaxesFormValues\n const preparedRequirements = prepareRequirements(requirements ?? [])\n\n return (\n <>\n {preparedRequirements.flatMap((requirement, index) => {\n if (!requirement.key) return []\n if (!isRequirementApplicable(requirement, requirementSetKey, watchedValues)) return []\n return [\n <Fragment key={`${requirement.key}-${index}`}>\n <QuestionInput\n requirement={{\n ...requirement,\n key: `${requirementSetKey}.${getUniqueRhfKey(requirement, index, preparedRequirements)}`,\n }}\n questionType={requirement.metadata?.type ?? 'Text'}\n />\n </Fragment>,\n ]\n })}\n </>\n )\n}\n"],"names":["RequirementFields","requirements","requirementSetKey","control","useFormContext","watchedValues","useWatch","preparedRequirements","prepareRequirements","jsx","Fragment","requirement","index","isRequirementApplicable","QuestionInput","getUniqueRhfKey"],"mappings":";;;;;;AA2BO,SAASA,EAAkB,EAAE,cAAAC,GAAc,mBAAAC,KAA6C;AAC7F,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GACdC,IAAgBC,EAAS,EAAE,SAAAH,GAAS,GACpCI,IAAuBC,EAAoBP,KAAgB,EAAE;AAEnE,SACE,gBAAAQ,EAAAC,GAAA,EACG,UAAAH,EAAqB,QAAQ,CAACI,GAAaC,MACrCD,EAAY,MACZE,EAAwBF,GAAaT,GAAmBG,CAAa,IACnE;AAAA,IACL,gBAAAI,EAACC,GAAA,EACC,UAAA,gBAAAD;AAAA,MAACK;AAAA,MAAA;AAAA,QACC,aAAa;AAAA,UACX,GAAGH;AAAA,UACH,KAAK,GAAGT,CAAiB,IAAIa,EAAgBJ,GAAaC,GAAOL,CAAoB,CAAC;AAAA,QAAA;AAAA,QAExF,cAAcI,EAAY,UAAU,QAAQ;AAAA,MAAA;AAAA,IAAA,KANjC,GAAGA,EAAY,GAAG,IAAIC,CAAK,EAQ1C;AAAA,EAAA,IAVkF,CAAA,IADvD,CAAA,CAa9B,EAAA,CACH;AAEJ;"}
@@ -0,0 +1,29 @@
1
+ import { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement';
2
+ /**
3
+ * Resolves each requirement's `applicableIf` constraints against non-editable (system/agency-set)
4
+ * siblings, and drops requirements that can never become applicable — mirroring gws-flows'
5
+ * `TaxRequirements::Edit.prepare_requirements`, which performs this same resolution server-side
6
+ * before Rails renders its own edit view.
7
+ *
8
+ * @remarks
9
+ * A constraint referencing an editable sibling is left untouched, since it can only be resolved
10
+ * dynamically against the user's current form input (see {@link isRequirementApplicable}). A
11
+ * constraint referencing a non-editable sibling is resolved once here, against that sibling's
12
+ * fetched `value`, since a non-editable value can never change over the lifetime of the form:
13
+ * - If the sibling's value satisfies the constraint, the constraint is dropped (the requirement
14
+ * is always applicable).
15
+ * - If it doesn't, the whole requirement is dropped — it can never become applicable.
16
+ *
17
+ * Non-editable requirements are dropped unconditionally, since they never become form fields.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare function prepareRequirements(requirements: TaxRequirement[]): TaxRequirement[];
22
+ /**
23
+ * Whether a requirement set has anything left to edit once {@link prepareRequirements} resolves
24
+ * non-editable-sibling constraints and drops non-editable/unsatisfiable requirements — mirroring
25
+ * gws-flows' `TaxRequirements::Edit.set_editable?`.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function isRequirementSetEditable(requirements: TaxRequirement[]): boolean;
@@ -0,0 +1,24 @@
1
+ function s(n) {
2
+ return n.flatMap((t) => {
3
+ if (t.editable === !1) return [];
4
+ const l = t.applicableIf ?? [], a = [];
5
+ for (const e of l) {
6
+ const i = n.find((o) => o.key === e.key);
7
+ if (!i || i.editable !== !1) {
8
+ a.push(e);
9
+ continue;
10
+ }
11
+ if (i.value !== e.value)
12
+ return [];
13
+ }
14
+ return [{ ...t, applicableIf: a }];
15
+ });
16
+ }
17
+ function r(n) {
18
+ return s(n).length > 0;
19
+ }
20
+ export {
21
+ r as isRequirementSetEditable,
22
+ s as prepareRequirements
23
+ };
24
+ //# sourceMappingURL=prepareRequirements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareRequirements.js","sources":["../../../../../src/components/Company/StateTaxes/shared/prepareRequirements.ts"],"sourcesContent":["import type { TaxRequirement } from '@gusto/embedded-api/models/components/taxrequirement'\n\n/**\n * Resolves each requirement's `applicableIf` constraints against non-editable (system/agency-set)\n * siblings, and drops requirements that can never become applicable — mirroring gws-flows'\n * `TaxRequirements::Edit.prepare_requirements`, which performs this same resolution server-side\n * before Rails renders its own edit view.\n *\n * @remarks\n * A constraint referencing an editable sibling is left untouched, since it can only be resolved\n * dynamically against the user's current form input (see {@link isRequirementApplicable}). A\n * constraint referencing a non-editable sibling is resolved once here, against that sibling's\n * fetched `value`, since a non-editable value can never change over the lifetime of the form:\n * - If the sibling's value satisfies the constraint, the constraint is dropped (the requirement\n * is always applicable).\n * - If it doesn't, the whole requirement is dropped — it can never become applicable.\n *\n * Non-editable requirements are dropped unconditionally, since they never become form fields.\n *\n * @internal\n */\nexport function prepareRequirements(requirements: TaxRequirement[]): TaxRequirement[] {\n return requirements.flatMap(requirement => {\n if (requirement.editable === false) return []\n\n const constraints = requirement.applicableIf ?? []\n const resolvedConstraints: typeof constraints = []\n\n for (const constraint of constraints) {\n const sibling = requirements.find(candidate => candidate.key === constraint.key)\n\n if (!sibling || sibling.editable !== false) {\n resolvedConstraints.push(constraint)\n continue\n }\n\n if (sibling.value === constraint.value) continue\n\n return []\n }\n\n return [{ ...requirement, applicableIf: resolvedConstraints }]\n })\n}\n\n/**\n * Whether a requirement set has anything left to edit once {@link prepareRequirements} resolves\n * non-editable-sibling constraints and drops non-editable/unsatisfiable requirements — mirroring\n * gws-flows' `TaxRequirements::Edit.set_editable?`.\n *\n * @internal\n */\nexport function isRequirementSetEditable(requirements: TaxRequirement[]): boolean {\n return prepareRequirements(requirements).length > 0\n}\n"],"names":["prepareRequirements","requirements","requirement","constraints","resolvedConstraints","constraint","sibling","candidate","isRequirementSetEditable"],"mappings":"AAqBO,SAASA,EAAoBC,GAAkD;AACpF,SAAOA,EAAa,QAAQ,CAAAC,MAAe;AACzC,QAAIA,EAAY,aAAa,GAAO,QAAO,CAAA;AAE3C,UAAMC,IAAcD,EAAY,gBAAgB,CAAA,GAC1CE,IAA0C,CAAA;AAEhD,eAAWC,KAAcF,GAAa;AACpC,YAAMG,IAAUL,EAAa,KAAK,OAAaM,EAAU,QAAQF,EAAW,GAAG;AAE/E,UAAI,CAACC,KAAWA,EAAQ,aAAa,IAAO;AAC1C,QAAAF,EAAoB,KAAKC,CAAU;AACnC;AAAA,MACF;AAEA,UAAIC,EAAQ,UAAUD,EAAW;AAEjC,eAAO,CAAA;AAAA,IACT;AAEA,WAAO,CAAC,EAAE,GAAGH,GAAa,cAAcE,GAAqB;AAAA,EAC/D,CAAC;AACH;AASO,SAASI,EAAyBP,GAAyC;AAChF,SAAOD,EAAoBC,CAAY,EAAE,SAAS;AACpD;"}