@gusto/embedded-react-sdk 0.46.2 → 0.46.3
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/CHANGELOG.md +67 -0
- package/dist/components/Common/DataView/DataTable/DataTable.js +76 -72
- package/dist/components/Common/DataView/DataTable/DataTable.js.map +1 -1
- package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js +8 -0
- package/dist/components/Common/DataView/DataTable/DataTable.module.scss.js.map +1 -0
- package/dist/components/Common/DataView/useDataView.d.ts +2 -0
- package/dist/components/Common/DataView/useDataView.js.map +1 -1
- package/dist/components/Common/DocumentViewer/DocumentViewer.js +10 -10
- package/dist/components/Common/DocumentViewer/DocumentViewer.js.map +1 -1
- package/dist/components/Common/DocumentViewer/DocumentViewer.module.scss.js +9 -9
- package/dist/components/Common/PaginationControl/PaginationControl.js +11 -10
- package/dist/components/Common/PaginationControl/PaginationControl.js.map +1 -1
- package/dist/components/Common/PaginationControl/PaginationControlTypes.d.ts +1 -1
- package/dist/components/Common/UI/DescriptionList/DescriptionList.js +11 -10
- package/dist/components/Common/UI/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Common/UI/DescriptionList/DescriptionList.module.scss.js +4 -4
- package/dist/components/Common/UI/Input/InputTypes.d.ts +1 -1
- package/dist/components/Common/UI/Input/InputTypes.js.map +1 -1
- package/dist/components/Common/UI/NumberInput/NumberInput.js +51 -48
- package/dist/components/Common/UI/NumberInput/NumberInput.js.map +1 -1
- package/dist/components/Common/VisuallyHidden/VisuallyHidden.d.ts +1 -1
- package/dist/components/Common/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +3 -4
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +3 -4
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +5 -6
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +3 -4
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +3 -4
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/shared/useSignCompanyForm/fields.js +4 -4
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +5 -6
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +6 -7
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +3 -4
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +3 -4
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +3 -4
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/fields.js +5 -5
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +3 -4
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +3 -4
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Contractor/Address/useAddress.js +5 -6
- package/dist/components/Contractor/Address/useAddress.js.map +1 -1
- package/dist/components/Contractor/Profile/useContractorProfile.js +33 -34
- package/dist/components/Contractor/Profile/useContractorProfile.js.map +1 -1
- package/dist/components/Employee/Compensation/management/EditCompensation/EditCompensation.js +14 -11
- package/dist/components/Employee/Compensation/management/EditCompensation/EditCompensation.js.map +1 -1
- package/dist/components/Employee/Compensation/management/EditPendingCompensation/EditPendingCompensation.js +0 -2
- package/dist/components/Employee/Compensation/management/EditPendingCompensation/EditPendingCompensation.js.map +1 -1
- package/dist/components/Employee/Compensation/management/ManagementCompensationFormBody.js +18 -18
- package/dist/components/Employee/Compensation/management/ManagementCompensationFormBody.js.map +1 -1
- package/dist/components/Employee/Compensation/onboarding/JobsList/JobsListPresentation.js +36 -36
- package/dist/components/Employee/Compensation/onboarding/JobsList/JobsListPresentation.js.map +1 -1
- package/dist/components/Employee/Compensation/shared/useCompensationForm/fields.js +4 -4
- package/dist/components/Employee/Compensation/shared/useCompensationForm/useCompensationForm.js +140 -140
- package/dist/components/Employee/Compensation/shared/useCompensationForm/useCompensationForm.js.map +1 -1
- package/dist/components/Employee/Compensation/shared/useJobForm/fields.js +6 -6
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.d.ts +6 -5
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js +162 -131
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js.map +1 -1
- package/dist/components/Employee/Dashboard/BasicDetailsView.js +74 -88
- package/dist/components/Employee/Dashboard/BasicDetailsView.js.map +1 -1
- package/dist/components/Employee/Dashboard/Dashboard.js +53 -51
- package/dist/components/Employee/Dashboard/Dashboard.js.map +1 -1
- package/dist/components/Employee/Dashboard/DocumentsView.js +17 -10
- package/dist/components/Employee/Dashboard/DocumentsView.js.map +1 -1
- package/dist/components/Employee/Dashboard/JobAndPayView.js +383 -357
- package/dist/components/Employee/Dashboard/JobAndPayView.js.map +1 -1
- package/dist/components/Employee/Dashboard/TaxesView.js +114 -101
- package/dist/components/Employee/Dashboard/TaxesView.js.map +1 -1
- package/dist/components/Employee/Dashboard/getPendingCompensationChanges.js +36 -36
- package/dist/components/Employee/Dashboard/getPendingCompensationChanges.js.map +1 -1
- package/dist/components/Employee/Deductions/DeductionsForm/StandardDeductionForm.js +57 -57
- package/dist/components/Employee/Deductions/DeductionsForm/StandardDeductionForm.js.map +1 -1
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.d.ts +14 -5
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.js +55 -36
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.js.map +1 -1
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/fields.js +8 -8
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.js +18 -18
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.js.map +1 -1
- package/dist/components/Employee/Deductions/shared/useDeductionForm/fields.js +4 -4
- package/dist/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.d.ts +3 -3
- package/dist/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +3 -4
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/shared/useSignEmployeeForm/fields.js +1 -1
- package/dist/components/Employee/FederalTaxes/shared/useFederalTaxesForm/fields.js +4 -4
- package/dist/components/Employee/HomeAddress/management/HomeAddressView.js +157 -147
- package/dist/components/Employee/HomeAddress/management/HomeAddressView.js.map +1 -1
- package/dist/components/Employee/HomeAddress/management/useHomeAddressManagement.js +56 -55
- package/dist/components/Employee/HomeAddress/management/useHomeAddressManagement.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js +20 -20
- package/dist/components/Employee/PaymentMethod/onboarding/BankForm.js.map +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/fields.js +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.d.ts +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.js +4 -4
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/fields.js +8 -8
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/fields.js +5 -5
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.d.ts +0 -1
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.js +11 -12
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/homeAddressSchema.test.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.d.ts +6 -1
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.js +95 -94
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useHomeAddressForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/fields.js +4 -4
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.d.ts +6 -1
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.js +87 -86
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useWorkAddressForm.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js +18 -18
- package/dist/components/Employee/StateTaxes/shared/EmployeeStateTaxesView.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fieldComponents.js +8 -8
- package/dist/components/Employee/Taxes/useTaxes.js +3 -4
- package/dist/components/Employee/Taxes/useTaxes.js.map +1 -1
- package/dist/components/Employee/WorkAddress/management/WorkAddressView.js +5 -1
- package/dist/components/Employee/WorkAddress/management/WorkAddressView.js.map +1 -1
- package/dist/components/Employee/WorkAddress/management/useWorkAddressManagement.js +61 -60
- package/dist/components/Employee/WorkAddress/management/useWorkAddressManagement.js.map +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +2 -3
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +2 -3
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesHoliday.js +6 -7
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesHoliday.js.map +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.d.ts +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.js +52 -68
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.js.map +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentation.module.scss.js +4 -4
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesPresentationTypes.d.ts +0 -11
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js +137 -163
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/SelectEmployeesTimeOff.js.map +1 -1
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/useSelectEmployeesData.js +36 -35
- package/dist/components/TimeOff/TimeOffManagement/SelectEmployees/useSelectEmployeesData.js.map +1 -1
- package/dist/components/TimeOff/TimeOffPolicyDetail/TimeOffPolicyDetailPresentation.js +34 -34
- package/dist/components/TimeOff/TimeOffPolicyDetail/TimeOffPolicyDetailPresentation.js.map +1 -1
- package/dist/helpers/breadcrumbHelpers.d.ts +1 -1
- package/dist/helpers/breadcrumbHelpers.js.map +1 -1
- package/dist/helpers/federalEin.d.ts +1 -0
- package/dist/helpers/federalEin.js.map +1 -1
- package/dist/helpers/mask.d.ts +8 -4
- package/dist/helpers/mask.js.map +1 -1
- package/dist/helpers/rem.d.ts +2 -1
- package/dist/helpers/rem.js.map +1 -1
- package/dist/hooks/useAsyncError.d.ts +1 -0
- package/dist/hooks/useAsyncError.js.map +1 -1
- package/dist/hooks/useForkRef/useForkRef.d.ts +1 -0
- package/dist/hooks/useForkRef/useForkRef.js.map +1 -1
- package/dist/i18n/I18n.d.ts +9 -1
- package/dist/i18n/I18n.js.map +1 -1
- package/dist/i18n/en/Company.TimeOff.EmployeeTable.json.js +14 -14
- package/dist/i18n/en/Company.TimeOff.SelectEmployees.json.js +12 -18
- package/dist/i18n/en/Company.TimeOff.SelectEmployees.json.js.map +1 -1
- package/dist/i18n/en/Employee.Compensation.json.js +24 -24
- package/dist/i18n/en/Employee.Dashboard.json.js +22 -20
- package/dist/i18n/en/Employee.Dashboard.json.js.map +1 -1
- package/dist/i18n/en/Employee.PaymentMethod.json.js +25 -25
- package/dist/i18n/en/Employee.StateTaxes.json.js +12 -10
- package/dist/i18n/en/Employee.StateTaxes.json.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/hooks.d.ts +1 -1
- package/dist/types/i18next.d.ts +4 -17
- package/dist/types/observability.d.ts +1 -1
- package/package.json +30 -27
- package/dist/components/Employee/Dashboard/CompensationCard.d.ts +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"childSupportGarnishmentFormSchema.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport { PaymentPeriod } from '@gusto/embedded-api/models/components/garnishmentchildsupport'\nimport type { Agencies } from '@gusto/embedded-api/models/components/childsupportdata'\nimport {\n buildFormSchema,\n type RequiredFieldConfig,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { coerceNaN } from '@/partner-hook-utils/form/preprocessors'\n\n// ── Error codes ────────────────────────────────────────────────────────\n\nexport const ChildSupportGarnishmentFormErrorCodes = {\n REQUIRED: 'REQUIRED',\n NEGATIVE_AMOUNT: 'NEGATIVE_AMOUNT',\n PERCENT_OUT_OF_RANGE: 'PERCENT_OUT_OF_RANGE',\n} as const\n\nexport type ChildSupportGarnishmentFormErrorCode =\n (typeof ChildSupportGarnishmentFormErrorCodes)[keyof typeof ChildSupportGarnishmentFormErrorCodes]\n\n// ── Required-attribute keys recognized from the API ────────────────────\n\n/**\n * Agencies declare which child-support attributes they need via\n * `required_attributes[].key`. The legacy form only mapped three keys;\n * unknown keys are ignored both there and here.\n */\nexport const SUPPORTED_REQUIRED_ATTR_KEYS = [\n 'case_number',\n 'order_number',\n 'remittance_number',\n] as const\n\nexport type SupportedRequiredAttrKey = (typeof SUPPORTED_REQUIRED_ATTR_KEYS)[number]\n\n// Field name on the form for each required-attribute key.\nexport const REQUIRED_ATTR_FIELD_NAME: Record<SupportedRequiredAttrKey, string> = {\n case_number: 'caseNumber',\n order_number: 'orderNumber',\n remittance_number: 'remittanceNumber',\n}\n\nexport function getRequiredAttrKeys(agency?: Agencies | null): Set<SupportedRequiredAttrKey> {\n const keys = new Set<SupportedRequiredAttrKey>()\n if (!agency?.requiredAttributes) return keys\n for (const attr of agency.requiredAttributes) {\n if (!attr.key) continue\n if ((SUPPORTED_REQUIRED_ATTR_KEYS as readonly string[]).includes(attr.key)) {\n keys.add(attr.key as SupportedRequiredAttrKey)\n }\n }\n return keys\n}\n\n// ── Field validators ───────────────────────────────────────────────────\n\nconst PERCENT_MIN = 0\nconst PERCENT_MAX = 100\n\nconst fieldValidators = {\n state: z.string(),\n fipsCode: z.string(),\n caseNumber: z.string(),\n orderNumber: z.string(),\n remittanceNumber: z.string(),\n // Currency cap on the pay-period — required, ≥ 0.\n payPeriodMaximum: z.preprocess(\n coerceNaN(0),\n z.number().min(0, { message: ChildSupportGarnishmentFormErrorCodes.NEGATIVE_AMOUNT }),\n ),\n // Percentage of paycheck, 0-100. Required.\n amount: z.preprocess(\n coerceNaN(0),\n z\n .number()\n .min(PERCENT_MIN, {\n message: ChildSupportGarnishmentFormErrorCodes.PERCENT_OUT_OF_RANGE,\n })\n .max(PERCENT_MAX, {\n message: ChildSupportGarnishmentFormErrorCodes.PERCENT_OUT_OF_RANGE,\n }),\n ),\n paymentPeriod: z.enum(PaymentPeriod),\n}\n\nexport type ChildSupportGarnishmentFormField = keyof typeof fieldValidators\n\nexport type ChildSupportGarnishmentFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\nexport type ChildSupportGarnishmentFormOutputs = ChildSupportGarnishmentFormData\n\n// ── Required fields config ─────────────────────────────────────────────\n//\n// `state`, `fipsCode`, `payPeriodMaximum`, `amount`, `paymentPeriod` are\n// always required. The three agency-attribute fields toggle requiredness\n// based on the currently selected agency — see `createChildSupportGarnishmentFormSchema`\n// which assigns 'always' / 'never' per call.\n\ninterface ChildSupportGarnishmentFormSchemaOptions {\n mode?: 'create' | 'update'\n /**\n * The agency record matching the currently selected `state`.
|
|
1
|
+
{"version":3,"file":"childSupportGarnishmentFormSchema.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/childSupportGarnishmentFormSchema.ts"],"sourcesContent":["import { z } from 'zod'\nimport { PaymentPeriod } from '@gusto/embedded-api/models/components/garnishmentchildsupport'\nimport type { Agencies } from '@gusto/embedded-api/models/components/childsupportdata'\nimport {\n buildFormSchema,\n type RequiredFieldConfig,\n} from '@/partner-hook-utils/form/buildFormSchema'\nimport { coerceNaN } from '@/partner-hook-utils/form/preprocessors'\n\n// ── Error codes ────────────────────────────────────────────────────────\n\nexport const ChildSupportGarnishmentFormErrorCodes = {\n REQUIRED: 'REQUIRED',\n NEGATIVE_AMOUNT: 'NEGATIVE_AMOUNT',\n PERCENT_OUT_OF_RANGE: 'PERCENT_OUT_OF_RANGE',\n} as const\n\nexport type ChildSupportGarnishmentFormErrorCode =\n (typeof ChildSupportGarnishmentFormErrorCodes)[keyof typeof ChildSupportGarnishmentFormErrorCodes]\n\n// ── Required-attribute keys recognized from the API ────────────────────\n\n/**\n * Agencies declare which child-support attributes they need via\n * `required_attributes[].key`. The legacy form only mapped three keys;\n * unknown keys are ignored both there and here.\n */\nexport const SUPPORTED_REQUIRED_ATTR_KEYS = [\n 'case_number',\n 'order_number',\n 'remittance_number',\n] as const\n\nexport type SupportedRequiredAttrKey = (typeof SUPPORTED_REQUIRED_ATTR_KEYS)[number]\n\n// Field name on the form for each required-attribute key.\nexport const REQUIRED_ATTR_FIELD_NAME: Record<SupportedRequiredAttrKey, string> = {\n case_number: 'caseNumber',\n order_number: 'orderNumber',\n remittance_number: 'remittanceNumber',\n}\n\nexport function getRequiredAttrKeys(agency?: Agencies | null): Set<SupportedRequiredAttrKey> {\n const keys = new Set<SupportedRequiredAttrKey>()\n if (!agency?.requiredAttributes) return keys\n for (const attr of agency.requiredAttributes) {\n if (!attr.key) continue\n if ((SUPPORTED_REQUIRED_ATTR_KEYS as readonly string[]).includes(attr.key)) {\n keys.add(attr.key as SupportedRequiredAttrKey)\n }\n }\n return keys\n}\n\n// ── Field validators ───────────────────────────────────────────────────\n\nconst PERCENT_MIN = 0\nconst PERCENT_MAX = 100\n\nconst fieldValidators = {\n state: z.string(),\n fipsCode: z.string(),\n caseNumber: z.string(),\n orderNumber: z.string(),\n remittanceNumber: z.string(),\n // Currency cap on the pay-period — required, ≥ 0.\n payPeriodMaximum: z.preprocess(\n coerceNaN(0),\n z.number().min(0, { message: ChildSupportGarnishmentFormErrorCodes.NEGATIVE_AMOUNT }),\n ),\n // Percentage of paycheck, 0-100. Required.\n amount: z.preprocess(\n coerceNaN(0),\n z\n .number()\n .min(PERCENT_MIN, {\n message: ChildSupportGarnishmentFormErrorCodes.PERCENT_OUT_OF_RANGE,\n })\n .max(PERCENT_MAX, {\n message: ChildSupportGarnishmentFormErrorCodes.PERCENT_OUT_OF_RANGE,\n }),\n ),\n paymentPeriod: z.enum(PaymentPeriod),\n}\n\nexport type ChildSupportGarnishmentFormField = keyof typeof fieldValidators\n\nexport type ChildSupportGarnishmentFormData = {\n [K in keyof typeof fieldValidators]: z.infer<(typeof fieldValidators)[K]>\n}\n\nexport type ChildSupportGarnishmentFormOutputs = ChildSupportGarnishmentFormData\n\n// ── Required fields config ─────────────────────────────────────────────\n//\n// `state`, `fipsCode`, `payPeriodMaximum`, `amount`, `paymentPeriod` are\n// always required. The three agency-attribute fields toggle requiredness\n// based on the currently selected agency — see `createChildSupportGarnishmentFormSchema`\n// which assigns 'always' / 'never' per call.\n\ninterface ChildSupportGarnishmentFormSchemaOptions {\n mode?: 'create' | 'update'\n /**\n * The agency record matching the currently selected `state`. Used only when\n * `agencyList` is not provided — `requiredAttributes` are pinned to this\n * single agency, so the schema must be rebuilt whenever the user picks a\n * different state. Prefer passing `agencyList` instead so requiredness\n * tracks the form's `state` value dynamically.\n */\n selectedAgency?: Agencies | null\n /**\n * Full list of agencies. When provided, the schema's requiredness for\n * `caseNumber` / `orderNumber` / `remittanceNumber` is computed at validation\n * time by looking up the agency whose `state` matches the form's `state`\n * value — so a single schema instance stays correct as the user changes\n * states. Takes precedence over `selectedAgency`.\n */\n agencyList?: readonly Agencies[]\n}\n\nexport function createChildSupportGarnishmentFormSchema({\n mode = 'create',\n selectedAgency,\n agencyList,\n}: ChildSupportGarnishmentFormSchemaOptions = {}) {\n // Read `data.state` eagerly (outside the `agencyList.find` callback) so that\n // `buildFormSchema`'s proxy-based predicate-dep detection always observes\n // the `state` access — otherwise an empty `agencyList` at schema-build time\n // would short-circuit the `find` before the proxy sees `data.state` and\n // `useDeriveFieldsMetadata` would treat the field metadata as static.\n const requiredFieldsConfig = agencyList\n ? ({\n caseNumber: data => {\n const state = data.state\n return getRequiredAttrKeys(agencyList.find(a => a.state === state)).has('case_number')\n },\n orderNumber: data => {\n const state = data.state\n return getRequiredAttrKeys(agencyList.find(a => a.state === state)).has('order_number')\n },\n remittanceNumber: data => {\n const state = data.state\n return getRequiredAttrKeys(agencyList.find(a => a.state === state)).has(\n 'remittance_number',\n )\n },\n } satisfies RequiredFieldConfig<typeof fieldValidators>)\n : (() => {\n const requiredAttrKeys = getRequiredAttrKeys(selectedAgency)\n return {\n caseNumber: requiredAttrKeys.has('case_number') ? 'always' : 'never',\n orderNumber: requiredAttrKeys.has('order_number') ? 'always' : 'never',\n remittanceNumber: requiredAttrKeys.has('remittance_number') ? 'always' : 'never',\n } satisfies RequiredFieldConfig<typeof fieldValidators>\n })()\n\n return buildFormSchema(fieldValidators, {\n requiredFieldsConfig,\n requiredErrorCode: ChildSupportGarnishmentFormErrorCodes.REQUIRED,\n mode,\n })\n}\n"],"names":["ChildSupportGarnishmentFormErrorCodes","SUPPORTED_REQUIRED_ATTR_KEYS","getRequiredAttrKeys","agency","keys","attr","PERCENT_MIN","PERCENT_MAX","fieldValidators","z","coerceNaN","PaymentPeriod","createChildSupportGarnishmentFormSchema","mode","selectedAgency","agencyList","requiredFieldsConfig","data","state","a","requiredAttrKeys","buildFormSchema"],"mappings":";;;;AAWO,MAAMA,IAAwC;AAAA,EACnD,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,sBAAsB;AACxB,GAYaC,IAA+B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF;AAWO,SAASC,EAAoBC,GAAyD;AAC3F,QAAMC,wBAAW,IAAA;AACjB,MAAI,CAACD,GAAQ,mBAAoB,QAAOC;AACxC,aAAWC,KAAQF,EAAO;AACxB,IAAKE,EAAK,OACLJ,EAAmD,SAASI,EAAK,GAAG,KACvED,EAAK,IAAIC,EAAK,GAA+B;AAGjD,SAAOD;AACT;AAIA,MAAME,IAAc,GACdC,IAAc,KAEdC,IAAkB;AAAA,EACtB,OAAOC,EAAE,OAAA;AAAA,EACT,UAAUA,EAAE,OAAA;AAAA,EACZ,YAAYA,EAAE,OAAA;AAAA,EACd,aAAaA,EAAE,OAAA;AAAA,EACf,kBAAkBA,EAAE,OAAA;AAAA;AAAA,EAEpB,kBAAkBA,EAAE;AAAA,IAClBC,EAAU,CAAC;AAAA,IACXD,EAAE,SAAS,IAAI,GAAG,EAAE,SAAST,EAAsC,gBAAA,CAAiB;AAAA,EAAA;AAAA;AAAA,EAGtF,QAAQS,EAAE;AAAA,IACRC,EAAU,CAAC;AA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21 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { SelectHookField as t } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
2
|
+
import { SelectHookField as n } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
4
3
|
import { NumberInputHookField as i } from "../../../../../partner-hook-utils/form/fields/NumberInputHookField.js";
|
|
4
|
+
import { TextInputHookField as t } from "../../../../../partner-hook-utils/form/fields/TextInputHookField.js";
|
|
5
5
|
function d(e) {
|
|
6
|
-
return /* @__PURE__ */ r(
|
|
6
|
+
return /* @__PURE__ */ r(n, { ...e, name: "state" });
|
|
7
7
|
}
|
|
8
8
|
function f(e) {
|
|
9
|
-
return /* @__PURE__ */ r(
|
|
9
|
+
return /* @__PURE__ */ r(n, { ...e, name: "fipsCode" });
|
|
10
10
|
}
|
|
11
11
|
function c(e) {
|
|
12
|
-
return /* @__PURE__ */ r(
|
|
12
|
+
return /* @__PURE__ */ r(t, { ...e, name: "caseNumber" });
|
|
13
13
|
}
|
|
14
14
|
function l(e) {
|
|
15
|
-
return /* @__PURE__ */ r(
|
|
15
|
+
return /* @__PURE__ */ r(t, { ...e, name: "orderNumber" });
|
|
16
16
|
}
|
|
17
17
|
function F(e) {
|
|
18
|
-
return /* @__PURE__ */ r(
|
|
18
|
+
return /* @__PURE__ */ r(t, { ...e, name: "remittanceNumber" });
|
|
19
19
|
}
|
|
20
20
|
function p(e) {
|
|
21
21
|
return /* @__PURE__ */ r(i, { ...e, name: "payPeriodMaximum" });
|
|
@@ -24,7 +24,7 @@ function b(e) {
|
|
|
24
24
|
return /* @__PURE__ */ r(i, { ...e, name: "amount" });
|
|
25
25
|
}
|
|
26
26
|
function N(e) {
|
|
27
|
-
return /* @__PURE__ */ r(
|
|
27
|
+
return /* @__PURE__ */ r(n, { ...e, name: "paymentPeriod" });
|
|
28
28
|
}
|
|
29
29
|
export {
|
|
30
30
|
b as AmountField,
|
|
@@ -33,9 +33,9 @@ function He({
|
|
|
33
33
|
validationMode: V = "onSubmit",
|
|
34
34
|
shouldFocusError: W = !0
|
|
35
35
|
}) {
|
|
36
|
-
const o = !P, v = o ? "create" : "update",
|
|
37
|
-
() =>
|
|
38
|
-
[
|
|
36
|
+
const o = !P, v = o ? "create" : "update", c = ae({}), d = u(
|
|
37
|
+
() => c.data?.childSupportData?.agencies ?? [],
|
|
38
|
+
[c.data]
|
|
39
39
|
), h = ne({ employeeId: C }, { enabled: !o }), t = u(() => o ? null : h.data?.garnishments?.find((e) => e.uuid === P) ?? null, [o, P, h.data]), F = u(
|
|
40
40
|
() => ({
|
|
41
41
|
state: t?.childSupport?.state ?? i?.state ?? "",
|
|
@@ -49,8 +49,8 @@ function He({
|
|
|
49
49
|
}),
|
|
50
50
|
[t, i]
|
|
51
51
|
), [E, L] = u(
|
|
52
|
-
() => se({ mode: v }),
|
|
53
|
-
[v]
|
|
52
|
+
() => se({ mode: v, agencyList: d }),
|
|
53
|
+
[v, d]
|
|
54
54
|
), n = ee({
|
|
55
55
|
resolver: re(E),
|
|
56
56
|
mode: V,
|
|
@@ -58,14 +58,14 @@ function He({
|
|
|
58
58
|
defaultValues: F,
|
|
59
59
|
values: F,
|
|
60
60
|
resetOptions: { keepDirtyValues: !0 }
|
|
61
|
-
}),
|
|
62
|
-
() =>
|
|
63
|
-
[
|
|
61
|
+
}), l = te({ control: n.control, name: "state" }), m = u(
|
|
62
|
+
() => d.find((e) => e.state === l) ?? null,
|
|
63
|
+
[d, l]
|
|
64
64
|
), R = Z(null);
|
|
65
65
|
q(() => {
|
|
66
66
|
const e = R.current;
|
|
67
|
-
R.current =
|
|
68
|
-
}, [
|
|
67
|
+
R.current = l, e !== null && e !== "" && e !== l && (n.setValue("caseNumber", ""), n.setValue("orderNumber", ""), n.setValue("remittanceNumber", ""));
|
|
68
|
+
}, [l]);
|
|
69
69
|
const N = m?.fipsCodes ?? [], b = N.length === 1 && !N[0]?.county?.length ? N[0]?.code ?? null : null;
|
|
70
70
|
q(() => {
|
|
71
71
|
b && n.setValue("fipsCode", b);
|
|
@@ -75,27 +75,27 @@ function He({
|
|
|
75
75
|
error: I,
|
|
76
76
|
setError: H
|
|
77
77
|
} = Se("ChildSupportGarnishmentForm"), g = ge(
|
|
78
|
-
o ? [
|
|
78
|
+
o ? [c] : [c, h],
|
|
79
79
|
{ submitError: I, setSubmitError: H }
|
|
80
80
|
), S = u(
|
|
81
|
-
() =>
|
|
81
|
+
() => d.map((e) => ({
|
|
82
82
|
state: e.state ?? "",
|
|
83
83
|
name: e.name ?? e.state ?? "",
|
|
84
84
|
manualPaymentRequired: e.manualPaymentRequired ?? !1
|
|
85
85
|
})),
|
|
86
|
-
[
|
|
87
|
-
),
|
|
86
|
+
[d]
|
|
87
|
+
), p = u(
|
|
88
88
|
() => (m?.fipsCodes ?? []).filter((e) => typeof e.code == "string").map((e) => ({ fipsCode: e.code, county: e.county ?? null })),
|
|
89
89
|
[m]
|
|
90
90
|
), f = u(
|
|
91
91
|
() => ue(m),
|
|
92
92
|
[m]
|
|
93
|
-
), K =
|
|
93
|
+
), K = p.length > 1 || p.length === 1 && b == null, s = ye(L, n.control), B = S.map((e) => ({ value: e.state, label: e.name })), D = p.map((e) => ({
|
|
94
94
|
value: e.fipsCode,
|
|
95
95
|
label: e.county ?? e.fipsCode
|
|
96
96
|
})), Q = {
|
|
97
97
|
state: M(s.state, B, S),
|
|
98
|
-
fipsCode: M(s.fipsCode, D,
|
|
98
|
+
fipsCode: M(s.fipsCode, D, p),
|
|
99
99
|
caseNumber: s.caseNumber,
|
|
100
100
|
orderNumber: s.orderNumber,
|
|
101
101
|
remittanceNumber: s.remittanceNumber,
|
|
@@ -169,11 +169,11 @@ function He({
|
|
|
169
169
|
)();
|
|
170
170
|
}), e;
|
|
171
171
|
}, z = Pe(n);
|
|
172
|
-
return
|
|
172
|
+
return c.isLoading ? { isLoading: !0, errorHandling: g } : !o && h.isLoading ? { isLoading: !0, errorHandling: g } : {
|
|
173
173
|
isLoading: !1,
|
|
174
174
|
data: {
|
|
175
175
|
agencies: S,
|
|
176
|
-
counties:
|
|
176
|
+
counties: p,
|
|
177
177
|
deduction: t
|
|
178
178
|
},
|
|
179
179
|
status: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChildSupportGarnishmentForm.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport {\n type Garnishment,\n type GarnishmentType,\n} from '@gusto/embedded-api/models/components/garnishment'\nimport type { Agencies } from '@gusto/embedded-api/models/components/childsupportdata'\nimport { PaymentPeriod } from '@gusto/embedded-api/models/components/garnishmentchildsupport'\nimport { useGarnishmentsCreateMutation } from '@gusto/embedded-api/react-query/garnishmentsCreate'\nimport { useGarnishmentsUpdateMutation } from '@gusto/embedded-api/react-query/garnishmentsUpdate'\nimport { useGarnishmentsList } from '@gusto/embedded-api/react-query/garnishmentsList'\nimport { useGarnishmentsGetChildSupportData } from '@gusto/embedded-api/react-query/garnishmentsGetChildSupportData'\nimport {\n createChildSupportGarnishmentFormSchema,\n getRequiredAttrKeys,\n type ChildSupportGarnishmentFormData,\n type ChildSupportGarnishmentFormOutputs,\n type SupportedRequiredAttrKey,\n} from './childSupportGarnishmentFormSchema'\nimport {\n StateField,\n FipsCodeField,\n CaseNumberField,\n OrderNumberField,\n RemittanceNumberField,\n PayPeriodMaximumField,\n AmountField,\n PaymentPeriodField,\n type CountyEntry,\n type StateFieldEntry,\n} from './fields'\nimport { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\n\nconst PAYMENT_PERIOD_OPTIONS = [\n { value: PaymentPeriod.EveryWeek, label: PaymentPeriod.EveryWeek },\n { value: PaymentPeriod.EveryOtherWeek, label: PaymentPeriod.EveryOtherWeek },\n { value: PaymentPeriod.TwicePerMonth, label: PaymentPeriod.TwicePerMonth },\n { value: PaymentPeriod.Monthly, label: PaymentPeriod.Monthly },\n] as const\n\nconst PAYMENT_PERIOD_ENTRIES = [\n PaymentPeriod.EveryWeek,\n PaymentPeriod.EveryOtherWeek,\n PaymentPeriod.TwicePerMonth,\n PaymentPeriod.Monthly,\n] as const\n\nexport interface UseChildSupportGarnishmentFormProps {\n employeeId: string\n /**\n * When set, loads that garnishment via the list query and updates it (PUT).\n * When omitted, the form is in create mode (POST).\n */\n garnishmentId?: string\n defaultValues?: Partial<ChildSupportGarnishmentFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface ChildSupportGarnishmentFormFields {\n State: typeof StateField\n /** Only available when the selected agency has more than one fips code, or the\n * sole code is county-scoped (not an \"all counties\" auto-pick). */\n FipsCode: typeof FipsCodeField | undefined\n /** Only available when the selected agency requires `case_number`. */\n CaseNumber: typeof CaseNumberField | undefined\n /** Only available when the selected agency requires `order_number`. */\n OrderNumber: typeof OrderNumberField | undefined\n /** Only available when the selected agency requires `remittance_number`. */\n RemittanceNumber: typeof RemittanceNumberField | undefined\n PayPeriodMaximum: typeof PayPeriodMaximumField\n Amount: typeof AmountField\n PaymentPeriod: typeof PaymentPeriodField\n}\n\nexport interface UseChildSupportGarnishmentFormReady extends BaseFormHookReady<\n FieldsMetadata,\n ChildSupportGarnishmentFormData,\n ChildSupportGarnishmentFormFields\n> {\n data: {\n /** Agencies offered as `State` options; raw entries the consumer can use\n * with `getOptionLabel` for translated names. */\n agencies: StateFieldEntry[]\n /** Counties for the currently selected state. Empty array when no state\n * is selected. */\n counties: CountyEntry[]\n /** The garnishment loaded for update; `null` in create mode. */\n deduction: Garnishment | null\n }\n status: {\n isPending: boolean\n mode: 'create' | 'update'\n /** The agency record matching the currently selected `state`. */\n selectedAgency: Agencies | null\n /** Mirrors `selectedAgency.manualPaymentRequired`; convenient for showing\n * a warning alert. */\n isManualPaymentRequired: boolean\n /** Which `required_attributes` keys the selected agency declares. */\n requiredAttrKeys: ReadonlySet<SupportedRequiredAttrKey>\n }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<Garnishment> | undefined>\n }\n}\n\nexport type UseChildSupportGarnishmentFormResult =\n | HookLoadingResult\n | UseChildSupportGarnishmentFormReady\n\nexport function useChildSupportGarnishmentForm({\n employeeId,\n garnishmentId,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseChildSupportGarnishmentFormProps): UseChildSupportGarnishmentFormResult {\n const isCreateMode = !garnishmentId\n const schemaMode = isCreateMode ? 'create' : 'update'\n\n // Agencies + their required-attributes / fips codes come from a single GET.\n const agencyDataQuery = useGarnishmentsGetChildSupportData({})\n const agencyList = useMemo(\n () => agencyDataQuery.data?.childSupportData?.agencies ?? [],\n [agencyDataQuery.data],\n )\n\n // Update mode reads the row from the list endpoint (the garnishments API\n // has no single-row GET).\n const garnishmentsListQuery = useGarnishmentsList({ employeeId }, { enabled: !isCreateMode })\n const fetchedDeduction = useMemo(() => {\n if (isCreateMode) return null\n return garnishmentsListQuery.data?.garnishments?.find(g => g.uuid === garnishmentId) ?? null\n }, [isCreateMode, garnishmentId, garnishmentsListQuery.data])\n\n const resolvedDefaults: ChildSupportGarnishmentFormData = useMemo(\n () => ({\n state: fetchedDeduction?.childSupport?.state ?? partnerDefaults?.state ?? '',\n fipsCode: fetchedDeduction?.childSupport?.fipsCode ?? partnerDefaults?.fipsCode ?? '',\n caseNumber: fetchedDeduction?.childSupport?.caseNumber ?? partnerDefaults?.caseNumber ?? '',\n orderNumber:\n fetchedDeduction?.childSupport?.orderNumber ?? partnerDefaults?.orderNumber ?? '',\n remittanceNumber:\n fetchedDeduction?.childSupport?.remittanceNumber ?? partnerDefaults?.remittanceNumber ?? '',\n amount: fetchedDeduction?.amount\n ? Number(fetchedDeduction.amount)\n : (partnerDefaults?.amount ?? 0),\n payPeriodMaximum: fetchedDeduction?.payPeriodMaximum\n ? Number(fetchedDeduction.payPeriodMaximum)\n : (partnerDefaults?.payPeriodMaximum ?? 0),\n paymentPeriod:\n (fetchedDeduction?.childSupport?.paymentPeriod as PaymentPeriod | undefined) ??\n partnerDefaults?.paymentPeriod ??\n PaymentPeriod.Monthly,\n }),\n [fetchedDeduction, partnerDefaults],\n )\n\n // The schema is built statically here. The agency-attribute fields\n // (`caseNumber`, `orderNumber`, `remittanceNumber`) are kept optional in the\n // schema and surfaced as `isRequired` at the metadata level when the\n // selected agency declares them in `required_attributes`. This matches the\n // legacy ChildSupportForm, which also used a static schema and relied on the\n // API to enforce missing-attribute validation. The hook's `requiredAttrKeys`\n // status flag tells consumers which UI fields to mark required.\n const [schema, metadataConfig] = useMemo(\n () => createChildSupportGarnishmentFormSchema({ mode: schemaMode }),\n [schemaMode],\n )\n\n const formMethods = useForm<\n ChildSupportGarnishmentFormData,\n unknown,\n ChildSupportGarnishmentFormOutputs\n >({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const liveWatchedState = useWatch({ control: formMethods.control, name: 'state' })\n const liveSelectedAgency = useMemo(\n () => agencyList.find(a => a.state === liveWatchedState) ?? null,\n [agencyList, liveWatchedState],\n )\n\n // The agency-attribute fields stay in sync with the chosen state: when the\n // user switches states, the previous attribute values would otherwise carry\n // over and potentially submit alongside the wrong agency. The ref tracks\n // the previous value so the wipe only fires on user-driven transitions —\n // NOT on the initial sync when an existing garnishment loads (state moves\n // from '' to e.g. 'AK' as a side effect of `values` updating, which would\n // otherwise clobber the loaded case/order/remittance values).\n const previousWatchedStateRef = useRef<string | null>(null)\n useEffect(() => {\n const previous = previousWatchedStateRef.current\n previousWatchedStateRef.current = liveWatchedState\n // First render (no previous value) → skip the wipe.\n if (previous === null) return\n // Server-side load: previous was '' (initial defaults before the row\n // arrived), now it's the loaded state. That's a sync, not a user toggle.\n if (previous === '') return\n if (previous === liveWatchedState) return\n formMethods.setValue('caseNumber', '')\n formMethods.setValue('orderNumber', '')\n formMethods.setValue('remittanceNumber', '')\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [liveWatchedState])\n\n // When the selected agency has a single \"all counties\" fips code, auto-fill\n // the field so the consumer doesn't have to render the county select.\n const fipsCodes = liveSelectedAgency?.fipsCodes ?? []\n const singleAllCountiesFipsCode =\n fipsCodes.length === 1 && !fipsCodes[0]?.county?.length ? (fipsCodes[0]?.code ?? null) : null\n useEffect(() => {\n if (singleAllCountiesFipsCode) {\n formMethods.setValue('fipsCode', singleAllCountiesFipsCode)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [singleAllCountiesFipsCode])\n\n const createGarnishmentMutation = useGarnishmentsCreateMutation()\n const updateGarnishmentMutation = useGarnishmentsUpdateMutation()\n const isPending = createGarnishmentMutation.isPending || updateGarnishmentMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('ChildSupportGarnishmentForm')\n\n const errorHandling = composeErrorHandler(\n isCreateMode ? [agencyDataQuery] : [agencyDataQuery, garnishmentsListQuery],\n { submitError, setSubmitError },\n )\n\n // ── Derived data exposed on the ready branch ─────────────────────────\n\n const agencies: StateFieldEntry[] = useMemo(\n () =>\n agencyList.map(a => ({\n state: a.state ?? '',\n name: a.name ?? a.state ?? '',\n manualPaymentRequired: a.manualPaymentRequired ?? false,\n })),\n [agencyList],\n )\n\n const counties: CountyEntry[] = useMemo(\n () =>\n (liveSelectedAgency?.fipsCodes ?? [])\n .filter(f => typeof f.code === 'string')\n .map(f => ({ fipsCode: f.code as string, county: f.county ?? null })),\n [liveSelectedAgency],\n )\n\n const requiredAttrKeys = useMemo(\n () => getRequiredAttrKeys(liveSelectedAgency),\n [liveSelectedAgency],\n )\n\n const hasSelectableCounties =\n counties.length > 1 || (counties.length === 1 && singleAllCountiesFipsCode == null)\n\n // ── Metadata + field-options wiring ─────────────────────────────────\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const stateOptions = agencies.map(a => ({ value: a.state, label: a.name }))\n const countyOptions = counties.map(c => ({\n value: c.fipsCode,\n label: c.county ?? c.fipsCode,\n }))\n\n const fieldsMetadata = {\n state: withOptions(baseMetadata.state, stateOptions, agencies),\n fipsCode: withOptions(baseMetadata.fipsCode, countyOptions, counties),\n caseNumber: baseMetadata.caseNumber,\n orderNumber: baseMetadata.orderNumber,\n remittanceNumber: baseMetadata.remittanceNumber,\n payPeriodMaximum: baseMetadata.payPeriodMaximum,\n amount: baseMetadata.amount,\n paymentPeriod: withOptions(\n baseMetadata.paymentPeriod,\n [...PAYMENT_PERIOD_OPTIONS],\n [...PAYMENT_PERIOD_ENTRIES],\n ),\n }\n\n // ── Submit ───────────────────────────────────────────────────────────\n\n const onSubmit = async (): Promise<HookSubmitResult<Garnishment> | undefined> => {\n let submitResult: HookSubmitResult<Garnishment> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: ChildSupportGarnishmentFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const childSupport = {\n state: payload.state,\n paymentPeriod: payload.paymentPeriod,\n fipsCode: payload.fipsCode,\n // Empty strings collapse to null so the API persists \"no value\n // declared\" rather than an empty case number.\n caseNumber: payload.caseNumber || null,\n orderNumber: payload.orderNumber || null,\n remittanceNumber: payload.remittanceNumber || null,\n }\n\n const description = `Child Support - ${childSupport.caseNumber ?? ''}`\n const amountStr = String(payload.amount)\n const payPeriodMaximumStr =\n payload.payPeriodMaximum > 0 ? String(payload.payPeriodMaximum) : null\n\n const requestBody = {\n active: true,\n amount: amountStr,\n description,\n courtOrdered: true,\n garnishmentType: 'child_support' as GarnishmentType,\n times: null,\n deductAsPercentage: true,\n payPeriodMaximum: payPeriodMaximumStr,\n recurring: true,\n childSupport,\n }\n\n let updated: Garnishment | undefined\n\n if (isCreateMode) {\n const result = await createGarnishmentMutation.mutateAsync({\n request: { employeeId, garnishmentRequest: requestBody },\n })\n updated = result.garnishment\n } else {\n if (!fetchedDeduction) {\n throw new SDKInternalError(\n 'Cannot update child-support deduction: no matching garnishment on file',\n )\n }\n const result = await updateGarnishmentMutation.mutateAsync({\n request: {\n garnishmentId: fetchedDeduction.uuid,\n updateGarnishmentRequest: {\n ...requestBody,\n version: fetchedDeduction.version as string,\n },\n },\n })\n updated = result.garnishment\n }\n\n if (!updated) {\n throw new SDKInternalError(\n isCreateMode\n ? 'Child-support deduction creation failed'\n : 'Child-support deduction update failed',\n )\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updated,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (agencyDataQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n if (!isCreateMode && garnishmentsListQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n agencies,\n counties,\n deduction: fetchedDeduction,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n selectedAgency: liveSelectedAgency,\n isManualPaymentRequired: liveSelectedAgency?.manualPaymentRequired ?? false,\n requiredAttrKeys,\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n State: StateField,\n FipsCode: hasSelectableCounties ? FipsCodeField : undefined,\n CaseNumber: requiredAttrKeys.has('case_number') ? CaseNumberField : undefined,\n OrderNumber: requiredAttrKeys.has('order_number') ? OrderNumberField : undefined,\n RemittanceNumber: requiredAttrKeys.has('remittance_number')\n ? RemittanceNumberField\n : undefined,\n PayPeriodMaximum: PayPeriodMaximumField,\n Amount: AmountField,\n PaymentPeriod: PaymentPeriodField,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type ChildSupportGarnishmentFormFieldsMetadata =\n UseChildSupportGarnishmentFormReady['form']['fieldsMetadata']\nexport type ChildSupportGarnishmentFormFieldsType =\n UseChildSupportGarnishmentFormReady['form']['Fields']\n"],"names":["PAYMENT_PERIOD_OPTIONS","PaymentPeriod","PAYMENT_PERIOD_ENTRIES","useChildSupportGarnishmentForm","employeeId","garnishmentId","partnerDefaults","validationMode","shouldFocusError","isCreateMode","schemaMode","agencyDataQuery","useGarnishmentsGetChildSupportData","agencyList","useMemo","garnishmentsListQuery","useGarnishmentsList","fetchedDeduction","g","resolvedDefaults","schema","metadataConfig","createChildSupportGarnishmentFormSchema","formMethods","useForm","zodResolver","liveWatchedState","useWatch","liveSelectedAgency","a","previousWatchedStateRef","useRef","useEffect","previous","fipsCodes","singleAllCountiesFipsCode","createGarnishmentMutation","useGarnishmentsCreateMutation","updateGarnishmentMutation","useGarnishmentsUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","agencies","counties","f","requiredAttrKeys","getRequiredAttrKeys","hasSelectableCounties","baseMetadata","useDeriveFieldsMetadata","stateOptions","countyOptions","c","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","childSupport","description","amountStr","payPeriodMaximumStr","requestBody","updated","SDKInternalError","hookFormInternals","useHookFormInternals","StateField","FipsCodeField","CaseNumberField","OrderNumberField","RemittanceNumberField","PayPeriodMaximumField","AmountField","PaymentPeriodField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;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OAAO6B;AAAA,QACP,UAAUtB,IAAwBuB,KAAgB;AAAA,QAClD,YAAYzB,EAAiB,IAAI,aAAa,IAAI0B,KAAkB;AAAA,QACpE,aAAa1B,EAAiB,IAAI,cAAc,IAAI2B,KAAmB;AAAA,QACvE,kBAAkB3B,EAAiB,IAAI,mBAAmB,IACtD4B,KACA;AAAA,QACJ,kBAAkBC;AAAA,QAClB,QAAQC;AAAA,QACR,eAAeC;AAAA,MAAA;AAAA,MAEjB,gBAAAvB;AAAA,MACA,mBAAAc;AAAA,MACA,yBAAyBU,GAA8B3D,GAAaH,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useChildSupportGarnishmentForm.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/useChildSupportGarnishmentForm.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport {\n type Garnishment,\n type GarnishmentType,\n} from '@gusto/embedded-api/models/components/garnishment'\nimport type { Agencies } from '@gusto/embedded-api/models/components/childsupportdata'\nimport { PaymentPeriod } from '@gusto/embedded-api/models/components/garnishmentchildsupport'\nimport { useGarnishmentsCreateMutation } from '@gusto/embedded-api/react-query/garnishmentsCreate'\nimport { useGarnishmentsUpdateMutation } from '@gusto/embedded-api/react-query/garnishmentsUpdate'\nimport { useGarnishmentsList } from '@gusto/embedded-api/react-query/garnishmentsList'\nimport { useGarnishmentsGetChildSupportData } from '@gusto/embedded-api/react-query/garnishmentsGetChildSupportData'\nimport {\n createChildSupportGarnishmentFormSchema,\n getRequiredAttrKeys,\n type ChildSupportGarnishmentFormData,\n type ChildSupportGarnishmentFormOutputs,\n type SupportedRequiredAttrKey,\n} from './childSupportGarnishmentFormSchema'\nimport {\n StateField,\n FipsCodeField,\n CaseNumberField,\n OrderNumberField,\n RemittanceNumberField,\n PayPeriodMaximumField,\n AmountField,\n PaymentPeriodField,\n type CountyEntry,\n type StateFieldEntry,\n} from './fields'\nimport { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\n\nconst PAYMENT_PERIOD_OPTIONS = [\n { value: PaymentPeriod.EveryWeek, label: PaymentPeriod.EveryWeek },\n { value: PaymentPeriod.EveryOtherWeek, label: PaymentPeriod.EveryOtherWeek },\n { value: PaymentPeriod.TwicePerMonth, label: PaymentPeriod.TwicePerMonth },\n { value: PaymentPeriod.Monthly, label: PaymentPeriod.Monthly },\n] as const\n\nconst PAYMENT_PERIOD_ENTRIES = [\n PaymentPeriod.EveryWeek,\n PaymentPeriod.EveryOtherWeek,\n PaymentPeriod.TwicePerMonth,\n PaymentPeriod.Monthly,\n] as const\n\nexport interface UseChildSupportGarnishmentFormProps {\n employeeId: string\n /**\n * When set, loads that garnishment via the list query and updates it (PUT).\n * When omitted, the form is in create mode (POST).\n */\n garnishmentId?: string\n defaultValues?: Partial<ChildSupportGarnishmentFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface ChildSupportGarnishmentFormFields {\n State: typeof StateField\n /** Only available when the selected agency has more than one fips code, or the\n * sole code is county-scoped (not an \"all counties\" auto-pick). */\n FipsCode: typeof FipsCodeField | undefined\n /** Only available when the selected agency requires `case_number`. */\n CaseNumber: typeof CaseNumberField | undefined\n /** Only available when the selected agency requires `order_number`. */\n OrderNumber: typeof OrderNumberField | undefined\n /** Only available when the selected agency requires `remittance_number`. */\n RemittanceNumber: typeof RemittanceNumberField | undefined\n PayPeriodMaximum: typeof PayPeriodMaximumField\n Amount: typeof AmountField\n PaymentPeriod: typeof PaymentPeriodField\n}\n\nexport interface UseChildSupportGarnishmentFormReady extends BaseFormHookReady<\n FieldsMetadata,\n ChildSupportGarnishmentFormData,\n ChildSupportGarnishmentFormFields\n> {\n data: {\n /** Agencies offered as `State` options; raw entries the consumer can use\n * with `getOptionLabel` for translated names. */\n agencies: StateFieldEntry[]\n /** Counties for the currently selected state. Empty array when no state\n * is selected. */\n counties: CountyEntry[]\n /** The garnishment loaded for update; `null` in create mode. */\n deduction: Garnishment | null\n }\n status: {\n isPending: boolean\n mode: 'create' | 'update'\n /** The agency record matching the currently selected `state`. */\n selectedAgency: Agencies | null\n /** Mirrors `selectedAgency.manualPaymentRequired`; convenient for showing\n * a warning alert. */\n isManualPaymentRequired: boolean\n /** Which `required_attributes` keys the selected agency declares. */\n requiredAttrKeys: ReadonlySet<SupportedRequiredAttrKey>\n }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<Garnishment> | undefined>\n }\n}\n\nexport type UseChildSupportGarnishmentFormResult =\n | HookLoadingResult\n | UseChildSupportGarnishmentFormReady\n\nexport function useChildSupportGarnishmentForm({\n employeeId,\n garnishmentId,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseChildSupportGarnishmentFormProps): UseChildSupportGarnishmentFormResult {\n const isCreateMode = !garnishmentId\n const schemaMode = isCreateMode ? 'create' : 'update'\n\n // Agencies + their required-attributes / fips codes come from a single GET.\n const agencyDataQuery = useGarnishmentsGetChildSupportData({})\n const agencyList = useMemo(\n () => agencyDataQuery.data?.childSupportData?.agencies ?? [],\n [agencyDataQuery.data],\n )\n\n // Update mode reads the row from the list endpoint (the garnishments API\n // has no single-row GET).\n const garnishmentsListQuery = useGarnishmentsList({ employeeId }, { enabled: !isCreateMode })\n const fetchedDeduction = useMemo(() => {\n if (isCreateMode) return null\n return garnishmentsListQuery.data?.garnishments?.find(g => g.uuid === garnishmentId) ?? null\n }, [isCreateMode, garnishmentId, garnishmentsListQuery.data])\n\n const resolvedDefaults: ChildSupportGarnishmentFormData = useMemo(\n () => ({\n state: fetchedDeduction?.childSupport?.state ?? partnerDefaults?.state ?? '',\n fipsCode: fetchedDeduction?.childSupport?.fipsCode ?? partnerDefaults?.fipsCode ?? '',\n caseNumber: fetchedDeduction?.childSupport?.caseNumber ?? partnerDefaults?.caseNumber ?? '',\n orderNumber:\n fetchedDeduction?.childSupport?.orderNumber ?? partnerDefaults?.orderNumber ?? '',\n remittanceNumber:\n fetchedDeduction?.childSupport?.remittanceNumber ?? partnerDefaults?.remittanceNumber ?? '',\n amount: fetchedDeduction?.amount\n ? Number(fetchedDeduction.amount)\n : (partnerDefaults?.amount ?? 0),\n payPeriodMaximum: fetchedDeduction?.payPeriodMaximum\n ? Number(fetchedDeduction.payPeriodMaximum)\n : (partnerDefaults?.payPeriodMaximum ?? 0),\n paymentPeriod:\n (fetchedDeduction?.childSupport?.paymentPeriod as PaymentPeriod | undefined) ??\n partnerDefaults?.paymentPeriod ??\n PaymentPeriod.Monthly,\n }),\n [fetchedDeduction, partnerDefaults],\n )\n\n // Pass the full agency list so requiredness for the agency-attribute fields\n // (`caseNumber`, `orderNumber`, `remittanceNumber`) is derived dynamically\n // from the form's `state` value. The schema doesn't need to rebuild when the\n // user changes states — the predicate runs at validation time and via\n // `useDeriveFieldsMetadata` for the (optional) label.\n const [schema, metadataConfig] = useMemo(\n () => createChildSupportGarnishmentFormSchema({ mode: schemaMode, agencyList }),\n [schemaMode, agencyList],\n )\n\n const formMethods = useForm<\n ChildSupportGarnishmentFormData,\n unknown,\n ChildSupportGarnishmentFormOutputs\n >({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n const liveWatchedState = useWatch({ control: formMethods.control, name: 'state' })\n const liveSelectedAgency = useMemo(\n () => agencyList.find(a => a.state === liveWatchedState) ?? null,\n [agencyList, liveWatchedState],\n )\n\n // The agency-attribute fields stay in sync with the chosen state: when the\n // user switches states, the previous attribute values would otherwise carry\n // over and potentially submit alongside the wrong agency. The ref tracks\n // the previous value so the wipe only fires on user-driven transitions —\n // NOT on the initial sync when an existing garnishment loads (state moves\n // from '' to e.g. 'AK' as a side effect of `values` updating, which would\n // otherwise clobber the loaded case/order/remittance values).\n const previousWatchedStateRef = useRef<string | null>(null)\n useEffect(() => {\n const previous = previousWatchedStateRef.current\n previousWatchedStateRef.current = liveWatchedState\n // First render (no previous value) → skip the wipe.\n if (previous === null) return\n // Server-side load: previous was '' (initial defaults before the row\n // arrived), now it's the loaded state. That's a sync, not a user toggle.\n if (previous === '') return\n if (previous === liveWatchedState) return\n formMethods.setValue('caseNumber', '')\n formMethods.setValue('orderNumber', '')\n formMethods.setValue('remittanceNumber', '')\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [liveWatchedState])\n\n // When the selected agency has a single \"all counties\" fips code, auto-fill\n // the field so the consumer doesn't have to render the county select.\n const fipsCodes = liveSelectedAgency?.fipsCodes ?? []\n const singleAllCountiesFipsCode =\n fipsCodes.length === 1 && !fipsCodes[0]?.county?.length ? (fipsCodes[0]?.code ?? null) : null\n useEffect(() => {\n if (singleAllCountiesFipsCode) {\n formMethods.setValue('fipsCode', singleAllCountiesFipsCode)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [singleAllCountiesFipsCode])\n\n const createGarnishmentMutation = useGarnishmentsCreateMutation()\n const updateGarnishmentMutation = useGarnishmentsUpdateMutation()\n const isPending = createGarnishmentMutation.isPending || updateGarnishmentMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('ChildSupportGarnishmentForm')\n\n const errorHandling = composeErrorHandler(\n isCreateMode ? [agencyDataQuery] : [agencyDataQuery, garnishmentsListQuery],\n { submitError, setSubmitError },\n )\n\n // ── Derived data exposed on the ready branch ─────────────────────────\n\n const agencies: StateFieldEntry[] = useMemo(\n () =>\n agencyList.map(a => ({\n state: a.state ?? '',\n name: a.name ?? a.state ?? '',\n manualPaymentRequired: a.manualPaymentRequired ?? false,\n })),\n [agencyList],\n )\n\n const counties: CountyEntry[] = useMemo(\n () =>\n (liveSelectedAgency?.fipsCodes ?? [])\n .filter(f => typeof f.code === 'string')\n .map(f => ({ fipsCode: f.code as string, county: f.county ?? null })),\n [liveSelectedAgency],\n )\n\n const requiredAttrKeys = useMemo(\n () => getRequiredAttrKeys(liveSelectedAgency),\n [liveSelectedAgency],\n )\n\n const hasSelectableCounties =\n counties.length > 1 || (counties.length === 1 && singleAllCountiesFipsCode == null)\n\n // ── Metadata + field-options wiring ─────────────────────────────────\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const stateOptions = agencies.map(a => ({ value: a.state, label: a.name }))\n const countyOptions = counties.map(c => ({\n value: c.fipsCode,\n label: c.county ?? c.fipsCode,\n }))\n\n const fieldsMetadata = {\n state: withOptions(baseMetadata.state, stateOptions, agencies),\n fipsCode: withOptions(baseMetadata.fipsCode, countyOptions, counties),\n caseNumber: baseMetadata.caseNumber,\n orderNumber: baseMetadata.orderNumber,\n remittanceNumber: baseMetadata.remittanceNumber,\n payPeriodMaximum: baseMetadata.payPeriodMaximum,\n amount: baseMetadata.amount,\n paymentPeriod: withOptions(\n baseMetadata.paymentPeriod,\n [...PAYMENT_PERIOD_OPTIONS],\n [...PAYMENT_PERIOD_ENTRIES],\n ),\n }\n\n // ── Submit ───────────────────────────────────────────────────────────\n\n const onSubmit = async (): Promise<HookSubmitResult<Garnishment> | undefined> => {\n let submitResult: HookSubmitResult<Garnishment> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: ChildSupportGarnishmentFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n const childSupport = {\n state: payload.state,\n paymentPeriod: payload.paymentPeriod,\n fipsCode: payload.fipsCode,\n // Empty strings collapse to null so the API persists \"no value\n // declared\" rather than an empty case number.\n caseNumber: payload.caseNumber || null,\n orderNumber: payload.orderNumber || null,\n remittanceNumber: payload.remittanceNumber || null,\n }\n\n const description = `Child Support - ${childSupport.caseNumber ?? ''}`\n const amountStr = String(payload.amount)\n const payPeriodMaximumStr =\n payload.payPeriodMaximum > 0 ? String(payload.payPeriodMaximum) : null\n\n const requestBody = {\n active: true,\n amount: amountStr,\n description,\n courtOrdered: true,\n garnishmentType: 'child_support' as GarnishmentType,\n times: null,\n deductAsPercentage: true,\n payPeriodMaximum: payPeriodMaximumStr,\n recurring: true,\n childSupport,\n }\n\n let updated: Garnishment | undefined\n\n if (isCreateMode) {\n const result = await createGarnishmentMutation.mutateAsync({\n request: { employeeId, garnishmentRequest: requestBody },\n })\n updated = result.garnishment\n } else {\n if (!fetchedDeduction) {\n throw new SDKInternalError(\n 'Cannot update child-support deduction: no matching garnishment on file',\n )\n }\n const result = await updateGarnishmentMutation.mutateAsync({\n request: {\n garnishmentId: fetchedDeduction.uuid,\n updateGarnishmentRequest: {\n ...requestBody,\n version: fetchedDeduction.version as string,\n },\n },\n })\n updated = result.garnishment\n }\n\n if (!updated) {\n throw new SDKInternalError(\n isCreateMode\n ? 'Child-support deduction creation failed'\n : 'Child-support deduction update failed',\n )\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updated,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (agencyDataQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n if (!isCreateMode && garnishmentsListQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n agencies,\n counties,\n deduction: fetchedDeduction,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n selectedAgency: liveSelectedAgency,\n isManualPaymentRequired: liveSelectedAgency?.manualPaymentRequired ?? false,\n requiredAttrKeys,\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n State: StateField,\n FipsCode: hasSelectableCounties ? FipsCodeField : undefined,\n CaseNumber: requiredAttrKeys.has('case_number') ? CaseNumberField : undefined,\n OrderNumber: requiredAttrKeys.has('order_number') ? OrderNumberField : undefined,\n RemittanceNumber: requiredAttrKeys.has('remittance_number')\n ? RemittanceNumberField\n : undefined,\n PayPeriodMaximum: PayPeriodMaximumField,\n Amount: AmountField,\n PaymentPeriod: PaymentPeriodField,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type ChildSupportGarnishmentFormFieldsMetadata =\n UseChildSupportGarnishmentFormReady['form']['fieldsMetadata']\nexport type ChildSupportGarnishmentFormFieldsType =\n UseChildSupportGarnishmentFormReady['form']['Fields']\n"],"names":["PAYMENT_PERIOD_OPTIONS","PaymentPeriod","PAYMENT_PERIOD_ENTRIES","useChildSupportGarnishmentForm","employeeId","garnishmentId","partnerDefaults","validationMode","shouldFocusError","isCreateMode","schemaMode","agencyDataQuery","useGarnishmentsGetChildSupportData","agencyList","useMemo","garnishmentsListQuery","useGarnishmentsList","fetchedDeduction","g","resolvedDefaults","schema","metadataConfig","createChildSupportGarnishmentFormSchema","formMethods","useForm","zodResolver","liveWatchedState","useWatch","liveSelectedAgency","a","previousWatchedStateRef","useRef","useEffect","previous","fipsCodes","singleAllCountiesFipsCode","createGarnishmentMutation","useGarnishmentsCreateMutation","updateGarnishmentMutation","useGarnishmentsUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","agencies","counties","f","requiredAttrKeys","getRequiredAttrKeys","hasSelectableCounties","baseMetadata","useDeriveFieldsMetadata","stateOptions","countyOptions","c","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","childSupport","description","amountStr","payPeriodMaximumStr","requestBody","updated","SDKInternalError","hookFormInternals","useHookFormInternals","StateField","FipsCodeField","CaseNumberField","OrderNumberField","RemittanceNumberField","PayPeriodMaximumField","AmountField","PaymentPeriodField","createGetFormSubmissionValues"],"mappings":";;;;;;;;;;;;;;;;;AA+CA,MAAMA,KAAyB;AAAA,EAC7B,EAAE,OAAOC,EAAc,WAAW,OAAOA,EAAc,UAAA;AAAA,EACvD,EAAE,OAAOA,EAAc,gBAAgB,OAAOA,EAAc,eAAA;AAAA,EAC5D,EAAE,OAAOA,EAAc,eAAe,OAAOA,EAAc,cAAA;AAAA,EAC3D,EAAE,OAAOA,EAAc,SAAS,OAAOA,EAAc,QAAA;AACvD,GAEMC,KAAyB;AAAA,EAC7BD,EAAc;AAAA,EACdA,EAAc;AAAA,EACdA,EAAc;AAAA,EACdA,EAAc;AAChB;AAiEO,SAASE,GAA+B;AAAA,EAC7C,YAAAC;AAAA,EACA,eAAAC;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AACrB,GAA8E;AAC5E,QAAMC,IAAe,CAACJ,GAChBK,IAAaD,IAAe,WAAW,UAGvCE,IAAkBC,GAAmC,EAAE,GACvDC,IAAaC;AAAA,IACjB,MAAMH,EAAgB,MAAM,kBAAkB,YAAY,CAAA;AAAA,IAC1D,CAACA,EAAgB,IAAI;AAAA,EAAA,GAKjBI,IAAwBC,GAAoB,EAAE,YAAAZ,EAAA,GAAc,EAAE,SAAS,CAACK,GAAc,GACtFQ,IAAmBH,EAAQ,MAC3BL,IAAqB,OAClBM,EAAsB,MAAM,cAAc,KAAK,OAAKG,EAAE,SAASb,CAAa,KAAK,MACvF,CAACI,GAAcJ,GAAeU,EAAsB,IAAI,CAAC,GAEtDI,IAAoDL;AAAA,IACxD,OAAO;AAAA,MACL,OAAOG,GAAkB,cAAc,SAASX,GAAiB,SAAS;AAAA,MAC1E,UAAUW,GAAkB,cA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,MAAM/B,IAAe,WAAW;AAAA,MAChC,gBAAgBmB;AAAA,MAChB,yBAAyBA,GAAoB,yBAAyB;AAAA,MACtE,kBAAAsB;AAAA,IAAA;AAAA,IAEF,SAAS,EAAE,UAAAU,EAAA;AAAA,IACX,eAAAf;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,OAAO6B;AAAA,QACP,UAAUtB,IAAwBuB,KAAgB;AAAA,QAClD,YAAYzB,EAAiB,IAAI,aAAa,IAAI0B,KAAkB;AAAA,QACpE,aAAa1B,EAAiB,IAAI,cAAc,IAAI2B,KAAmB;AAAA,QACvE,kBAAkB3B,EAAiB,IAAI,mBAAmB,IACtD4B,KACA;AAAA,QACJ,kBAAkBC;AAAA,QAClB,QAAQC;AAAA,QACR,eAAeC;AAAA,MAAA;AAAA,MAEjB,gBAAAvB;AAAA,MACA,mBAAAc;AAAA,MACA,yBAAyBU,GAA8B3D,GAAaH,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { SelectHookField as i } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
2
|
+
import { SelectHookField as o } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
4
3
|
import { NumberInputHookField as t } from "../../../../../partner-hook-utils/form/fields/NumberInputHookField.js";
|
|
5
4
|
import { RadioGroupHookField as r } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
5
|
+
import { TextInputHookField as i } from "../../../../../partner-hook-utils/form/fields/TextInputHookField.js";
|
|
6
6
|
function l(n) {
|
|
7
|
-
return /* @__PURE__ */ e(
|
|
7
|
+
return /* @__PURE__ */ e(i, { ...n, name: "description" });
|
|
8
8
|
}
|
|
9
9
|
function p(n) {
|
|
10
10
|
return /* @__PURE__ */ e(r, { ...n, name: "recurring" });
|
|
@@ -22,7 +22,7 @@ function A(n) {
|
|
|
22
22
|
return /* @__PURE__ */ e(t, { ...n, name: "annualMaximum" });
|
|
23
23
|
}
|
|
24
24
|
function g(n) {
|
|
25
|
-
return /* @__PURE__ */ e(
|
|
25
|
+
return /* @__PURE__ */ e(o, { ...n, name: "garnishmentType" });
|
|
26
26
|
}
|
|
27
27
|
export {
|
|
28
28
|
F as AmountField,
|
|
@@ -12,9 +12,9 @@ export interface UseDeductionFormProps {
|
|
|
12
12
|
*/
|
|
13
13
|
garnishmentId?: string;
|
|
14
14
|
/**
|
|
15
|
-
* Court-ordered deductions are stored as garnishments with `courtOrdered:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Court-ordered deductions are stored as garnishments with `courtOrdered: true`
|
|
16
|
+
* and require a `garnishmentType` (Federal Tax Lien, Student Loan, etc.).
|
|
17
|
+
* When `false`, the form is for a "custom" post-tax deduction —
|
|
18
18
|
* `garnishmentType` is excluded from the schema and submit payload.
|
|
19
19
|
*
|
|
20
20
|
* Note: this hook does NOT handle `garnishmentType: 'child_support'`. Use
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeductionForm.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.tsx"],"sourcesContent":["import { useMemo } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport {\n type Garnishment,\n type GarnishmentType,\n} from '@gusto/embedded-api/models/components/garnishment'\nimport { useGarnishmentsCreateMutation } from '@gusto/embedded-api/react-query/garnishmentsCreate'\nimport { useGarnishmentsUpdateMutation } from '@gusto/embedded-api/react-query/garnishmentsUpdate'\nimport { useGarnishmentsList } from '@gusto/embedded-api/react-query/garnishmentsList'\nimport {\n createDeductionFormSchema,\n type DeductionFormData,\n type DeductionFormOutputs,\n type DeductionFormOptionalFieldsToRequire,\n} from './deductionFormSchema'\nimport {\n DescriptionField,\n RecurringField,\n DeductAsPercentageField,\n AmountField,\n TotalAmountField,\n AnnualMaximumField,\n GarnishmentTypeField,\n} from './fields'\nimport { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\n\nexport type { DeductionFormOptionalFieldsToRequire } from './deductionFormSchema'\n\n// GarnishmentType is a runtime enum; the schema gates which values are valid.\n// The hook's `withOptions` entries below carry the raw enum values so the\n// consumer can supply translated labels via `getOptionLabel` on the field.\n//\n// `'child_support'` is intentionally omitted — child-support garnishments\n// require agency-keyed required attributes (case number, order number,\n// remittance number, county) that this hook doesn't model. Use\n// `useChildSupportGarnishmentForm` for those.\nconst GARNISHMENT_TYPES: readonly GarnishmentType[] = [\n 'federal_tax_lien',\n 'state_tax_lien',\n 'student_loan',\n 'creditor_garnishment',\n 'federal_loan',\n 'other_garnishment',\n] as const\n\nexport interface UseDeductionFormProps {\n employeeId: string\n /**\n * When set, loads that garnishment via the list query and updates it (PUT).\n * When omitted, the form is in create mode (POST).\n */\n garnishmentId?: string\n /**\n * Court-ordered deductions are stored as garnishments with `courtOrdered:\n * true` and require a `garnishmentType` (Federal Tax Lien, Student Loan,\n * etc.). When `false`, the form is for a \"custom\" post-tax deduction —\n * `garnishmentType` is excluded from the schema and submit payload.\n *\n * Note: this hook does NOT handle `garnishmentType: 'child_support'`. Use\n * `useChildSupportGarnishmentForm` for child-support agency-keyed payloads.\n */\n courtOrdered: boolean\n optionalFieldsToRequire?: DeductionFormOptionalFieldsToRequire\n defaultValues?: Partial<DeductionFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface DeductionFormFields {\n Description: typeof DescriptionField\n Recurring: typeof RecurringField\n DeductAsPercentage: typeof DeductAsPercentageField\n Amount: typeof AmountField\n /** Only available when `status.isRecurring` is true. */\n TotalAmount: typeof TotalAmountField | undefined\n /** Only available when `status.isRecurring` is true. */\n AnnualMaximum: typeof AnnualMaximumField | undefined\n /** Only available when `courtOrdered: true`. */\n GarnishmentType: typeof GarnishmentTypeField | undefined\n}\n\nexport interface UseDeductionFormReady extends BaseFormHookReady<\n FieldsMetadata,\n DeductionFormData,\n DeductionFormFields\n> {\n data: {\n /** The garnishment loaded for update; `null` in create mode. */\n deduction: Garnishment | null\n }\n status: {\n isPending: boolean\n mode: 'create' | 'update'\n /**\n * Mirrors the watched `recurring` value. Cap fields (`TotalAmount`,\n * `AnnualMaximum`) are only included on `Fields` when this is true — the\n * consumer can render them unconditionally and the gating happens in the\n * hook.\n */\n isRecurring: boolean\n }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<Garnishment> | undefined>\n }\n}\n\nexport type UseDeductionFormResult = HookLoadingResult | UseDeductionFormReady\n\nexport function useDeductionForm({\n employeeId,\n garnishmentId,\n courtOrdered,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseDeductionFormProps): UseDeductionFormResult {\n const isCreateMode = !garnishmentId\n const schemaMode = isCreateMode ? 'create' : 'update'\n\n // The garnishments API has no single-row GET — the list endpoint is the only\n // way to retrieve an existing garnishment. We use the (non-suspense) list\n // query and pick the matching row by uuid.\n const garnishmentsListQuery = useGarnishmentsListMutationLikeLoader({\n employeeId,\n enabled: !isCreateMode,\n })\n\n const fetchedDeduction = useMemo(() => {\n if (isCreateMode) return null\n return garnishmentsListQuery.data?.find(g => g.uuid === garnishmentId) ?? null\n }, [isCreateMode, garnishmentId, garnishmentsListQuery.data])\n\n const [schema, metadataConfig] = useMemo(\n () =>\n createDeductionFormSchema({\n mode: schemaMode,\n courtOrdered,\n optionalFieldsToRequire,\n }),\n [schemaMode, courtOrdered, optionalFieldsToRequire],\n )\n\n const resolvedDefaults: DeductionFormData = useMemo(\n () => ({\n description: fetchedDeduction?.description ?? partnerDefaults?.description ?? '',\n recurring: fetchedDeduction?.recurring ?? partnerDefaults?.recurring ?? true,\n deductAsPercentage:\n fetchedDeduction?.deductAsPercentage ?? partnerDefaults?.deductAsPercentage ?? true,\n amount: fetchedDeduction?.amount\n ? Number(fetchedDeduction.amount)\n : (partnerDefaults?.amount ?? 0),\n // Caps stay as numbers in the form (0 means \"no cap\"); the hook drops\n // them to null on the wire in onSubmit.\n totalAmount: fetchedDeduction?.totalAmount\n ? Number(fetchedDeduction.totalAmount)\n : (partnerDefaults?.totalAmount ?? 0),\n annualMaximum: fetchedDeduction?.annualMaximum\n ? Number(fetchedDeduction.annualMaximum)\n : (partnerDefaults?.annualMaximum ?? 0),\n garnishmentType:\n fetchedDeduction?.garnishmentType ??\n partnerDefaults?.garnishmentType ??\n // First non-child-support type — partners typically pick via the\n // GarnishmentType select before saving.\n 'federal_tax_lien',\n }),\n [fetchedDeduction, partnerDefaults],\n )\n\n const formMethods = useForm<DeductionFormData, unknown, DeductionFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n // The cap fields only appear when the deduction is recurring. Watching here\n // (inside the hook) keeps the consumer from having to reach into\n // hookFormInternals — the conditional Fields below flip to `undefined`.\n const watchedRecurring = useWatch({ control: formMethods.control, name: 'recurring' })\n const isRecurring = watchedRecurring\n\n const createGarnishmentMutation = useGarnishmentsCreateMutation()\n const updateGarnishmentMutation = useGarnishmentsUpdateMutation()\n const isPending = createGarnishmentMutation.isPending || updateGarnishmentMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('DeductionForm')\n\n const queriesForErrors = !isCreateMode ? [garnishmentsListQuery] : []\n const errorHandling = composeErrorHandler(queriesForErrors, { submitError, setSubmitError })\n\n const garnishmentTypeOptions = GARNISHMENT_TYPES.map(value => ({ value, label: value }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n description: baseMetadata.description,\n recurring: withOptions<boolean>(\n baseMetadata.recurring,\n [\n { value: 'true', label: 'true' },\n { value: 'false', label: 'false' },\n ],\n [true, false],\n ),\n deductAsPercentage: withOptions<boolean>(\n baseMetadata.deductAsPercentage,\n [\n { value: 'true', label: 'true' },\n { value: 'false', label: 'false' },\n ],\n [true, false],\n ),\n amount: baseMetadata.amount,\n totalAmount: baseMetadata.totalAmount,\n annualMaximum: baseMetadata.annualMaximum,\n garnishmentType: courtOrdered\n ? withOptions(baseMetadata.garnishmentType, garnishmentTypeOptions, GARNISHMENT_TYPES)\n : baseMetadata.garnishmentType,\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<Garnishment> | undefined> => {\n let submitResult: HookSubmitResult<Garnishment> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: DeductionFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n // The API's `times` column is \"number of remaining occurrences\" —\n // for one-time deductions we set it to 1, for recurring we null it\n // out. Matches the legacy GarnishmentForm/CustomDeductionForm.\n const times = payload.recurring ? null : 1\n // Wire conversions: amount is always a string; the optional caps\n // collapse to undefined when the partner left them at zero.\n const amountStr = String(payload.amount)\n const totalAmountStr = payload.totalAmount > 0 ? String(payload.totalAmount) : undefined\n const annualMaximumStr =\n payload.annualMaximum > 0 ? String(payload.annualMaximum) : undefined\n\n let updated: Garnishment | undefined\n\n if (isCreateMode) {\n const result = await createGarnishmentMutation.mutateAsync({\n request: {\n employeeId,\n garnishmentRequest: {\n active: true,\n description: payload.description,\n recurring: payload.recurring,\n deductAsPercentage: payload.deductAsPercentage,\n amount: amountStr,\n totalAmount: totalAmountStr,\n annualMaximum: annualMaximumStr,\n courtOrdered,\n garnishmentType: courtOrdered ? payload.garnishmentType : undefined,\n times,\n },\n },\n })\n updated = result.garnishment\n } else {\n if (!fetchedDeduction) {\n throw new SDKInternalError(\n 'Cannot update deduction: no matching garnishment on file',\n )\n }\n const result = await updateGarnishmentMutation.mutateAsync({\n request: {\n garnishmentId: fetchedDeduction.uuid,\n updateGarnishmentRequest: {\n version: fetchedDeduction.version as string,\n active: true,\n description: payload.description,\n recurring: payload.recurring,\n deductAsPercentage: payload.deductAsPercentage,\n amount: amountStr,\n totalAmount: totalAmountStr,\n annualMaximum: annualMaximumStr,\n courtOrdered,\n // The API rejects garnishment_type changes on update — only\n // include when court-ordered AND when matching the loaded\n // row's type (no-op pass-through).\n garnishmentType: courtOrdered ? payload.garnishmentType : undefined,\n times,\n },\n },\n })\n updated = result.garnishment\n }\n\n if (!updated) {\n throw new SDKInternalError(\n isCreateMode ? 'Deduction creation failed' : 'Deduction update failed',\n )\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updated,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (!isCreateMode && garnishmentsListQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n deduction: fetchedDeduction,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n isRecurring,\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Description: DescriptionField,\n Recurring: RecurringField,\n DeductAsPercentage: DeductAsPercentageField,\n Amount: AmountField,\n TotalAmount: isRecurring ? TotalAmountField : undefined,\n AnnualMaximum: isRecurring ? AnnualMaximumField : undefined,\n GarnishmentType: courtOrdered ? GarnishmentTypeField : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type DeductionFormFieldsMetadata = UseDeductionFormReady['form']['fieldsMetadata']\nexport type DeductionFormFieldsType = UseDeductionFormReady['form']['Fields']\n\n// ── Internal loader ─────────────────────────────────────────────────────\n//\n// `useGarnishmentsList` is the only way to retrieve an existing garnishment\n// row — the API has no single-row GET. We expose a tiny wrapper that returns\n// the array directly so the hook above can `.find()` by uuid. Skips the fetch\n// entirely in create mode via `enabled: false`.\n\nfunction useGarnishmentsListMutationLikeLoader({\n employeeId,\n enabled,\n}: {\n employeeId: string\n enabled: boolean\n}) {\n const query = useGarnishmentsList({ employeeId }, { enabled })\n return {\n data: query.data?.garnishments,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n }\n}\n"],"names":["GARNISHMENT_TYPES","useDeductionForm","employeeId","garnishmentId","courtOrdered","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","isCreateMode","schemaMode","garnishmentsListQuery","useGarnishmentsListMutationLikeLoader","fetchedDeduction","useMemo","g","schema","metadataConfig","createDeductionFormSchema","resolvedDefaults","formMethods","useForm","zodResolver","isRecurring","useWatch","createGarnishmentMutation","useGarnishmentsCreateMutation","updateGarnishmentMutation","useGarnishmentsUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","garnishmentTypeOptions","value","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","times","amountStr","totalAmountStr","annualMaximumStr","updated","SDKInternalError","hookFormInternals","useHookFormInternals","DescriptionField","RecurringField","DeductAsPercentageField","AmountField","TotalAmountField","AnnualMaximumField","GarnishmentTypeField","createGetFormSubmissionValues","enabled","query","useGarnishmentsList"],"mappings":";;;;;;;;;;;;;;;AAkDA,MAAMA,IAAgD;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAiEO,SAASC,GAAiB;AAAA,EAC/B,YAAAC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,WAAWA,EAAM;AAAA,IACjB,OAAOA,EAAM;AAAA,IACb,SAASA,EAAM;AAAA,EAAA;AAEnB;"}
|
|
1
|
+
{"version":3,"file":"useDeductionForm.js","sources":["../../../../../../src/components/Employee/Deductions/shared/useDeductionForm/useDeductionForm.tsx"],"sourcesContent":["import { useMemo } from 'react'\nimport { useForm, useWatch } from 'react-hook-form'\nimport type { UseFormProps } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport {\n type Garnishment,\n type GarnishmentType,\n} from '@gusto/embedded-api/models/components/garnishment'\nimport { useGarnishmentsCreateMutation } from '@gusto/embedded-api/react-query/garnishmentsCreate'\nimport { useGarnishmentsUpdateMutation } from '@gusto/embedded-api/react-query/garnishmentsUpdate'\nimport { useGarnishmentsList } from '@gusto/embedded-api/react-query/garnishmentsList'\nimport {\n createDeductionFormSchema,\n type DeductionFormData,\n type DeductionFormOutputs,\n type DeductionFormOptionalFieldsToRequire,\n} from './deductionFormSchema'\nimport {\n DescriptionField,\n RecurringField,\n DeductAsPercentageField,\n AmountField,\n TotalAmountField,\n AnnualMaximumField,\n GarnishmentTypeField,\n} from './fields'\nimport { useDeriveFieldsMetadata } from '@/partner-hook-utils/form/useDeriveFieldsMetadata'\nimport { useHookFormInternals } from '@/partner-hook-utils/form/useHookFormInternals'\nimport { createGetFormSubmissionValues } from '@/partner-hook-utils/form/getFormSubmissionValues'\nimport { withOptions } from '@/partner-hook-utils/form/withOptions'\nimport { composeErrorHandler } from '@/partner-hook-utils/composeErrorHandler'\nimport type {\n BaseFormHookReady,\n FieldsMetadata,\n HookLoadingResult,\n HookSubmitResult,\n} from '@/partner-hook-utils/types'\nimport { useBaseSubmit } from '@/components/Base/useBaseSubmit'\nimport { SDKInternalError } from '@/types/sdkError'\n\nexport type { DeductionFormOptionalFieldsToRequire } from './deductionFormSchema'\n\n// GarnishmentType is a runtime enum; the schema gates which values are valid.\n// The hook's `withOptions` entries below carry the raw enum values so the\n// consumer can supply translated labels via `getOptionLabel` on the field.\n//\n// `'child_support'` is intentionally omitted — child-support garnishments\n// require agency-keyed required attributes (case number, order number,\n// remittance number, county) that this hook doesn't model. Use\n// `useChildSupportGarnishmentForm` for those.\nconst GARNISHMENT_TYPES: readonly GarnishmentType[] = [\n 'federal_tax_lien',\n 'state_tax_lien',\n 'student_loan',\n 'creditor_garnishment',\n 'federal_loan',\n 'other_garnishment',\n] as const\n\nexport interface UseDeductionFormProps {\n employeeId: string\n /**\n * When set, loads that garnishment via the list query and updates it (PUT).\n * When omitted, the form is in create mode (POST).\n */\n garnishmentId?: string\n /**\n * Court-ordered deductions are stored as garnishments with `courtOrdered: true`\n * and require a `garnishmentType` (Federal Tax Lien, Student Loan, etc.).\n * When `false`, the form is for a \"custom\" post-tax deduction —\n * `garnishmentType` is excluded from the schema and submit payload.\n *\n * Note: this hook does NOT handle `garnishmentType: 'child_support'`. Use\n * `useChildSupportGarnishmentForm` for child-support agency-keyed payloads.\n */\n courtOrdered: boolean\n optionalFieldsToRequire?: DeductionFormOptionalFieldsToRequire\n defaultValues?: Partial<DeductionFormData>\n validationMode?: UseFormProps['mode']\n shouldFocusError?: boolean\n}\n\nexport interface DeductionFormFields {\n Description: typeof DescriptionField\n Recurring: typeof RecurringField\n DeductAsPercentage: typeof DeductAsPercentageField\n Amount: typeof AmountField\n /** Only available when `status.isRecurring` is true. */\n TotalAmount: typeof TotalAmountField | undefined\n /** Only available when `status.isRecurring` is true. */\n AnnualMaximum: typeof AnnualMaximumField | undefined\n /** Only available when `courtOrdered: true`. */\n GarnishmentType: typeof GarnishmentTypeField | undefined\n}\n\nexport interface UseDeductionFormReady extends BaseFormHookReady<\n FieldsMetadata,\n DeductionFormData,\n DeductionFormFields\n> {\n data: {\n /** The garnishment loaded for update; `null` in create mode. */\n deduction: Garnishment | null\n }\n status: {\n isPending: boolean\n mode: 'create' | 'update'\n /**\n * Mirrors the watched `recurring` value. Cap fields (`TotalAmount`,\n * `AnnualMaximum`) are only included on `Fields` when this is true — the\n * consumer can render them unconditionally and the gating happens in the\n * hook.\n */\n isRecurring: boolean\n }\n actions: {\n onSubmit: () => Promise<HookSubmitResult<Garnishment> | undefined>\n }\n}\n\nexport type UseDeductionFormResult = HookLoadingResult | UseDeductionFormReady\n\nexport function useDeductionForm({\n employeeId,\n garnishmentId,\n courtOrdered,\n optionalFieldsToRequire,\n defaultValues: partnerDefaults,\n validationMode = 'onSubmit',\n shouldFocusError = true,\n}: UseDeductionFormProps): UseDeductionFormResult {\n const isCreateMode = !garnishmentId\n const schemaMode = isCreateMode ? 'create' : 'update'\n\n // The garnishments API has no single-row GET — the list endpoint is the only\n // way to retrieve an existing garnishment. We use the (non-suspense) list\n // query and pick the matching row by uuid.\n const garnishmentsListQuery = useGarnishmentsListMutationLikeLoader({\n employeeId,\n enabled: !isCreateMode,\n })\n\n const fetchedDeduction = useMemo(() => {\n if (isCreateMode) return null\n return garnishmentsListQuery.data?.find(g => g.uuid === garnishmentId) ?? null\n }, [isCreateMode, garnishmentId, garnishmentsListQuery.data])\n\n const [schema, metadataConfig] = useMemo(\n () =>\n createDeductionFormSchema({\n mode: schemaMode,\n courtOrdered,\n optionalFieldsToRequire,\n }),\n [schemaMode, courtOrdered, optionalFieldsToRequire],\n )\n\n const resolvedDefaults: DeductionFormData = useMemo(\n () => ({\n description: fetchedDeduction?.description ?? partnerDefaults?.description ?? '',\n recurring: fetchedDeduction?.recurring ?? partnerDefaults?.recurring ?? true,\n deductAsPercentage:\n fetchedDeduction?.deductAsPercentage ?? partnerDefaults?.deductAsPercentage ?? true,\n amount: fetchedDeduction?.amount\n ? Number(fetchedDeduction.amount)\n : (partnerDefaults?.amount ?? 0),\n // Caps stay as numbers in the form (0 means \"no cap\"); the hook drops\n // them to null on the wire in onSubmit.\n totalAmount: fetchedDeduction?.totalAmount\n ? Number(fetchedDeduction.totalAmount)\n : (partnerDefaults?.totalAmount ?? 0),\n annualMaximum: fetchedDeduction?.annualMaximum\n ? Number(fetchedDeduction.annualMaximum)\n : (partnerDefaults?.annualMaximum ?? 0),\n garnishmentType:\n fetchedDeduction?.garnishmentType ??\n partnerDefaults?.garnishmentType ??\n // First non-child-support type — partners typically pick via the\n // GarnishmentType select before saving.\n 'federal_tax_lien',\n }),\n [fetchedDeduction, partnerDefaults],\n )\n\n const formMethods = useForm<DeductionFormData, unknown, DeductionFormOutputs>({\n resolver: zodResolver(schema),\n mode: validationMode,\n shouldFocusError,\n defaultValues: resolvedDefaults,\n values: resolvedDefaults,\n resetOptions: { keepDirtyValues: true },\n })\n\n // The cap fields only appear when the deduction is recurring. Watching here\n // (inside the hook) keeps the consumer from having to reach into\n // hookFormInternals — the conditional Fields below flip to `undefined`.\n const watchedRecurring = useWatch({ control: formMethods.control, name: 'recurring' })\n const isRecurring = watchedRecurring\n\n const createGarnishmentMutation = useGarnishmentsCreateMutation()\n const updateGarnishmentMutation = useGarnishmentsUpdateMutation()\n const isPending = createGarnishmentMutation.isPending || updateGarnishmentMutation.isPending\n\n const {\n baseSubmitHandler,\n error: submitError,\n setError: setSubmitError,\n } = useBaseSubmit('DeductionForm')\n\n const queriesForErrors = !isCreateMode ? [garnishmentsListQuery] : []\n const errorHandling = composeErrorHandler(queriesForErrors, { submitError, setSubmitError })\n\n const garnishmentTypeOptions = GARNISHMENT_TYPES.map(value => ({ value, label: value }))\n\n const baseMetadata = useDeriveFieldsMetadata(metadataConfig, formMethods.control)\n const fieldsMetadata = {\n description: baseMetadata.description,\n recurring: withOptions<boolean>(\n baseMetadata.recurring,\n [\n { value: 'true', label: 'true' },\n { value: 'false', label: 'false' },\n ],\n [true, false],\n ),\n deductAsPercentage: withOptions<boolean>(\n baseMetadata.deductAsPercentage,\n [\n { value: 'true', label: 'true' },\n { value: 'false', label: 'false' },\n ],\n [true, false],\n ),\n amount: baseMetadata.amount,\n totalAmount: baseMetadata.totalAmount,\n annualMaximum: baseMetadata.annualMaximum,\n garnishmentType: courtOrdered\n ? withOptions(baseMetadata.garnishmentType, garnishmentTypeOptions, GARNISHMENT_TYPES)\n : baseMetadata.garnishmentType,\n }\n\n const onSubmit = async (): Promise<HookSubmitResult<Garnishment> | undefined> => {\n let submitResult: HookSubmitResult<Garnishment> | undefined\n\n await new Promise<void>(resolve => {\n void formMethods.handleSubmit(\n async (data: DeductionFormOutputs) => {\n await baseSubmitHandler(data, async payload => {\n // The API's `times` column is \"number of remaining occurrences\" —\n // for one-time deductions we set it to 1, for recurring we null it\n // out. Matches the legacy GarnishmentForm/CustomDeductionForm.\n const times = payload.recurring ? null : 1\n // Wire conversions: amount is always a string; the optional caps\n // collapse to undefined when the partner left them at zero.\n const amountStr = String(payload.amount)\n const totalAmountStr = payload.totalAmount > 0 ? String(payload.totalAmount) : undefined\n const annualMaximumStr =\n payload.annualMaximum > 0 ? String(payload.annualMaximum) : undefined\n\n let updated: Garnishment | undefined\n\n if (isCreateMode) {\n const result = await createGarnishmentMutation.mutateAsync({\n request: {\n employeeId,\n garnishmentRequest: {\n active: true,\n description: payload.description,\n recurring: payload.recurring,\n deductAsPercentage: payload.deductAsPercentage,\n amount: amountStr,\n totalAmount: totalAmountStr,\n annualMaximum: annualMaximumStr,\n courtOrdered,\n garnishmentType: courtOrdered ? payload.garnishmentType : undefined,\n times,\n },\n },\n })\n updated = result.garnishment\n } else {\n if (!fetchedDeduction) {\n throw new SDKInternalError(\n 'Cannot update deduction: no matching garnishment on file',\n )\n }\n const result = await updateGarnishmentMutation.mutateAsync({\n request: {\n garnishmentId: fetchedDeduction.uuid,\n updateGarnishmentRequest: {\n version: fetchedDeduction.version as string,\n active: true,\n description: payload.description,\n recurring: payload.recurring,\n deductAsPercentage: payload.deductAsPercentage,\n amount: amountStr,\n totalAmount: totalAmountStr,\n annualMaximum: annualMaximumStr,\n courtOrdered,\n // The API rejects garnishment_type changes on update — only\n // include when court-ordered AND when matching the loaded\n // row's type (no-op pass-through).\n garnishmentType: courtOrdered ? payload.garnishmentType : undefined,\n times,\n },\n },\n })\n updated = result.garnishment\n }\n\n if (!updated) {\n throw new SDKInternalError(\n isCreateMode ? 'Deduction creation failed' : 'Deduction update failed',\n )\n }\n\n submitResult = {\n mode: isCreateMode ? 'create' : 'update',\n data: updated,\n }\n })\n resolve()\n },\n () => {\n resolve()\n },\n )()\n })\n\n return submitResult\n }\n\n const hookFormInternals = useHookFormInternals(formMethods)\n\n if (!isCreateMode && garnishmentsListQuery.isLoading) {\n return { isLoading: true as const, errorHandling }\n }\n\n return {\n isLoading: false as const,\n data: {\n deduction: fetchedDeduction,\n },\n status: {\n isPending,\n mode: isCreateMode ? 'create' : 'update',\n isRecurring,\n },\n actions: { onSubmit },\n errorHandling,\n form: {\n Fields: {\n Description: DescriptionField,\n Recurring: RecurringField,\n DeductAsPercentage: DeductAsPercentageField,\n Amount: AmountField,\n TotalAmount: isRecurring ? TotalAmountField : undefined,\n AnnualMaximum: isRecurring ? AnnualMaximumField : undefined,\n GarnishmentType: courtOrdered ? GarnishmentTypeField : undefined,\n },\n fieldsMetadata,\n hookFormInternals,\n getFormSubmissionValues: createGetFormSubmissionValues(formMethods, schema),\n },\n }\n}\n\nexport type DeductionFormFieldsMetadata = UseDeductionFormReady['form']['fieldsMetadata']\nexport type DeductionFormFieldsType = UseDeductionFormReady['form']['Fields']\n\n// ── Internal loader ─────────────────────────────────────────────────────\n//\n// `useGarnishmentsList` is the only way to retrieve an existing garnishment\n// row — the API has no single-row GET. We expose a tiny wrapper that returns\n// the array directly so the hook above can `.find()` by uuid. Skips the fetch\n// entirely in create mode via `enabled: false`.\n\nfunction useGarnishmentsListMutationLikeLoader({\n employeeId,\n enabled,\n}: {\n employeeId: string\n enabled: boolean\n}) {\n const query = useGarnishmentsList({ employeeId }, { enabled })\n return {\n data: query.data?.garnishments,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n }\n}\n"],"names":["GARNISHMENT_TYPES","useDeductionForm","employeeId","garnishmentId","courtOrdered","optionalFieldsToRequire","partnerDefaults","validationMode","shouldFocusError","isCreateMode","schemaMode","garnishmentsListQuery","useGarnishmentsListMutationLikeLoader","fetchedDeduction","useMemo","g","schema","metadataConfig","createDeductionFormSchema","resolvedDefaults","formMethods","useForm","zodResolver","isRecurring","useWatch","createGarnishmentMutation","useGarnishmentsCreateMutation","updateGarnishmentMutation","useGarnishmentsUpdateMutation","isPending","baseSubmitHandler","submitError","setSubmitError","useBaseSubmit","errorHandling","composeErrorHandler","garnishmentTypeOptions","value","baseMetadata","useDeriveFieldsMetadata","fieldsMetadata","withOptions","onSubmit","submitResult","resolve","data","payload","times","amountStr","totalAmountStr","annualMaximumStr","updated","SDKInternalError","hookFormInternals","useHookFormInternals","DescriptionField","RecurringField","DeductAsPercentageField","AmountField","TotalAmountField","AnnualMaximumField","GarnishmentTypeField","createGetFormSubmissionValues","enabled","query","useGarnishmentsList"],"mappings":";;;;;;;;;;;;;;;AAkDA,MAAMA,IAAgD;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAiEO,SAASC,GAAiB;AAAA,EAC/B,YAAAC;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC;AAAA,EACA,yBAAAC;AAAA,EACA,eAAeC;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AACrB,GAAkD;AAChD,QAAMC,IAAe,CAACN,GAChBO,IAAaD,IAAe,WAAW,UAKvCE,IAAwBC,GAAsC;AAAA,IAClE,YAAAV;AAAA,IACA,SAAS,CAACO;AAAA,EAAA,CACX,GAEKI,IAAmBC,EAAQ,MAC3BL,IAAqB,OAClBE,EAAsB,MAAM,KAAK,OAAKI,EAAE,SAASZ,CAAa,KAAK,MACzE,CAACM,GAAcN,GAAeQ,EAAsB,IAAI,CAAC,GAEtD,CAACK,GAAQC,CAAc,IAAIH;AAAA,IAC/B,MACEI,EAA0B;AAAA,MACxB,MAAMR;AAAA,MACN,cAAAN;AAAA,MACA,yBAAAC;AAAA,IAAA,CACD;AAAA,IACH,CAACK,GAAYN,GAAcC,CAAuB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e,WAAW;AAAA,MAChC,aAAAc;AAAA,IAAA;AAAA,IAEF,SAAS,EAAE,UAAAmB,EAAA;AAAA,IACX,eAAAR;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ;AAAA,QACN,aAAaqB;AAAA,QACb,WAAWC;AAAA,QACX,oBAAoBC;AAAA,QACpB,QAAQC;AAAA,QACR,aAAanC,IAAcoC,IAAmB;AAAA,QAC9C,eAAepC,IAAcqC,IAAqB;AAAA,QAClD,iBAAiBxD,IAAeyD,IAAuB;AAAA,MAAA;AAAA,MAEzD,gBAAArB;AAAA,MACA,mBAAAa;AAAA,MACA,yBAAyBS,GAA8B1C,GAAaJ,CAAM;AAAA,IAAA;AAAA,EAC5E;AAEJ;AAYA,SAASJ,GAAsC;AAAA,EAC7C,YAAAV;AAAA,EACA,SAAA6D;AACF,GAGG;AACD,QAAMC,IAAQC,EAAoB,EAAE,YAAA/D,KAAc,EAAE,SAAA6D,GAAS;AAC7D,SAAO;AAAA,IACL,MAAMC,EAAM,MAAM;AAAA,IAClB,WAAWA,EAAM;AAAA,IACjB,OAAOA,EAAM;AAAA,IACb,SAASA,EAAM;AAAA,EAAA;AAEnB;"}
|
package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js
CHANGED
|
@@ -14,11 +14,10 @@ import "../../../../../../contexts/LocaleProvider/useLocale.js";
|
|
|
14
14
|
import "../../../../../../shared/constants.js";
|
|
15
15
|
import "classnames";
|
|
16
16
|
import "../../../../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
17
|
-
import "../../../../../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
18
17
|
import { createCompoundContext as t } from "../../../../../Base/createCompoundContext.js";
|
|
19
|
-
const [
|
|
18
|
+
const [v, P] = t("DocumentListContext");
|
|
20
19
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
P as DocumentListProvider,
|
|
21
|
+
v as useDocumentList
|
|
23
22
|
};
|
|
24
23
|
//# sourceMappingURL=useDocumentList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.ts"],"sourcesContent":["import type { Form } from '@gusto/embedded-api/models/components/form'\nimport { createCompoundContext } from '@/components/Base'\n\ntype DocumentListContextType = {\n employeeForms: Form[]\n hasSignedAllForms: boolean\n handleContinue: () => void\n handleRequestFormToSign: (form: Form) => void\n documentListError: Error | null\n formToSign?: Form\n}\n\nconst [useDocumentList, DocumentListProvider] =\n createCompoundContext<DocumentListContextType>('DocumentListContext')\nexport { useDocumentList, DocumentListProvider }\n"],"names":["useDocumentList","DocumentListProvider","createCompoundContext"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDocumentList.js","sources":["../../../../../../../src/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.ts"],"sourcesContent":["import type { Form } from '@gusto/embedded-api/models/components/form'\nimport { createCompoundContext } from '@/components/Base'\n\ntype DocumentListContextType = {\n employeeForms: Form[]\n hasSignedAllForms: boolean\n handleContinue: () => void\n handleRequestFormToSign: (form: Form) => void\n documentListError: Error | null\n formToSign?: Form\n}\n\nconst [useDocumentList, DocumentListProvider] =\n createCompoundContext<DocumentListContextType>('DocumentListContext')\nexport { useDocumentList, DocumentListProvider }\n"],"names":["useDocumentList","DocumentListProvider","createCompoundContext"],"mappings":";;;;;;;;;;;;;;;;;AAYA,MAAM,CAACA,GAAiBC,CAAoB,IAC1CC,EAA+C,qBAAqB;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { CheckboxHookField as t } from "../../../../../partner-hook-utils/form/fields/CheckboxHookField.js";
|
|
2
3
|
import { TextInputHookField as n } from "../../../../../partner-hook-utils/form/fields/TextInputHookField.js";
|
|
3
4
|
import { SelectHookField as a } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
4
|
-
import { CheckboxHookField as t } from "../../../../../partner-hook-utils/form/fields/CheckboxHookField.js";
|
|
5
5
|
import { RadioGroupHookField as p } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
6
6
|
function c(r) {
|
|
7
7
|
return /* @__PURE__ */ e(n, { ...r, name: "signature" });
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { SelectHookField as t } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
3
2
|
import { NumberInputHookField as o } from "../../../../../partner-hook-utils/form/fields/NumberInputHookField.js";
|
|
4
|
-
import { RadioGroupHookField as
|
|
3
|
+
import { RadioGroupHookField as t } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
4
|
+
import { SelectHookField as r } from "../../../../../partner-hook-utils/form/fields/SelectHookField.js";
|
|
5
5
|
function d(n) {
|
|
6
|
-
return /* @__PURE__ */ e(
|
|
6
|
+
return /* @__PURE__ */ e(r, { ...n, name: "filingStatus" });
|
|
7
7
|
}
|
|
8
8
|
function a(n) {
|
|
9
|
-
return /* @__PURE__ */ e(
|
|
9
|
+
return /* @__PURE__ */ e(t, { ...n, name: "twoJobs" });
|
|
10
10
|
}
|
|
11
11
|
function f(n) {
|
|
12
12
|
return /* @__PURE__ */ e(o, { ...n, name: "dependentsAmount", format: "currency", min: 0 });
|