@gusto/embedded-react-sdk 0.10.2 → 0.10.3-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/components/Base/Base.d.ts +3 -2
  3. package/dist/components/Base/Base.js +31 -31
  4. package/dist/components/Base/Base.js.map +1 -1
  5. package/dist/components/Company/BankAccount/BankAccountComponents.js +16 -9
  6. package/dist/components/Company/BankAccount/BankAccountComponents.js.map +1 -1
  7. package/dist/components/Company/BankAccount/BankAccountForm/Actions.js +22 -8
  8. package/dist/components/Company/BankAccount/BankAccountForm/Actions.js.map +1 -1
  9. package/dist/components/Company/BankAccount/BankAccountForm/BankAccountForm.d.ts +1 -0
  10. package/dist/components/Company/BankAccount/BankAccountForm/BankAccountForm.js +23 -25
  11. package/dist/components/Company/BankAccount/BankAccountForm/BankAccountForm.js.map +1 -1
  12. package/dist/components/Company/BankAccount/BankAccountForm/context.d.ts +4 -0
  13. package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
  14. package/dist/components/Company/BankAccount/BankAccountList/AccountView.js +14 -13
  15. package/dist/components/Company/BankAccount/BankAccountList/AccountView.js.map +1 -1
  16. package/dist/components/Company/BankAccount/stateMachine.d.ts +1 -1
  17. package/dist/components/Company/BankAccount/stateMachine.js +13 -5
  18. package/dist/components/Company/BankAccount/stateMachine.js.map +1 -1
  19. package/dist/components/Company/DocumentSigner/SignatureForm/SignatureForm.js +41 -42
  20. package/dist/components/Company/DocumentSigner/SignatureForm/SignatureForm.js.map +1 -1
  21. package/dist/components/Company/FederalTaxes/Head.js +11 -11
  22. package/dist/components/Company/FederalTaxes/Head.js.map +1 -1
  23. package/dist/components/Company/Industry/Industry.js +30 -31
  24. package/dist/components/Company/Industry/Industry.js.map +1 -1
  25. package/dist/components/Company/Locations/LocationForm/LocationForm.js +34 -37
  26. package/dist/components/Company/Locations/LocationForm/LocationForm.js.map +1 -1
  27. package/dist/components/Company/Locations/Locations.d.ts +1 -1
  28. package/dist/components/Company/Locations/Locations.js +19 -17
  29. package/dist/components/Company/Locations/Locations.js.map +1 -1
  30. package/dist/components/Company/Locations/LocationsList/List.js +5 -2
  31. package/dist/components/Company/Locations/LocationsList/List.js.map +1 -1
  32. package/dist/components/Company/PaySchedule/PaySchedule.js +70 -71
  33. package/dist/components/Company/PaySchedule/PaySchedule.js.map +1 -1
  34. package/dist/components/Contractor/Address/Address.js +37 -38
  35. package/dist/components/Contractor/Address/Address.js.map +1 -1
  36. package/dist/components/Contractor/List/index.js +47 -50
  37. package/dist/components/Contractor/List/index.js.map +1 -1
  38. package/dist/components/Contractor/NewHireReport/NewHireReport.js +57 -58
  39. package/dist/components/Contractor/NewHireReport/NewHireReport.js.map +1 -1
  40. package/dist/components/Employee/Compensation/Compensation.js +123 -132
  41. package/dist/components/Employee/Compensation/Compensation.js.map +1 -1
  42. package/dist/components/Employee/Deductions/Deductions.js +74 -79
  43. package/dist/components/Employee/Deductions/Deductions.js.map +1 -1
  44. package/dist/components/Employee/DocumentSigner/SignatureForm/SignatureForm.js +36 -42
  45. package/dist/components/Employee/DocumentSigner/SignatureForm/SignatureForm.js.map +1 -1
  46. package/dist/components/Employee/EmployeeList/EmployeeList.js +57 -58
  47. package/dist/components/Employee/EmployeeList/EmployeeList.js.map +1 -1
  48. package/dist/components/Employee/PaymentMethod/PaymentMethod.js +95 -97
  49. package/dist/components/Employee/PaymentMethod/PaymentMethod.js.map +1 -1
  50. package/dist/components/Employee/Profile/Profile.js +118 -124
  51. package/dist/components/Employee/Profile/Profile.js.map +1 -1
  52. package/dist/components/Employee/Taxes/FederalForm.js +4 -4
  53. package/dist/components/Employee/Taxes/FederalForm.js.map +1 -1
  54. package/dist/components/Employee/Taxes/Taxes.js +59 -60
  55. package/dist/components/Employee/Taxes/Taxes.js.map +1 -1
  56. package/dist/contexts/ApiProvider/ApiProvider.js +16 -14
  57. package/dist/contexts/ApiProvider/ApiProvider.js.map +1 -1
  58. package/dist/contexts/ComponentAdapter/componentAdapterTypes.d.ts +5 -0
  59. package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.d.ts +2 -0
  60. package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js +19 -17
  61. package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js.map +1 -1
  62. package/dist/contexts/LoadingIndicatorProvider/LoadingIndicatorProvider.d.ts +7 -0
  63. package/dist/contexts/LoadingIndicatorProvider/LoadingIndicatorProvider.js +10 -0
  64. package/dist/contexts/LoadingIndicatorProvider/LoadingIndicatorProvider.js.map +1 -0
  65. package/dist/contexts/LoadingIndicatorProvider/useLoadingIndicator.d.ts +6 -0
  66. package/dist/contexts/LoadingIndicatorProvider/useLoadingIndicator.js +11 -0
  67. package/dist/contexts/LoadingIndicatorProvider/useLoadingIndicator.js.map +1 -0
  68. package/dist/i18n/en/Company.Locations.json.js +2 -2
  69. package/dist/shared/constants.d.ts +2 -0
  70. package/dist/shared/constants.js +10 -9
  71. package/dist/shared/constants.js.map +1 -1
  72. package/dist/style.css +1 -1
  73. package/dist/types/i18next.d.ts +1 -1
  74. package/package.json +8 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Compensation.js","sources":["../../../../src/components/Employee/Compensation/Compensation.tsx"],"sourcesContent":["import { zodResolver } from '@hookform/resolvers/zod'\nimport { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm, type SubmitHandler } from 'react-hook-form'\nimport { useTranslation } from 'react-i18next'\nimport {\n useJobsAndCompensationsGetJobsSuspense,\n invalidateJobsAndCompensationsGetJobs,\n} from '@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs'\nimport { useJobsAndCompensationsCreateJobMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob'\nimport { useJobsAndCompensationsUpdateMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdate'\nimport { useJobsAndCompensationsDeleteMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsDelete'\nimport { useJobsAndCompensationsUpdateCompensationMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation'\nimport { useLocationsGetMinimumWagesSuspense } from '@gusto/embedded-api/react-query/locationsGetMinimumWages'\nimport { useEmployeeAddressesGetWorkAddressesSuspense } from '@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses'\nimport { type Job } from '@gusto/embedded-api/models/components/job'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type { FlsaStatusType } from '@gusto/embedded-api/models/components/flsastatustype'\nimport { useFederalTaxDetailsGetSuspense } from '@gusto/embedded-api/react-query/federalTaxDetailsGet'\nimport { useEmployeesGetSuspense } from '@gusto/embedded-api/react-query/employeesGet'\nimport type { OnboardingContextInterface } from '../OnboardingFlow/OnboardingFlow'\nimport { List } from './List'\nimport { Head } from './Head'\nimport { Edit } from './Edit'\nimport { Actions } from './Actions'\nimport {\n type CompensationInputs,\n type CompensationOutputs,\n CompensationProvider,\n CompensationSchema,\n type MODE,\n} from './useCompensation'\nimport { Form } from '@/components/Common/Form'\nimport type { RequireAtLeastOne } from '@/types/Helpers'\nimport type { PAY_PERIODS } from '@/shared/constants'\nimport { componentEvents, FlsaStatus } from '@/shared/constants'\nimport { useComponentDictionary, useI18n } from '@/i18n'\nimport {\n BaseComponent,\n type BaseComponentInterface,\n useBase,\n type CommonComponentInterface,\n} from '@/components/Base'\nimport { useFlow } from '@/components/Flow/useFlow'\n\nexport type CompensationDefaultValues = RequireAtLeastOne<{\n rate?: Job['rate']\n title?: Job['title']\n paymentUnit?: (typeof PAY_PERIODS)[keyof typeof PAY_PERIODS]\n flsaStatus?: FlsaStatusType\n}>\n\ninterface CompensationProps extends CommonComponentInterface<'Employee.Compensation'> {\n employeeId: string\n startDate: string\n defaultValues?: CompensationDefaultValues\n}\n\nexport function Compensation(props: CompensationProps & BaseComponentInterface) {\n useComponentDictionary('Employee.Compensation', props.dictionary)\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nconst findCurrentCompensation = (employeeJob?: Job | null) => {\n return employeeJob?.compensations?.find(comp => comp.uuid === employeeJob.currentCompensationUuid)\n}\n\nconst Root = ({ employeeId, startDate, className, children, ...props }: CompensationProps) => {\n useI18n('Employee.Compensation')\n const { baseSubmitHandler, onEvent } = useBase()\n const queryClient = useQueryClient()\n\n const { data: jobsData } = useJobsAndCompensationsGetJobsSuspense({ employeeId })\n const employeeJobs = jobsData.jobList!\n\n const { data: addressesData } = useEmployeeAddressesGetWorkAddressesSuspense({ employeeId })\n const workAddresses = addressesData.employeeWorkAddressesList!\n\n const currentWorkAddress = workAddresses.find(address => address.active)!\n\n const {\n data: { minimumWageList },\n } = useLocationsGetMinimumWagesSuspense({\n locationUuid: currentWorkAddress.locationUuid!,\n })\n const minimumWages = minimumWageList!\n\n const {\n data: { employee },\n } = useEmployeesGetSuspense({ employeeId })\n\n if (!employee) {\n throw new Error('Employee not found')\n }\n\n const { data } = useFederalTaxDetailsGetSuspense({ companyId: employee.companyUuid! })\n const showTwoPercentStakeholder = data.federalTaxDetails!.taxPayerType === 'S-Corporation'\n\n const updateCompensationMutation = useJobsAndCompensationsUpdateCompensationMutation({\n onSettled: () => invalidateJobsAndCompensationsGetJobs(queryClient, [employeeId]),\n })\n const createEmployeeJobMutation = useJobsAndCompensationsCreateJobMutation({\n onSettled: () => invalidateJobsAndCompensationsGetJobs(queryClient, [employeeId]),\n })\n const updateEmployeeJobMutation = useJobsAndCompensationsUpdateMutation({\n onSettled: () => invalidateJobsAndCompensationsGetJobs(queryClient, [employeeId]),\n })\n const deleteEmployeeJobMutation = useJobsAndCompensationsDeleteMutation({\n onSettled: () => invalidateJobsAndCompensationsGetJobs(queryClient, [employeeId]),\n })\n\n //Job being edited/created\n const [currentJob, setCurrentJob] = useState<Job | null>(\n employeeJobs.length === 1 ? (employeeJobs[0] ?? null) : null,\n )\n\n const [mode, setMode] = useState<MODE>(() => {\n if (!employeeJobs.length) {\n return 'ADD_INITIAL_JOB'\n }\n\n const currentCompensation = findCurrentCompensation(employeeJobs[0])\n\n if (employeeJobs.length === 1 && currentCompensation?.flsaStatus !== FlsaStatus.NONEXEMPT) {\n return 'EDIT_INITIAL_JOB'\n }\n\n return 'LIST'\n })\n\n const [showFlsaChangeWarning, setShowFlsaChangeWarning] = useState(false)\n //Getting current compensation for a job -> the one with the most recent effective date\n const currentCompensation = findCurrentCompensation(currentJob)\n /** Returns FLSA status of a current compensation of a primary job:\n * Employees can have multiple jobs, with multiple compensations, but only 1 job is primary with 1 current compensation\n */\n const primaryFlsaStatus = useMemo<string | undefined>(() => {\n return employeeJobs.reduce<string | undefined>((prev, curr) => {\n const compensation = curr.compensations?.find(\n comp => comp.uuid === curr.currentCompensationUuid,\n )\n if (!curr.primary || !compensation) return prev\n return compensation.flsaStatus ?? prev\n }, undefined)\n }, [employeeJobs])\n\n const defaultValues: CompensationInputs = useMemo(() => {\n return {\n jobTitle:\n currentJob?.title && currentJob.title !== ''\n ? currentJob.title\n : (props.defaultValues?.title ?? ''),\n flsaStatus:\n currentCompensation?.flsaStatus ?? primaryFlsaStatus ?? props.defaultValues?.flsaStatus,\n rate: Number(currentCompensation?.rate ?? props.defaultValues?.rate ?? 0),\n adjustForMinimumWage: currentCompensation?.adjustForMinimumWage ?? false,\n minimumWageId: currentCompensation?.minimumWages?.[0]?.uuid ?? '',\n paymentUnit: currentCompensation?.paymentUnit ?? props.defaultValues?.paymentUnit ?? 'Hour',\n stateWcCovered: currentJob?.stateWcCovered ?? false,\n stateWcClassCode: currentJob?.stateWcClassCode ?? '',\n } as CompensationInputs\n }, [currentJob, currentCompensation, primaryFlsaStatus, props.defaultValues])\n\n const formMethods = useForm<CompensationInputs, unknown, CompensationOutputs>({\n resolver: zodResolver(CompensationSchema),\n defaultValues,\n })\n const { resetField, setValue, handleSubmit, reset } = formMethods\n useEffect(() => {\n reset(defaultValues)\n }, [currentJob, defaultValues, reset])\n\n const submitWithEffect = async (newMode?: MODE) => {\n if (mode === 'LIST' && newMode === 'PROCEED') {\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_DONE)\n return\n }\n //If no job has been modified, switch to edit mode\n if (!currentJob && mode === 'LIST') {\n setMode('ADD_ADDITIONAL_JOB')\n return\n }\n //Performing post-submit state setting only on success\n await handleSubmit(async (data: CompensationOutputs) => {\n await onSubmit(data)\n switch (newMode) {\n case 'LIST':\n setMode('LIST')\n setCurrentJob(null)\n reset(defaultValues)\n break\n default:\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_DONE)\n }\n })()\n }\n const handleAdd = () => {\n setMode('ADD_ADDITIONAL_JOB')\n setCurrentJob(null)\n reset(defaultValues)\n }\n\n const handleCancelAddJob = () => {\n if (employeeJobs.length > 0) {\n setMode('LIST')\n } else {\n setMode('ADD_INITIAL_JOB')\n }\n\n setCurrentJob(null)\n reset(defaultValues)\n }\n\n const handleEdit = (uuid: string) => {\n const selectedJob = employeeJobs.find(job => uuid === job.uuid)\n if (selectedJob) {\n setMode('EDIT_ADDITIONAL_JOB')\n setCurrentJob(selectedJob)\n }\n }\n\n const handleDelete = async (jobId: string) => {\n await deleteEmployeeJobMutation.mutateAsync({ request: { jobId } })\n onEvent(componentEvents.EMPLOYEE_JOB_DELETED)\n }\n\n /**Update dependent field values upon change in FLSA type */\n const handleFlsaChange = (value: string | number) => {\n //Attempting to change flsa status from nonexempt should prompt user about deletion of other jobs associated with the employee\n if (currentCompensation?.flsaStatus === FlsaStatus.NONEXEMPT && employeeJobs.length > 1) {\n setShowFlsaChangeWarning(true)\n }\n if (value === FlsaStatus.OWNER) {\n setValue('paymentUnit', 'Paycheck')\n resetField('rate', { defaultValue: Number(currentCompensation?.rate) })\n } else if (\n value === FlsaStatus.COMMISSION_ONLY_NONEXEMPT ||\n value === FlsaStatus.COMMISSION_ONLY_EXEMPT\n ) {\n setValue('paymentUnit', 'Year')\n setValue('rate', 0)\n } else {\n //reset fields\n resetField('paymentUnit', { defaultValue: currentCompensation?.paymentUnit })\n resetField('rate', { defaultValue: Number(currentCompensation?.rate) })\n }\n }\n\n const onSubmit: SubmitHandler<CompensationOutputs> = async data => {\n await baseSubmitHandler(data, async payload => {\n const { jobTitle, twoPercentShareholder, ...compensationData } = payload\n let updatedJobData\n //Note: some of the type fixes below are due to the fact that API incorrectly defines current_compensation_uuid as optional\n if (!currentJob) {\n //Adding new job for NONEXEMPT\n const data = await createEmployeeJobMutation.mutateAsync({\n request: {\n employeeId,\n requestBody: {\n title: jobTitle,\n hireDate: startDate,\n stateWcCovered: compensationData.stateWcCovered,\n stateWcClassCode: compensationData.stateWcCovered\n ? compensationData.stateWcClassCode\n : null,\n twoPercentShareholder: twoPercentShareholder ?? false,\n },\n },\n })\n updatedJobData = data.job!\n onEvent(componentEvents.EMPLOYEE_JOB_CREATED, updatedJobData)\n } else {\n const data = await updateEmployeeJobMutation.mutateAsync({\n request: {\n jobId: currentJob.uuid,\n requestBody: {\n title: jobTitle,\n version: currentJob.version as string,\n hireDate: startDate,\n stateWcClassCode: compensationData.stateWcCovered\n ? compensationData.stateWcClassCode\n : null,\n stateWcCovered: compensationData.stateWcCovered,\n twoPercentShareholder: twoPercentShareholder ?? false,\n },\n },\n })\n updatedJobData = data.job!\n onEvent(componentEvents.EMPLOYEE_JOB_UPDATED, updatedJobData)\n }\n\n const { compensation } = await updateCompensationMutation.mutateAsync({\n request: {\n compensationId: updatedJobData.currentCompensationUuid!,\n requestBody: {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n version: updatedJobData.compensations?.find(\n comp => comp.uuid === updatedJobData.currentCompensationUuid,\n )?.version!,\n ...compensationData,\n rate: String(compensationData.rate),\n minimumWages: compensationData.adjustForMinimumWage\n ? [{ uuid: compensationData.minimumWageId }]\n : [],\n },\n },\n })\n setShowFlsaChangeWarning(false)\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_UPDATED, compensation)\n })\n }\n return (\n <section className={className}>\n <CompensationProvider\n value={{\n employeeJobs,\n currentJob,\n primaryFlsaStatus,\n showFlsaChangeWarning,\n mode,\n minimumWages,\n handleFlsaChange,\n handleDelete,\n handleEdit,\n handleAdd,\n submitWithEffect,\n handleCancelAddJob,\n isPending:\n updateCompensationMutation.isPending ||\n createEmployeeJobMutation.isPending ||\n updateEmployeeJobMutation.isPending ||\n deleteEmployeeJobMutation.isPending,\n state: currentWorkAddress.state,\n showTwoPercentStakeholder,\n }}\n >\n <FormProvider {...formMethods}>\n <Form>\n {children ? (\n children\n ) : (\n <>\n <Head />\n <List />\n <Edit />\n <Actions />\n </>\n )}\n </Form>\n </FormProvider>\n </CompensationProvider>\n </section>\n )\n}\n\nCompensation.Head = Head\nCompensation.List = List\nCompensation.Actions = Actions\nCompensation.Edit = Edit\n\nexport const CompensationContextual = () => {\n const { employeeId, onEvent, startDate, defaultValues } = useFlow<OnboardingContextInterface>()\n const { t } = useTranslation('common')\n\n if (!employeeId || !startDate) {\n throw new Error(\n t('errors.missingParamsOrContext', {\n component: 'Compensation',\n param: !employeeId ? 'employeeId' : 'startDate',\n provider: 'FlowProvider',\n }),\n )\n }\n return (\n <Compensation\n employeeId={employeeId}\n startDate={startDate}\n onEvent={onEvent}\n defaultValues={defaultValues?.compensation}\n />\n )\n}\n"],"names":["Compensation","props","useComponentDictionary","jsx","BaseComponent","Root","findCurrentCompensation","employeeJob","comp","employeeId","startDate","className","children","useI18n","baseSubmitHandler","onEvent","useBase","queryClient","useQueryClient","jobsData","useJobsAndCompensationsGetJobsSuspense","employeeJobs","addressesData","useEmployeeAddressesGetWorkAddressesSuspense","currentWorkAddress","address","minimumWageList","useLocationsGetMinimumWagesSuspense","minimumWages","employee","useEmployeesGetSuspense","data","useFederalTaxDetailsGetSuspense","showTwoPercentStakeholder","updateCompensationMutation","useJobsAndCompensationsUpdateCompensationMutation","invalidateJobsAndCompensationsGetJobs","createEmployeeJobMutation","useJobsAndCompensationsCreateJobMutation","updateEmployeeJobMutation","useJobsAndCompensationsUpdateMutation","deleteEmployeeJobMutation","useJobsAndCompensationsDeleteMutation","currentJob","setCurrentJob","useState","mode","setMode","currentCompensation","FlsaStatus","showFlsaChangeWarning","setShowFlsaChangeWarning","primaryFlsaStatus","useMemo","prev","curr","compensation","defaultValues","formMethods","useForm","zodResolver","CompensationSchema","resetField","setValue","handleSubmit","reset","useEffect","submitWithEffect","newMode","componentEvents","onSubmit","handleAdd","handleCancelAddJob","handleEdit","uuid","selectedJob","job","handleDelete","jobId","handleFlsaChange","value","payload","jobTitle","twoPercentShareholder","compensationData","updatedJobData","CompensationProvider","FormProvider","Form","jsxs","Fragment","Head","List","Edit","Actions","CompensationContextual","useFlow","t","useTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,SAASA,EAAaC,GAAmD;AACvD,SAAAC,GAAA,yBAAyBD,EAAM,UAAU,GAE9D,gBAAAE,EAACC,IAAe,EAAA,GAAGH,GACjB,UAAA,gBAAAE,EAACE,MAAM,GAAGJ,GAAQ,UAAMA,EAAA,SAAA,CAAS,EACnC,CAAA;AAEJ;AAEA,MAAMK,IAA0B,CAACC,MACxBA,GAAa,eAAe,KAAK,OAAQC,EAAK,SAASD,EAAY,uBAAuB,GAG7FF,KAAO,CAAC,EAAE,YAAAI,GAAY,WAAAC,GAAW,WAAAC,GAAW,UAAAC,GAAU,GAAGX,QAA+B;AAC5F,EAAAY,GAAQ,uBAAuB;AAC/B,QAAM,EAAE,mBAAAC,GAAmB,SAAAC,EAAQ,IAAIC,GAAQ,GACzCC,IAAcC,GAAe,GAE7B,EAAE,MAAMC,EAAA,IAAaC,GAAuC,EAAE,YAAAX,GAAY,GAC1EY,IAAeF,EAAS,SAExB,EAAE,MAAMG,EAAA,IAAkBC,GAA6C,EAAE,YAAAd,GAAY,GAGrFe,IAFgBF,EAAc,0BAEK,KAAK,CAAAG,MAAWA,EAAQ,MAAM,GAEjE;AAAA,IACJ,MAAM,EAAE,iBAAAC,EAAgB;AAAA,MACtBC,GAAoC;AAAA,IACtC,cAAcH,EAAm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AAf;AAAA,QACrB,UAAU;AAAA,MACX,CAAA;AAAA,IACH;AAGA,SAAA,gBAAAN;AAAA,IAACH;AAAA,IAAA;AAAA,MACC,YAAAS;AAAA,MACA,WAAAC;AAAA,MACA,SAAAK;AAAA,MACA,eAAe0C,GAAe;AAAA,IAAA;AAAA,EAChC;AAEJ;"}
1
+ {"version":3,"file":"Compensation.js","sources":["../../../../src/components/Employee/Compensation/Compensation.tsx"],"sourcesContent":["import { zodResolver } from '@hookform/resolvers/zod'\nimport { useEffect, useMemo, useState } from 'react'\nimport { FormProvider, useForm, type SubmitHandler } from 'react-hook-form'\nimport { useTranslation } from 'react-i18next'\nimport { useJobsAndCompensationsGetJobsSuspense } from '@gusto/embedded-api/react-query/jobsAndCompensationsGetJobs'\nimport { useJobsAndCompensationsCreateJobMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsCreateJob'\nimport { useJobsAndCompensationsUpdateMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdate'\nimport { useJobsAndCompensationsDeleteMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsDelete'\nimport { useJobsAndCompensationsUpdateCompensationMutation } from '@gusto/embedded-api/react-query/jobsAndCompensationsUpdateCompensation'\nimport { useLocationsGetMinimumWagesSuspense } from '@gusto/embedded-api/react-query/locationsGetMinimumWages'\nimport { useEmployeeAddressesGetWorkAddressesSuspense } from '@gusto/embedded-api/react-query/employeeAddressesGetWorkAddresses'\nimport { type Job } from '@gusto/embedded-api/models/components/job'\nimport type { FlsaStatusType } from '@gusto/embedded-api/models/components/flsastatustype'\nimport { useFederalTaxDetailsGetSuspense } from '@gusto/embedded-api/react-query/federalTaxDetailsGet'\nimport { useEmployeesGetSuspense } from '@gusto/embedded-api/react-query/employeesGet'\nimport type { OnboardingContextInterface } from '../OnboardingFlow/OnboardingFlow'\nimport { List } from './List'\nimport { Head } from './Head'\nimport { Edit } from './Edit'\nimport { Actions } from './Actions'\nimport {\n type CompensationInputs,\n type CompensationOutputs,\n CompensationProvider,\n CompensationSchema,\n type MODE,\n} from './useCompensation'\nimport { Form } from '@/components/Common/Form'\nimport type { RequireAtLeastOne } from '@/types/Helpers'\nimport type { PAY_PERIODS } from '@/shared/constants'\nimport { componentEvents, FlsaStatus } from '@/shared/constants'\nimport { useComponentDictionary, useI18n } from '@/i18n'\nimport {\n BaseComponent,\n type BaseComponentInterface,\n useBase,\n type CommonComponentInterface,\n} from '@/components/Base'\nimport { useFlow } from '@/components/Flow/useFlow'\n\nexport type CompensationDefaultValues = RequireAtLeastOne<{\n rate?: Job['rate']\n title?: Job['title']\n paymentUnit?: (typeof PAY_PERIODS)[keyof typeof PAY_PERIODS]\n flsaStatus?: FlsaStatusType\n}>\n\ninterface CompensationProps extends CommonComponentInterface<'Employee.Compensation'> {\n employeeId: string\n startDate: string\n defaultValues?: CompensationDefaultValues\n}\n\nexport function Compensation(props: CompensationProps & BaseComponentInterface) {\n useComponentDictionary('Employee.Compensation', props.dictionary)\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\n\nconst findCurrentCompensation = (employeeJob?: Job | null) => {\n return employeeJob?.compensations?.find(comp => comp.uuid === employeeJob.currentCompensationUuid)\n}\n\nconst Root = ({ employeeId, startDate, className, children, ...props }: CompensationProps) => {\n useI18n('Employee.Compensation')\n const { baseSubmitHandler, onEvent } = useBase()\n\n const { data: jobsData } = useJobsAndCompensationsGetJobsSuspense({ employeeId })\n const employeeJobs = jobsData.jobList!\n\n const { data: addressesData } = useEmployeeAddressesGetWorkAddressesSuspense({ employeeId })\n const workAddresses = addressesData.employeeWorkAddressesList!\n\n const currentWorkAddress = workAddresses.find(address => address.active)!\n\n const {\n data: { minimumWageList },\n } = useLocationsGetMinimumWagesSuspense({\n locationUuid: currentWorkAddress.locationUuid!,\n })\n const minimumWages = minimumWageList!\n\n const {\n data: { employee },\n } = useEmployeesGetSuspense({ employeeId })\n\n if (!employee) {\n throw new Error('Employee not found')\n }\n\n const { data } = useFederalTaxDetailsGetSuspense({ companyId: employee.companyUuid! })\n const showTwoPercentStakeholder = data.federalTaxDetails!.taxPayerType === 'S-Corporation'\n\n const updateCompensationMutation = useJobsAndCompensationsUpdateCompensationMutation()\n const createEmployeeJobMutation = useJobsAndCompensationsCreateJobMutation()\n const updateEmployeeJobMutation = useJobsAndCompensationsUpdateMutation()\n const deleteEmployeeJobMutation = useJobsAndCompensationsDeleteMutation()\n\n //Job being edited/created\n const [currentJob, setCurrentJob] = useState<Job | null>(\n employeeJobs.length === 1 ? (employeeJobs[0] ?? null) : null,\n )\n\n const [mode, setMode] = useState<MODE>(() => {\n if (!employeeJobs.length) {\n return 'ADD_INITIAL_JOB'\n }\n\n const currentCompensation = findCurrentCompensation(employeeJobs[0])\n\n if (employeeJobs.length === 1 && currentCompensation?.flsaStatus !== FlsaStatus.NONEXEMPT) {\n return 'EDIT_INITIAL_JOB'\n }\n\n return 'LIST'\n })\n\n const [showFlsaChangeWarning, setShowFlsaChangeWarning] = useState(false)\n //Getting current compensation for a job -> the one with the most recent effective date\n const currentCompensation = findCurrentCompensation(currentJob)\n /** Returns FLSA status of a current compensation of a primary job:\n * Employees can have multiple jobs, with multiple compensations, but only 1 job is primary with 1 current compensation\n */\n const primaryFlsaStatus = useMemo<string | undefined>(() => {\n return employeeJobs.reduce<string | undefined>((prev, curr) => {\n const compensation = curr.compensations?.find(\n comp => comp.uuid === curr.currentCompensationUuid,\n )\n if (!curr.primary || !compensation) return prev\n return compensation.flsaStatus ?? prev\n }, undefined)\n }, [employeeJobs])\n\n const defaultValues: CompensationInputs = useMemo(() => {\n return {\n jobTitle:\n currentJob?.title && currentJob.title !== ''\n ? currentJob.title\n : (props.defaultValues?.title ?? ''),\n flsaStatus:\n currentCompensation?.flsaStatus ?? primaryFlsaStatus ?? props.defaultValues?.flsaStatus,\n rate: Number(currentCompensation?.rate ?? props.defaultValues?.rate ?? 0),\n adjustForMinimumWage: currentCompensation?.adjustForMinimumWage ?? false,\n minimumWageId: currentCompensation?.minimumWages?.[0]?.uuid ?? '',\n paymentUnit: currentCompensation?.paymentUnit ?? props.defaultValues?.paymentUnit ?? 'Hour',\n stateWcCovered: currentJob?.stateWcCovered ?? false,\n stateWcClassCode: currentJob?.stateWcClassCode ?? '',\n } as CompensationInputs\n }, [currentJob, currentCompensation, primaryFlsaStatus, props.defaultValues])\n\n const formMethods = useForm<CompensationInputs, unknown, CompensationOutputs>({\n resolver: zodResolver(CompensationSchema),\n defaultValues,\n })\n const { resetField, setValue, handleSubmit, reset } = formMethods\n useEffect(() => {\n reset(defaultValues)\n }, [currentJob, defaultValues, reset])\n\n const submitWithEffect = async (newMode?: MODE) => {\n if (mode === 'LIST' && newMode === 'PROCEED') {\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_DONE)\n return\n }\n //If no job has been modified, switch to edit mode\n if (!currentJob && mode === 'LIST') {\n setMode('ADD_ADDITIONAL_JOB')\n return\n }\n //Performing post-submit state setting only on success\n await handleSubmit(async (data: CompensationOutputs) => {\n await onSubmit(data)\n switch (newMode) {\n case 'LIST':\n setMode('LIST')\n setCurrentJob(null)\n reset(defaultValues)\n break\n default:\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_DONE)\n }\n })()\n }\n const handleAdd = () => {\n setMode('ADD_ADDITIONAL_JOB')\n setCurrentJob(null)\n reset(defaultValues)\n }\n\n const handleCancelAddJob = () => {\n if (employeeJobs.length > 0) {\n setMode('LIST')\n } else {\n setMode('ADD_INITIAL_JOB')\n }\n\n setCurrentJob(null)\n reset(defaultValues)\n }\n\n const handleEdit = (uuid: string) => {\n const selectedJob = employeeJobs.find(job => uuid === job.uuid)\n if (selectedJob) {\n setMode('EDIT_ADDITIONAL_JOB')\n setCurrentJob(selectedJob)\n }\n }\n\n const handleDelete = async (jobId: string) => {\n await deleteEmployeeJobMutation.mutateAsync({ request: { jobId } })\n onEvent(componentEvents.EMPLOYEE_JOB_DELETED)\n }\n\n /**Update dependent field values upon change in FLSA type */\n const handleFlsaChange = (value: string | number) => {\n //Attempting to change flsa status from nonexempt should prompt user about deletion of other jobs associated with the employee\n if (currentCompensation?.flsaStatus === FlsaStatus.NONEXEMPT && employeeJobs.length > 1) {\n setShowFlsaChangeWarning(true)\n }\n if (value === FlsaStatus.OWNER) {\n setValue('paymentUnit', 'Paycheck')\n resetField('rate', { defaultValue: Number(currentCompensation?.rate) })\n } else if (\n value === FlsaStatus.COMMISSION_ONLY_NONEXEMPT ||\n value === FlsaStatus.COMMISSION_ONLY_EXEMPT\n ) {\n setValue('paymentUnit', 'Year')\n setValue('rate', 0)\n } else {\n //reset fields\n resetField('paymentUnit', { defaultValue: currentCompensation?.paymentUnit })\n resetField('rate', { defaultValue: Number(currentCompensation?.rate) })\n }\n }\n\n const onSubmit: SubmitHandler<CompensationOutputs> = async data => {\n await baseSubmitHandler(data, async payload => {\n const { jobTitle, twoPercentShareholder, ...compensationData } = payload\n let updatedJobData\n //Note: some of the type fixes below are due to the fact that API incorrectly defines current_compensation_uuid as optional\n if (!currentJob) {\n //Adding new job for NONEXEMPT\n const data = await createEmployeeJobMutation.mutateAsync({\n request: {\n employeeId,\n requestBody: {\n title: jobTitle,\n hireDate: startDate,\n stateWcCovered: compensationData.stateWcCovered,\n stateWcClassCode: compensationData.stateWcCovered\n ? compensationData.stateWcClassCode\n : null,\n twoPercentShareholder: twoPercentShareholder ?? false,\n },\n },\n })\n updatedJobData = data.job!\n onEvent(componentEvents.EMPLOYEE_JOB_CREATED, updatedJobData)\n } else {\n const data = await updateEmployeeJobMutation.mutateAsync({\n request: {\n jobId: currentJob.uuid,\n requestBody: {\n title: jobTitle,\n version: currentJob.version as string,\n hireDate: startDate,\n stateWcClassCode: compensationData.stateWcCovered\n ? compensationData.stateWcClassCode\n : null,\n stateWcCovered: compensationData.stateWcCovered,\n twoPercentShareholder: twoPercentShareholder ?? false,\n },\n },\n })\n updatedJobData = data.job!\n onEvent(componentEvents.EMPLOYEE_JOB_UPDATED, updatedJobData)\n }\n\n const { compensation } = await updateCompensationMutation.mutateAsync({\n request: {\n compensationId: updatedJobData.currentCompensationUuid!,\n requestBody: {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n version: updatedJobData.compensations?.find(\n comp => comp.uuid === updatedJobData.currentCompensationUuid,\n )?.version!,\n ...compensationData,\n rate: String(compensationData.rate),\n minimumWages: compensationData.adjustForMinimumWage\n ? [{ uuid: compensationData.minimumWageId }]\n : [],\n },\n },\n })\n setShowFlsaChangeWarning(false)\n onEvent(componentEvents.EMPLOYEE_COMPENSATION_UPDATED, compensation)\n })\n }\n return (\n <section className={className}>\n <CompensationProvider\n value={{\n employeeJobs,\n currentJob,\n primaryFlsaStatus,\n showFlsaChangeWarning,\n mode,\n minimumWages,\n handleFlsaChange,\n handleDelete,\n handleEdit,\n handleAdd,\n submitWithEffect,\n handleCancelAddJob,\n isPending:\n updateCompensationMutation.isPending ||\n createEmployeeJobMutation.isPending ||\n updateEmployeeJobMutation.isPending ||\n deleteEmployeeJobMutation.isPending,\n state: currentWorkAddress.state,\n showTwoPercentStakeholder,\n }}\n >\n <FormProvider {...formMethods}>\n <Form>\n {children ? (\n children\n ) : (\n <>\n <Head />\n <List />\n <Edit />\n <Actions />\n </>\n )}\n </Form>\n </FormProvider>\n </CompensationProvider>\n </section>\n )\n}\n\nCompensation.Head = Head\nCompensation.List = List\nCompensation.Actions = Actions\nCompensation.Edit = Edit\n\nexport const CompensationContextual = () => {\n const { employeeId, onEvent, startDate, defaultValues } = useFlow<OnboardingContextInterface>()\n const { t } = useTranslation('common')\n\n if (!employeeId || !startDate) {\n throw new Error(\n t('errors.missingParamsOrContext', {\n component: 'Compensation',\n param: !employeeId ? 'employeeId' : 'startDate',\n provider: 'FlowProvider',\n }),\n )\n }\n return (\n <Compensation\n employeeId={employeeId}\n startDate={startDate}\n onEvent={onEvent}\n defaultValues={defaultValues?.compensation}\n />\n )\n}\n"],"names":["Compensation","props","useComponentDictionary","jsx","BaseComponent","Root","findCurrentCompensation","employeeJob","comp","employeeId","startDate","className","children","useI18n","baseSubmitHandler","onEvent","useBase","jobsData","useJobsAndCompensationsGetJobsSuspense","employeeJobs","addressesData","useEmployeeAddressesGetWorkAddressesSuspense","currentWorkAddress","address","minimumWageList","useLocationsGetMinimumWagesSuspense","minimumWages","employee","useEmployeesGetSuspense","data","useFederalTaxDetailsGetSuspense","showTwoPercentStakeholder","updateCompensationMutation","useJobsAndCompensationsUpdateCompensationMutation","createEmployeeJobMutation","useJobsAndCompensationsCreateJobMutation","updateEmployeeJobMutation","useJobsAndCompensationsUpdateMutation","deleteEmployeeJobMutation","useJobsAndCompensationsDeleteMutation","currentJob","setCurrentJob","useState","mode","setMode","currentCompensation","FlsaStatus","showFlsaChangeWarning","setShowFlsaChangeWarning","primaryFlsaStatus","useMemo","prev","curr","compensation","defaultValues","formMethods","useForm","zodResolver","CompensationSchema","resetField","setValue","handleSubmit","reset","useEffect","submitWithEffect","newMode","componentEvents","onSubmit","handleAdd","handleCancelAddJob","handleEdit","uuid","selectedJob","job","handleDelete","jobId","handleFlsaChange","value","payload","jobTitle","twoPercentShareholder","compensationData","updatedJobData","CompensationProvider","FormProvider","Form","jsxs","Fragment","Head","List","Edit","Actions","CompensationContextual","useFlow","t","useTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqDO,SAASA,EAAaC,GAAmD;AACvD,SAAAC,GAAA,yBAAyBD,EAAM,UAAU,GAE9D,gBAAAE,EAACC,IAAe,EAAA,GAAGH,GACjB,UAAA,gBAAAE,EAACE,MAAM,GAAGJ,GAAQ,UAAMA,EAAA,SAAA,CAAS,EACnC,CAAA;AAEJ;AAEA,MAAMK,IAA0B,CAACC,MACxBA,GAAa,eAAe,KAAK,OAAQC,EAAK,SAASD,EAAY,uBAAuB,GAG7FF,KAAO,CAAC,EAAE,YAAAI,GAAY,WAAAC,GAAW,WAAAC,GAAW,UAAAC,GAAU,GAAGX,QAA+B;AAC5F,EAAAY,GAAQ,uBAAuB;AAC/B,QAAM,EA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ACjC,WAAW;AAAA,QACX,OAAQrF,IAA4B,cAAf;AAAA,QACrB,UAAU;AAAA,MACX,CAAA;AAAA,IACH;AAGA,SAAA,gBAAAN;AAAA,IAACH;AAAA,IAAA;AAAA,MACC,YAAAS;AAAA,MACA,WAAAC;AAAA,MACA,SAAAK;AAAA,MACA,eAAeuC,GAAe;AAAA,IAAA;AAAA,EAChC;AAEJ;"}
@@ -1,39 +1,34 @@
1
- import { jsx as t, jsxs as C } from "react/jsx-runtime";
2
- import { useTranslation as q } from "react-i18next";
3
- import { useState as M, useMemo as y, useEffect as B } from "react";
1
+ import { jsx as t, jsxs as A } from "react/jsx-runtime";
2
+ import { useTranslation as U } from "react-i18next";
3
+ import { useState as M, useMemo as Y, useEffect as q } from "react";
4
4
  import { z as T } from "zod";
5
- import { useForm as L, FormProvider as O } from "react-hook-form";
6
- import { zodResolver as R } from "@hookform/resolvers/zod";
7
- import { useGarnishmentsListSuspense as G, invalidateGarnishmentsList as N } from "@gusto/embedded-api/react-query/garnishmentsList";
8
- import { useGarnishmentsCreateMutation as j } from "@gusto/embedded-api/react-query/garnishmentsCreate";
9
- import { useGarnishmentsUpdateMutation as z } from "@gusto/embedded-api/react-query/garnishmentsUpdate";
10
- import { useQueryClient as H } from "@tanstack/react-query";
11
- import { DeductionSchema as V, DeductionsProvider as Q } from "./useDeductions.js";
12
- import { BaseComponent as k } from "../../Base/Base.js";
13
- import { useBase as J } from "../../Base/useBase.js";
14
- import { Form as S } from "../../Common/Form/Form.js";
15
- import { useComponentDictionary as K, useI18n as W } from "../../../i18n/I18n.js";
5
+ import { useForm as O, FormProvider as C } from "react-hook-form";
6
+ import { zodResolver as y } from "@hookform/resolvers/zod";
7
+ import { useGarnishmentsListSuspense as B } from "@gusto/embedded-api/react-query/garnishmentsList";
8
+ import { useGarnishmentsCreateMutation as R } from "@gusto/embedded-api/react-query/garnishmentsCreate";
9
+ import { useGarnishmentsUpdateMutation as j } from "@gusto/embedded-api/react-query/garnishmentsUpdate";
10
+ import { DeductionSchema as G, DeductionsProvider as z } from "./useDeductions.js";
11
+ import { BaseComponent as H } from "../../Base/Base.js";
12
+ import { useBase as V } from "../../Base/useBase.js";
13
+ import { Form as L } from "../../Common/Form/Form.js";
14
+ import { useComponentDictionary as k, useI18n as J } from "../../../i18n/I18n.js";
16
15
  import { componentEvents as s } from "../../../shared/constants.js";
17
- import { Actions as _ } from "./Actions.js";
18
- import { IncludeDeductionsForm as X } from "./IncludeDeductionsForm.js";
19
- import { Head as b } from "./Head.js";
20
- import { DeductionForm as Z } from "./DeductionForm.js";
21
- import { DeductionsList as $ } from "./DeductionsList.js";
22
- import { useFlow as ee } from "../../Flow/useFlow.js";
16
+ import { Actions as N } from "./Actions.js";
17
+ import { IncludeDeductionsForm as K } from "./IncludeDeductionsForm.js";
18
+ import { Head as S } from "./Head.js";
19
+ import { DeductionForm as Q } from "./DeductionForm.js";
20
+ import { DeductionsList as W } from "./DeductionsList.js";
21
+ import { useFlow as X } from "../../Flow/useFlow.js";
23
22
  T.object({ includeDeductions: T.enum(["Yes", "No"]) });
24
- function te(n) {
25
- return /* @__PURE__ */ t(k, { ...n, children: /* @__PURE__ */ t(ne, { ...n, children: n.children }) });
23
+ function Z(o) {
24
+ return /* @__PURE__ */ t(H, { ...o, children: /* @__PURE__ */ t($, { ...o, children: o.children }) });
26
25
  }
27
- const ne = ({ employeeId: n, className: d, dictionary: a }) => {
28
- const { onEvent: i, baseSubmitHandler: h } = J(), f = H();
29
- K("Employee.Deductions", a);
30
- const { data: x } = G({ employeeId: n }), p = x.garnishmentList, { mutateAsync: g, isPending: w } = z({
31
- onSettled: () => N(f, [n])
32
- }), { mutateAsync: F, isPending: U } = j({
33
- onSettled: () => N(f, [n])
34
- }), P = p.filter((r) => r.active), [u, m] = M(P.length < 1 ? "INITIAL" : "LIST"), [e, l] = M(null);
35
- W("Employee.Deductions");
36
- const D = y(() => ({
26
+ const $ = ({ employeeId: o, className: d, dictionary: a }) => {
27
+ const { onEvent: i, baseSubmitHandler: h } = V();
28
+ k("Employee.Deductions", a);
29
+ const { data: _ } = B({ employeeId: o }), f = _.garnishmentList, { mutateAsync: p, isPending: b } = j(), { mutateAsync: x, isPending: w } = R(), g = f.filter((r) => r.active), [u, m] = M(g.length < 1 ? "INITIAL" : "LIST"), [e, l] = M(null);
30
+ J("Employee.Deductions");
31
+ const D = Y(() => ({
37
32
  amount: e?.amount ? Number(e.amount) : 0,
38
33
  description: e?.description ?? "",
39
34
  times: e?.times ?? null,
@@ -43,57 +38,57 @@ const ne = ({ employeeId: n, className: d, dictionary: a }) => {
43
38
  deductAsPercentage: e?.deductAsPercentage?.toString() ?? "true",
44
39
  active: !0,
45
40
  courtOrdered: e?.courtOrdered ?? !1
46
- }), [e]), I = L({
41
+ }), [e]), I = O({
47
42
  // resolver: zodResolver(IncludeDeductionsSchema),
48
43
  defaultValues: { includeDeductions: "No" }
49
- }), E = L({
50
- resolver: R(V),
44
+ }), E = O({
45
+ resolver: y(G),
51
46
  defaultValues: D
52
- }), { reset: v } = E;
53
- B(() => {
54
- v(D);
55
- }, [e, D, v, u]);
56
- const Y = async (r) => {
57
- await h(r, async (o) => {
58
- const { garnishment: c } = await g({
47
+ }), { reset: P } = E;
48
+ q(() => {
49
+ P(D);
50
+ }, [e, D, P, u]);
51
+ const F = async (r) => {
52
+ await h(r, async (n) => {
53
+ const { garnishment: c } = await p({
59
54
  request: {
60
- garnishmentId: o.uuid,
55
+ garnishmentId: n.uuid,
61
56
  requestBody: {
62
- ...o,
63
- totalAmount: o.totalAmount ?? void 0,
57
+ ...n,
58
+ totalAmount: n.totalAmount ?? void 0,
64
59
  active: !1,
65
- version: o.version
60
+ version: n.version
66
61
  }
67
62
  }
68
63
  });
69
64
  i(s.EMPLOYEE_DEDUCTION_DELETED, c);
70
65
  });
71
- }, A = async (r) => {
72
- await h(r, async (o) => {
73
- if ("includeDeductions" in o)
74
- if (o.includeDeductions === "Yes")
66
+ }, v = async (r) => {
67
+ await h(r, async (n) => {
68
+ if ("includeDeductions" in n)
69
+ if (n.includeDeductions === "Yes")
75
70
  m("ADD"), i(s.EMPLOYEE_DEDUCTION_ADD);
76
71
  else {
77
72
  i(s.EMPLOYEE_DEDUCTION_DONE);
78
73
  return;
79
74
  }
80
- if (!("includeDeductions" in o)) {
75
+ if (!("includeDeductions" in n)) {
81
76
  if (u === "ADD") {
82
- const { garnishment: c } = await F({
77
+ const { garnishment: c } = await x({
83
78
  request: {
84
- employeeId: n,
85
- requestBody: { ...o, times: o.recurring ? null : 1 }
79
+ employeeId: o,
80
+ requestBody: { ...n, times: n.recurring ? null : 1 }
86
81
  }
87
82
  });
88
83
  i(s.EMPLOYEE_DEDUCTION_CREATED, c);
89
84
  } else if (u === "EDIT") {
90
- const { garnishment: c } = await g({
85
+ const { garnishment: c } = await p({
91
86
  request: {
92
87
  garnishmentId: e?.uuid ?? "",
93
88
  requestBody: {
94
- ...o,
89
+ ...n,
95
90
  version: e?.version,
96
- times: o.recurring ? null : 1
91
+ times: n.recurring ? null : 1
97
92
  }
98
93
  }
99
94
  });
@@ -104,20 +99,20 @@ const ne = ({ employeeId: n, className: d, dictionary: a }) => {
104
99
  });
105
100
  };
106
101
  return /* @__PURE__ */ t("section", { className: d, children: /* @__PURE__ */ t(
107
- Q,
102
+ z,
108
103
  {
109
104
  value: {
110
- isPending: U || w,
111
- employeeId: n,
105
+ isPending: w || b,
106
+ employeeId: o,
112
107
  mode: u,
113
- deductions: p,
108
+ deductions: f,
114
109
  handleAdd: () => {
115
110
  m("ADD");
116
111
  },
117
112
  handleCancel: () => {
118
- m(P.length < 1 ? "INITIAL" : "LIST"), l(null);
113
+ m(g.length < 1 ? "INITIAL" : "LIST"), l(null);
119
114
  },
120
- handleDelete: Y,
115
+ handleDelete: F,
121
116
  handleEdit: (r) => {
122
117
  m("EDIT"), l(r);
123
118
  },
@@ -125,21 +120,21 @@ const ne = ({ employeeId: n, className: d, dictionary: a }) => {
125
120
  i(s.EMPLOYEE_DEDUCTION_DONE);
126
121
  }
127
122
  },
128
- children: u === "INITIAL" ? /* @__PURE__ */ t(O, { ...I, children: /* @__PURE__ */ C(S, { onSubmit: I.handleSubmit(A), children: [
129
- /* @__PURE__ */ t(b, {}),
130
- /* @__PURE__ */ t(X, {}),
131
- /* @__PURE__ */ t(_, {})
132
- ] }) }) : /* @__PURE__ */ t(O, { ...E, children: /* @__PURE__ */ C(S, { onSubmit: E.handleSubmit(A), children: [
133
- /* @__PURE__ */ t(b, {}),
134
- /* @__PURE__ */ t($, {}),
135
- /* @__PURE__ */ t(Z, {}),
136
- /* @__PURE__ */ t(_, {})
123
+ children: u === "INITIAL" ? /* @__PURE__ */ t(C, { ...I, children: /* @__PURE__ */ A(L, { onSubmit: I.handleSubmit(v), children: [
124
+ /* @__PURE__ */ t(S, {}),
125
+ /* @__PURE__ */ t(K, {}),
126
+ /* @__PURE__ */ t(N, {})
127
+ ] }) }) : /* @__PURE__ */ t(C, { ...E, children: /* @__PURE__ */ A(L, { onSubmit: E.handleSubmit(v), children: [
128
+ /* @__PURE__ */ t(S, {}),
129
+ /* @__PURE__ */ t(W, {}),
130
+ /* @__PURE__ */ t(Q, {}),
131
+ /* @__PURE__ */ t(N, {})
137
132
  ] }) })
138
133
  }
139
134
  ) });
140
- }, Se = () => {
141
- const { employeeId: n, onEvent: d } = ee(), { t: a } = q("common");
142
- if (!n)
135
+ }, Oe = () => {
136
+ const { employeeId: o, onEvent: d } = X(), { t: a } = U("common");
137
+ if (!o)
143
138
  throw new Error(
144
139
  a("errors.missingParamsOrContext", {
145
140
  component: "Deductions",
@@ -147,11 +142,11 @@ const ne = ({ employeeId: n, className: d, dictionary: a }) => {
147
142
  provider: "FlowProvider"
148
143
  })
149
144
  );
150
- return /* @__PURE__ */ t(te, { employeeId: n, onEvent: d });
145
+ return /* @__PURE__ */ t(Z, { employeeId: o, onEvent: d });
151
146
  };
152
147
  export {
153
- te as Deductions,
154
- Se as DeductionsContextual,
155
- ne as Root
148
+ Z as Deductions,
149
+ Oe as DeductionsContextual,
150
+ $ as Root
156
151
  };
157
152
  //# sourceMappingURL=Deductions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Deductions.js","sources":["../../../../src/components/Employee/Deductions/Deductions.tsx"],"sourcesContent":["import { useTranslation } from 'react-i18next'\nimport { useEffect, useMemo, useState } from 'react'\nimport { z } from 'zod'\nimport { FormProvider, useForm, type SubmitHandler } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport {\n useGarnishmentsListSuspense,\n invalidateGarnishmentsList,\n} from '@gusto/embedded-api/react-query/garnishmentsList'\nimport { type Garnishment } 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 { useQueryClient } from '@tanstack/react-query'\nimport type { OnboardingContextInterface } from '../OnboardingFlow/OnboardingFlow'\nimport {\n type DeductionInputs,\n type DeductionPayload,\n DeductionSchema,\n DeductionsProvider,\n type MODE,\n} from './useDeductions'\nimport {\n useBase,\n BaseComponent,\n type BaseComponentInterface,\n type CommonComponentInterface,\n} from '@/components/Base'\nimport { Form } from '@/components/Common/Form'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Actions } from '@/components/Employee/Deductions/Actions'\nimport { IncludeDeductionsForm } from '@/components/Employee/Deductions/IncludeDeductionsForm'\nimport { Head } from '@/components/Employee/Deductions/Head'\nimport { DeductionForm } from '@/components/Employee/Deductions/DeductionForm'\nimport { DeductionsList } from '@/components/Employee/Deductions/DeductionsList'\nimport { useFlow } from '@/components/Flow/useFlow'\nimport { useComponentDictionary } from '@/i18n/I18n'\n\ninterface DeductionsProps extends CommonComponentInterface<'Employee.Deductions'> {\n employeeId: string\n}\n\nconst IncludeDeductionsSchema = z.object({ includeDeductions: z.enum(['Yes', 'No']) })\nexport type IncludeDeductionsPayload = z.output<typeof IncludeDeductionsSchema>\n\nexport function Deductions(props: DeductionsProps & BaseComponentInterface) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\nexport const Root = ({ employeeId, className, dictionary }: DeductionsProps) => {\n const { onEvent, baseSubmitHandler } = useBase()\n const queryClient = useQueryClient()\n useComponentDictionary('Employee.Deductions', dictionary)\n\n const { data } = useGarnishmentsListSuspense({ employeeId })\n const deductions = data.garnishmentList!\n\n // Used for deletion or edit of deduction\n const { mutateAsync: updateDeduction, isPending: isPendingUpdate } =\n useGarnishmentsUpdateMutation({\n onSettled: () => invalidateGarnishmentsList(queryClient, [employeeId]),\n })\n const { mutateAsync: createDeduction, isPending: isPendingCreate } =\n useGarnishmentsCreateMutation({\n onSettled: () => invalidateGarnishmentsList(queryClient, [employeeId]),\n })\n\n const activeDeductions = deductions.filter(deduction => deduction.active)\n const [mode, setMode] = useState<MODE>(activeDeductions.length < 1 ? 'INITIAL' : 'LIST')\n const [currentDeduction, setCurrentDeduction] = useState<Garnishment | null>(null)\n useI18n('Employee.Deductions')\n\n const defaultValues: DeductionInputs = useMemo(() => {\n return {\n amount: currentDeduction?.amount ? Number(currentDeduction.amount) : 0,\n description: currentDeduction?.description ?? '',\n times: currentDeduction?.times ?? null,\n recurring: currentDeduction?.recurring?.toString() ?? 'true',\n annualMaximum: currentDeduction?.annualMaximum\n ? Number(currentDeduction.annualMaximum)\n : null,\n payPeriodMaximum: currentDeduction?.payPeriodMaximum\n ? Number(currentDeduction.payPeriodMaximum)\n : null,\n deductAsPercentage: currentDeduction?.deductAsPercentage?.toString() ?? 'true',\n active: true,\n courtOrdered: currentDeduction?.courtOrdered ?? false,\n } as DeductionInputs\n }, [currentDeduction])\n\n const includeDeductionsFormMethods = useForm<IncludeDeductionsPayload>({\n // resolver: zodResolver(IncludeDeductionsSchema),\n defaultValues: { includeDeductions: 'No' },\n })\n\n const formMethods = useForm<DeductionInputs, unknown, DeductionPayload>({\n resolver: zodResolver(DeductionSchema),\n defaultValues,\n })\n\n const { reset: resetForm } = formMethods\n\n useEffect(() => {\n resetForm(defaultValues)\n }, [currentDeduction, defaultValues, resetForm, mode])\n\n const handleDelete = async (deduction: Garnishment) => {\n await baseSubmitHandler(deduction, async payload => {\n //Deletion of deduction is simply updating it with active: false\n const { garnishment } = await updateDeduction({\n request: {\n garnishmentId: payload.uuid,\n requestBody: {\n ...payload,\n totalAmount: payload.totalAmount ?? undefined,\n active: false,\n version: payload.version as string,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DELETED, garnishment)\n })\n }\n const onSubmit: SubmitHandler<DeductionPayload | IncludeDeductionsPayload> = async data => {\n await baseSubmitHandler(data, async payload => {\n if ('includeDeductions' in payload) {\n if (payload.includeDeductions === 'Yes') {\n setMode('ADD')\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_ADD)\n } else {\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DONE)\n return\n }\n }\n if (!('includeDeductions' in payload)) {\n if (mode === 'ADD') {\n const { garnishment: createDeductionResponse } = await createDeduction({\n request: {\n employeeId: employeeId,\n requestBody: { ...payload, times: payload.recurring ? null : 1 },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_CREATED, createDeductionResponse)\n } else if (mode === 'EDIT') {\n const { garnishment: updateDeductionResponse } = await updateDeduction({\n request: {\n garnishmentId: currentDeduction?.uuid ?? '',\n requestBody: {\n ...payload,\n version: currentDeduction?.version as string,\n times: payload.recurring ? null : 1,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_UPDATED, updateDeductionResponse)\n setCurrentDeduction(null)\n }\n setMode('LIST')\n }\n })\n }\n const handleAdd = () => {\n setMode('ADD')\n }\n const handleCancel = () => {\n setMode(activeDeductions.length < 1 ? 'INITIAL' : 'LIST')\n setCurrentDeduction(null)\n }\n const handleEdit = (deduction: Garnishment) => {\n setMode('EDIT')\n setCurrentDeduction(deduction)\n }\n const handlePassthrough = () => {\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DONE)\n }\n return (\n <section className={className}>\n <DeductionsProvider\n value={{\n isPending: isPendingCreate || isPendingUpdate,\n employeeId,\n mode,\n deductions,\n handleAdd,\n handleCancel,\n handleDelete,\n handleEdit,\n handlePassthrough,\n }}\n >\n {mode === 'INITIAL' ? (\n <FormProvider {...includeDeductionsFormMethods}>\n <Form onSubmit={includeDeductionsFormMethods.handleSubmit(onSubmit)}>\n <Head />\n <IncludeDeductionsForm />\n <Actions />\n </Form>\n </FormProvider>\n ) : (\n <FormProvider {...formMethods}>\n <Form onSubmit={formMethods.handleSubmit(onSubmit)}>\n <Head />\n <DeductionsList />\n <DeductionForm />\n <Actions />\n </Form>\n </FormProvider>\n )}\n </DeductionsProvider>\n </section>\n )\n}\n\nexport const DeductionsContextual = () => {\n const { employeeId, onEvent } = useFlow<OnboardingContextInterface>()\n const { t } = useTranslation('common')\n\n if (!employeeId) {\n throw new Error(\n t('errors.missingParamsOrContext', {\n component: 'Deductions',\n param: 'employeeId',\n provider: 'FlowProvider',\n }),\n )\n }\n return <Deductions employeeId={employeeId} onEvent={onEvent} />\n}\n"],"names":["z","Deductions","props","jsx","BaseComponent","Root","employeeId","className","dictionary","onEvent","baseSubmitHandler","useBase","queryClient","useQueryClient","useComponentDictionary","data","useGarnishmentsListSuspense","deductions","updateDeduction","isPendingUpdate","useGarnishmentsUpdateMutation","invalidateGarnishmentsList","createDeduction","isPendingCreate","useGarnishmentsCreateMutation","activeDeductions","deduction","mode","setMode","useState","currentDeduction","setCurrentDeduction","useI18n","defaultValues","useMemo","includeDeductionsFormMethods","useForm","formMethods","zodResolver","DeductionSchema","resetForm","useEffect","handleDelete","payload","garnishment","componentEvents","onSubmit","createDeductionResponse","updateDeductionResponse","DeductionsProvider","FormProvider","jsxs","Form","Head","IncludeDeductionsForm","Actions","DeductionsList","DeductionForm","DeductionsContextual","useFlow","t","useTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0CgCA,EAAE,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AA,QACjD;AAAA,MAcM;AAAA,MAEC,UAASlB,MAAA,YACP,gBAAAxB,EAAA+C,GAAA,EAAc,GAAGf,GAChB,UAAC,gBAAAgB,EAAAC,GAAA,EAAK,UAAUjB,EAA6B,aAAaW,CAAQ,GAChE,UAAA;AAAA,QAAA,gBAAA3C,EAACkD,GAAK,EAAA;AAAA,0BACLC,GAAsB,EAAA;AAAA,0BACtBC,GAAQ,CAAA,CAAA;AAAA,MAAA,EACX,CAAA,EACF,CAAA,IAEC,gBAAApD,EAAA+C,GAAA,EAAc,GAAGb,GAChB,UAAC,gBAAAc,EAAAC,GAAA,EAAK,UAAUf,EAAY,aAAaS,CAAQ,GAC/C,UAAA;AAAA,QAAA,gBAAA3C,EAACkD,GAAK,EAAA;AAAA,0BACLG,GAAe,EAAA;AAAA,0BACfC,GAAc,EAAA;AAAA,0BACdF,GAAQ,CAAA,CAAA;AAAA,MAAA,EAAA,CACX,EACF,CAAA;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ,GAEaG,KAAuB,MAAM;AACxC,QAAM,EAAE,YAAApD,GAAY,SAAAG,EAAQ,IAAIkD,GAAoC,GAC9D,EAAE,GAAAC,EAAA,IAAMC,EAAe,QAAQ;AAErC,MAAI,CAACvD;AACH,UAAM,IAAI;AAAA,MACRsD,EAAE,iCAAiC;AAAA,QACjC,WAAW;AAAA,QACX,OAAO;AAAA,QACP,UAAU;AAAA,MACX,CAAA;AAAA,IACH;AAEK,SAAA,gBAAAzD,EAACF,IAAW,EAAA,YAAAK,GAAwB,SAAAG,EAAkB,CAAA;AAC/D;"}
1
+ {"version":3,"file":"Deductions.js","sources":["../../../../src/components/Employee/Deductions/Deductions.tsx"],"sourcesContent":["import { useTranslation } from 'react-i18next'\nimport { useEffect, useMemo, useState } from 'react'\nimport { z } from 'zod'\nimport { FormProvider, useForm, type SubmitHandler } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useGarnishmentsListSuspense } from '@gusto/embedded-api/react-query/garnishmentsList'\nimport { type Garnishment } 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 type { OnboardingContextInterface } from '../OnboardingFlow/OnboardingFlow'\nimport {\n type DeductionInputs,\n type DeductionPayload,\n DeductionSchema,\n DeductionsProvider,\n type MODE,\n} from './useDeductions'\nimport {\n useBase,\n BaseComponent,\n type BaseComponentInterface,\n type CommonComponentInterface,\n} from '@/components/Base'\nimport { Form } from '@/components/Common/Form'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Actions } from '@/components/Employee/Deductions/Actions'\nimport { IncludeDeductionsForm } from '@/components/Employee/Deductions/IncludeDeductionsForm'\nimport { Head } from '@/components/Employee/Deductions/Head'\nimport { DeductionForm } from '@/components/Employee/Deductions/DeductionForm'\nimport { DeductionsList } from '@/components/Employee/Deductions/DeductionsList'\nimport { useFlow } from '@/components/Flow/useFlow'\nimport { useComponentDictionary } from '@/i18n/I18n'\n\ninterface DeductionsProps extends CommonComponentInterface<'Employee.Deductions'> {\n employeeId: string\n}\n\nconst IncludeDeductionsSchema = z.object({ includeDeductions: z.enum(['Yes', 'No']) })\nexport type IncludeDeductionsPayload = z.output<typeof IncludeDeductionsSchema>\n\nexport function Deductions(props: DeductionsProps & BaseComponentInterface) {\n return (\n <BaseComponent {...props}>\n <Root {...props}>{props.children}</Root>\n </BaseComponent>\n )\n}\nexport const Root = ({ employeeId, className, dictionary }: DeductionsProps) => {\n const { onEvent, baseSubmitHandler } = useBase()\n useComponentDictionary('Employee.Deductions', dictionary)\n\n const { data } = useGarnishmentsListSuspense({ employeeId })\n const deductions = data.garnishmentList!\n\n // Used for deletion or edit of deduction\n const { mutateAsync: updateDeduction, isPending: isPendingUpdate } =\n useGarnishmentsUpdateMutation()\n const { mutateAsync: createDeduction, isPending: isPendingCreate } =\n useGarnishmentsCreateMutation()\n\n const activeDeductions = deductions.filter(deduction => deduction.active)\n const [mode, setMode] = useState<MODE>(activeDeductions.length < 1 ? 'INITIAL' : 'LIST')\n const [currentDeduction, setCurrentDeduction] = useState<Garnishment | null>(null)\n useI18n('Employee.Deductions')\n\n const defaultValues: DeductionInputs = useMemo(() => {\n return {\n amount: currentDeduction?.amount ? Number(currentDeduction.amount) : 0,\n description: currentDeduction?.description ?? '',\n times: currentDeduction?.times ?? null,\n recurring: currentDeduction?.recurring?.toString() ?? 'true',\n annualMaximum: currentDeduction?.annualMaximum\n ? Number(currentDeduction.annualMaximum)\n : null,\n payPeriodMaximum: currentDeduction?.payPeriodMaximum\n ? Number(currentDeduction.payPeriodMaximum)\n : null,\n deductAsPercentage: currentDeduction?.deductAsPercentage?.toString() ?? 'true',\n active: true,\n courtOrdered: currentDeduction?.courtOrdered ?? false,\n } as DeductionInputs\n }, [currentDeduction])\n\n const includeDeductionsFormMethods = useForm<IncludeDeductionsPayload>({\n // resolver: zodResolver(IncludeDeductionsSchema),\n defaultValues: { includeDeductions: 'No' },\n })\n\n const formMethods = useForm<DeductionInputs, unknown, DeductionPayload>({\n resolver: zodResolver(DeductionSchema),\n defaultValues,\n })\n\n const { reset: resetForm } = formMethods\n\n useEffect(() => {\n resetForm(defaultValues)\n }, [currentDeduction, defaultValues, resetForm, mode])\n\n const handleDelete = async (deduction: Garnishment) => {\n await baseSubmitHandler(deduction, async payload => {\n //Deletion of deduction is simply updating it with active: false\n const { garnishment } = await updateDeduction({\n request: {\n garnishmentId: payload.uuid,\n requestBody: {\n ...payload,\n totalAmount: payload.totalAmount ?? undefined,\n active: false,\n version: payload.version as string,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DELETED, garnishment)\n })\n }\n const onSubmit: SubmitHandler<DeductionPayload | IncludeDeductionsPayload> = async data => {\n await baseSubmitHandler(data, async payload => {\n if ('includeDeductions' in payload) {\n if (payload.includeDeductions === 'Yes') {\n setMode('ADD')\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_ADD)\n } else {\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DONE)\n return\n }\n }\n if (!('includeDeductions' in payload)) {\n if (mode === 'ADD') {\n const { garnishment: createDeductionResponse } = await createDeduction({\n request: {\n employeeId: employeeId,\n requestBody: { ...payload, times: payload.recurring ? null : 1 },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_CREATED, createDeductionResponse)\n } else if (mode === 'EDIT') {\n const { garnishment: updateDeductionResponse } = await updateDeduction({\n request: {\n garnishmentId: currentDeduction?.uuid ?? '',\n requestBody: {\n ...payload,\n version: currentDeduction?.version as string,\n times: payload.recurring ? null : 1,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_UPDATED, updateDeductionResponse)\n setCurrentDeduction(null)\n }\n setMode('LIST')\n }\n })\n }\n const handleAdd = () => {\n setMode('ADD')\n }\n const handleCancel = () => {\n setMode(activeDeductions.length < 1 ? 'INITIAL' : 'LIST')\n setCurrentDeduction(null)\n }\n const handleEdit = (deduction: Garnishment) => {\n setMode('EDIT')\n setCurrentDeduction(deduction)\n }\n const handlePassthrough = () => {\n onEvent(componentEvents.EMPLOYEE_DEDUCTION_DONE)\n }\n return (\n <section className={className}>\n <DeductionsProvider\n value={{\n isPending: isPendingCreate || isPendingUpdate,\n employeeId,\n mode,\n deductions,\n handleAdd,\n handleCancel,\n handleDelete,\n handleEdit,\n handlePassthrough,\n }}\n >\n {mode === 'INITIAL' ? (\n <FormProvider {...includeDeductionsFormMethods}>\n <Form onSubmit={includeDeductionsFormMethods.handleSubmit(onSubmit)}>\n <Head />\n <IncludeDeductionsForm />\n <Actions />\n </Form>\n </FormProvider>\n ) : (\n <FormProvider {...formMethods}>\n <Form onSubmit={formMethods.handleSubmit(onSubmit)}>\n <Head />\n <DeductionsList />\n <DeductionForm />\n <Actions />\n </Form>\n </FormProvider>\n )}\n </DeductionsProvider>\n </section>\n )\n}\n\nexport const DeductionsContextual = () => {\n const { employeeId, onEvent } = useFlow<OnboardingContextInterface>()\n const { t } = useTranslation('common')\n\n if (!employeeId) {\n throw new Error(\n t('errors.missingParamsOrContext', {\n component: 'Deductions',\n param: 'employeeId',\n provider: 'FlowProvider',\n }),\n )\n }\n return <Deductions employeeId={employeeId} onEvent={onEvent} />\n}\n"],"names":["z","Deductions","props","jsx","BaseComponent","Root","employeeId","className","dictionary","onEvent","baseSubmitHandler","useBase","useComponentDictionary","data","useGarnishmentsListSuspense","deductions","updateDeduction","isPendingUpdate","useGarnishmentsUpdateMutation","createDeduction","isPendingCreate","useGarnishmentsCreateMutation","activeDeductions","deduction","mode","setMode","useState","currentDeduction","setCurrentDeduction","useI18n","defaultValues","useMemo","includeDeductionsFormMethods","useForm","formMethods","zodResolver","DeductionSchema","resetForm","useEffect","handleDelete","payload","garnishment","componentEvents","onSubmit","createDeductionResponse","updateDeductionResponse","DeductionsProvider","FormProvider","jsxs","Form","Head","IncludeDeductionsForm","Actions","DeductionsList","DeductionForm","DeductionsContextual","useFlow","t","useTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCgCA,EAAE,OAAO,EAAE,mBAAmBA,EAAE,KAAK,CAAC,OAAO,IAAI,CAAC,EAAG,CAAA;AAG9E,SAASC,EAAWC,GAAiD;AAExE,SAAA,gBAAAC,EAACC,GAAe,EAAA,GAAGF,GACjB,UAAA,gBAAAC,EAACE,KAAM,GAAGH,GAAQ,UAAMA,EAAA,SAAA,CAAS,EACnC,CAAA;AAEJ;AACO,MAAMG,IAAO,CAAC,EAAE,YAAAC,GAAY,WAAAC,GAAW,YAAAC,QAAkC;AAC9E,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAkB,IAAIC,EAAQ;AAC/C,EAAAC,EAAuB,uBAAuBJ,CAAU;AAExD,QAAM,EAAE,MAAAK,EAAK,IAAIC,EAA4B,EAAE,YAAAR,GAAY,GACrDS,IAAaF,EAAK,iBAGlB,EAAE,aAAaG,GAAi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,IAAI+C,EAAoC,GAC9D,EAAE,GAAAC,EAAA,IAAMC,EAAe,QAAQ;AAErC,MAAI,CAACpD;AACH,UAAM,IAAI;AAAA,MACRmD,EAAE,iCAAiC;AAAA,QACjC,WAAW;AAAA,QACX,OAAO;AAAA,QACP,UAAU;AAAA,MACX,CAAA;AAAA,IACH;AAEK,SAAA,gBAAAtD,EAACF,GAAW,EAAA,YAAAK,GAAwB,SAAAG,EAAkB,CAAA;AAC/D;"}
@@ -1,60 +1,54 @@
1
1
  import { jsx as o, jsxs as x, Fragment as b } from "react/jsx-runtime";
2
- import { invalidateEmployeeFormsList as w } from "@gusto/embedded-api/react-query/employeeFormsList";
3
- import { useEmployeeFormsGetPdfSuspense as B } from "@gusto/embedded-api/react-query/employeeFormsGetPdf";
4
- import { useEmployeeFormsSignMutation as C } from "@gusto/embedded-api/react-query/employeeFormsSign";
5
- import { useEmployeeFormsGetSuspense as A } from "@gusto/embedded-api/react-query/employeeFormsGet";
6
- import { useQueryClient as q } from "@tanstack/react-query";
2
+ import { useEmployeeFormsGetPdfSuspense as y } from "@gusto/embedded-api/react-query/employeeFormsGetPdf";
3
+ import { useEmployeeFormsSignMutation as B } from "@gusto/embedded-api/react-query/employeeFormsSign";
4
+ import { useEmployeeFormsGetSuspense as w } from "@gusto/embedded-api/react-query/employeeFormsGet";
7
5
  import { Form as u } from "./Form.js";
8
6
  import { Head as a } from "./Head.js";
9
7
  import { Actions as c } from "./Actions.js";
10
8
  import { Preview as f } from "./Preview.js";
11
- import { SignatureFormProvider as G } from "./useSignatureForm.js";
12
- import { BaseComponent as H } from "../../../Base/Base.js";
13
- import { useBase as L } from "../../../Base/useBase.js";
14
- import { useI18n as M } from "../../../../i18n/I18n.js";
9
+ import { SignatureFormProvider as A } from "./useSignatureForm.js";
10
+ import { BaseComponent as C } from "../../../Base/Base.js";
11
+ import { useBase as G } from "../../../Base/useBase.js";
12
+ import { useI18n as H } from "../../../../i18n/I18n.js";
15
13
  import { componentEvents as s } from "../../../../shared/constants.js";
16
- import { Flex as R } from "../../../Common/Flex/Flex.js";
17
- import { SignatureForm as j } from "../../../Common/SignatureForm/SignatureForm.js";
18
- function e(r) {
19
- return /* @__PURE__ */ o(H, { ...r, children: /* @__PURE__ */ o(k, { ...r }) });
14
+ import { Flex as M } from "../../../Common/Flex/Flex.js";
15
+ import { SignatureForm as R } from "../../../Common/SignatureForm/SignatureForm.js";
16
+ function n(r) {
17
+ return /* @__PURE__ */ o(C, { ...r, children: /* @__PURE__ */ o(j, { ...r }) });
20
18
  }
21
- function k({ employeeId: r, formId: d, className: l, children: n }) {
22
- M("Employee.DocumentSigner");
23
- const { onEvent: i, baseSubmitHandler: p } = L(), g = q(), { data: F } = A({ employeeId: r, formId: d }), t = F.form, {
24
- data: { formPdf: S }
25
- } = B({ employeeId: r, formId: t.uuid }), E = S.documentUrl, { mutateAsync: h, isPending: P } = C({
26
- onSettled: async () => {
27
- await w(g, [r]);
28
- }
29
- });
30
- return /* @__PURE__ */ o("section", { className: l, children: /* @__PURE__ */ o(
31
- G,
19
+ function j({ employeeId: r, formId: d, className: p, children: t }) {
20
+ H("Employee.DocumentSigner");
21
+ const { onEvent: m, baseSubmitHandler: l } = G(), { data: g } = w({ employeeId: r, formId: d }), e = g.form, {
22
+ data: { formPdf: F }
23
+ } = y({ employeeId: r, formId: e.uuid }), S = F.documentUrl, { mutateAsync: E, isPending: h } = B();
24
+ return /* @__PURE__ */ o("section", { className: p, children: /* @__PURE__ */ o(
25
+ A,
32
26
  {
33
27
  value: {
34
- pdfUrl: E,
28
+ pdfUrl: S,
35
29
  handleBack: () => {
36
- i(s.CANCEL);
30
+ m(s.CANCEL);
37
31
  },
38
- form: t,
39
- isPending: P
32
+ form: e,
33
+ isPending: h
40
34
  },
41
- children: /* @__PURE__ */ o(j, { onSubmit: async (y) => {
42
- await p(y, async (m) => {
43
- if (t.uuid) {
44
- const { form: v } = await h({
35
+ children: /* @__PURE__ */ o(R, { onSubmit: async (P) => {
36
+ await l(P, async (i) => {
37
+ if (e.uuid) {
38
+ const { form: v } = await E({
45
39
  request: {
46
40
  employeeId: r,
47
- formId: t.uuid,
41
+ formId: e.uuid,
48
42
  requestBody: {
49
- signatureText: m.signature,
50
- agree: m.confirmSignature
43
+ signatureText: i.signature,
44
+ agree: i.confirmSignature
51
45
  }
52
46
  }
53
47
  });
54
- i(s.EMPLOYEE_SIGN_FORM, v);
48
+ m(s.EMPLOYEE_SIGN_FORM, v);
55
49
  }
56
50
  });
57
- }, children: /* @__PURE__ */ o(R, { flexDirection: "column", children: n || /* @__PURE__ */ x(b, { children: [
51
+ }, children: /* @__PURE__ */ o(M, { flexDirection: "column", children: t || /* @__PURE__ */ x(b, { children: [
58
52
  /* @__PURE__ */ o(a, {}),
59
53
  /* @__PURE__ */ o(f, {}),
60
54
  /* @__PURE__ */ o(u, {}),
@@ -63,11 +57,11 @@ function k({ employeeId: r, formId: d, className: l, children: n }) {
63
57
  }
64
58
  ) });
65
59
  }
66
- e.Head = a;
67
- e.Preview = f;
68
- e.Form = u;
69
- e.Actions = c;
60
+ n.Head = a;
61
+ n.Preview = f;
62
+ n.Form = u;
63
+ n.Actions = c;
70
64
  export {
71
- e as SignatureForm
65
+ n as SignatureForm
72
66
  };
73
67
  //# sourceMappingURL=SignatureForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SignatureForm.js","sources":["../../../../../src/components/Employee/DocumentSigner/SignatureForm/SignatureForm.tsx"],"sourcesContent":["import { invalidateEmployeeFormsList } from '@gusto/embedded-api/react-query/employeeFormsList'\nimport { useEmployeeFormsGetPdfSuspense } from '@gusto/embedded-api/react-query/employeeFormsGetPdf'\nimport { useEmployeeFormsSignMutation } from '@gusto/embedded-api/react-query/employeeFormsSign'\nimport { useEmployeeFormsGetSuspense } from '@gusto/embedded-api/react-query/employeeFormsGet'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { Form as FormComponent } from './Form'\nimport { Head } from './Head'\nimport { Actions } from './Actions'\nimport { Preview } from './Preview'\nimport { SignatureFormProvider } from './useSignatureForm'\nimport {\n BaseComponent,\n type BaseComponentInterface,\n type CommonComponentInterface,\n} from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Flex } from '@/components/Common'\nimport type { SignatureFormInputs } from '@/components/Common/SignatureForm'\nimport { SignatureForm as SharedSignatureForm } from '@/components/Common/SignatureForm'\n\ninterface SignatureFormProps extends CommonComponentInterface {\n employeeId: string\n formId: string\n}\n\nexport function SignatureForm(props: SignatureFormProps & BaseComponentInterface) {\n return (\n <BaseComponent {...props}>\n <Root {...props} />\n </BaseComponent>\n )\n}\n\nfunction Root({ employeeId, formId, className, children }: SignatureFormProps) {\n useI18n('Employee.DocumentSigner')\n const { onEvent, baseSubmitHandler } = useBase()\n const queryClient = useQueryClient()\n\n const { data } = useEmployeeFormsGetSuspense({ employeeId, formId })\n const form = data.form!\n\n const {\n data: { formPdf },\n } = useEmployeeFormsGetPdfSuspense({ employeeId, formId: form.uuid })\n const pdfUrl = formPdf!.documentUrl\n\n const { mutateAsync: signForm, isPending: isSignFormPending } = useEmployeeFormsSignMutation({\n onSettled: async () => {\n await invalidateEmployeeFormsList(queryClient, [employeeId])\n },\n })\n\n const handleBack = () => {\n onEvent(componentEvents.CANCEL)\n }\n\n const handleSubmit = async (data: SignatureFormInputs) => {\n await baseSubmitHandler(data, async payload => {\n if (form.uuid) {\n const { form: signFormResult } = await signForm({\n request: {\n employeeId,\n formId: form.uuid,\n requestBody: {\n signatureText: payload.signature,\n agree: payload.confirmSignature,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_SIGN_FORM, signFormResult)\n }\n })\n }\n\n return (\n <section className={className}>\n <SignatureFormProvider\n value={{\n pdfUrl,\n handleBack,\n form,\n isPending: isSignFormPending,\n }}\n >\n <SharedSignatureForm onSubmit={handleSubmit}>\n <Flex flexDirection=\"column\">\n {children ? (\n children\n ) : (\n <>\n <Head />\n <Preview />\n <FormComponent />\n <Actions />\n </>\n )}\n </Flex>\n </SharedSignatureForm>\n </SignatureFormProvider>\n </section>\n )\n}\n\nSignatureForm.Head = Head\nSignatureForm.Preview = Preview\nSignatureForm.Form = FormComponent\nSignatureForm.Actions = Actions\n"],"names":["SignatureForm","props","jsx","BaseComponent","Root","employeeId","formId","className","children","useI18n","onEvent","baseSubmitHandler","useBase","queryClient","useQueryClient","data","useEmployeeFormsGetSuspense","form","formPdf","useEmployeeFormsGetPdfSuspense","pdfUrl","signForm","isSignFormPending","useEmployeeFormsSignMutation","invalidateEmployeeFormsList","SignatureFormProvider","componentEvents","SharedSignatureForm","payload","signFormResult","Flex","jsxs","Fragment","Head","Preview","FormComponent","Actions"],"mappings":";;;;;;;;;;;;;;;;;AA2BO,SAASA,EAAcC,GAAoD;AAE9E,SAAA,gBAAAC,EAACC,KAAe,GAAGF,GACjB,4BAACG,GAAM,EAAA,GAAGH,GAAO,EACnB,CAAA;AAEJ;AAEA,SAASG,EAAK,EAAE,YAAAC,GAAY,QAAAC,GAAQ,WAAAC,GAAW,UAAAC,KAAgC;AAC7E,EAAAC,EAAQ,yBAAyB;AACjC,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAkB,IAAIC,EAAQ,GACzCC,IAAcC,EAAe,GAE7B,EAAE,MAAAC,EAAK,IAAIC,EAA4B,EAAE,YAAAX,GAAY,QAAAC,GAAQ,GAC7DW,IAAOF,EAAK,MAEZ;AAAA,IACJ,MAAM,EAAE,SAAAG,EAAQ;AAAA,EAAA,IACdC,EAA+B,EAAE,YAAAd,GAAY,QAAQY,EAAK,MAAM,GAC9DG,IAASF,EAAS,aAElB,EAAE,aAAaG,GAAU,WAAWC,EAAA,IAAsBC,EAA6B;AAAA,IAC3F,WAAW,YAAY;AACrB,YAAMC,EAA4BX,GAAa,CAACR,CAAU,CAAC;AAAA,IAAA;AAAA,EAC7D,CACD;AAyBC,SAAA,gBAAAH,EAAC,aAAQ,WAAAK,GACP,UAAA,gBAAAL;AAAA,IAACuB;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,QAAAL;AAAA,QACA,YA3BW,MAAM;AACvB,UAAAV,EAAQgB,EAAgB,MAAM;AAAA,QAChC;AAAA,QA0BQ,MAAAT;AAAA,QACA,WAAWK;AAAA,MACb;AAAA,MAEA,UAAA,gBAAApB,EAACyB,GAAoB,EAAA,UA5BN,OAAOZ,MAA8B;AAClD,cAAAJ,EAAkBI,GAAM,OAAMa,MAAW;AAC7C,cAAIX,EAAK,MAAM;AACb,kBAAM,EAAE,MAAMY,EAAe,IAAI,MAAMR,EAAS;AAAA,cAC9C,SAAS;AAAA,gBACP,YAAAhB;AAAA,gBACA,QAAQY,EAAK;AAAA,gBACb,aAAa;AAAA,kBACX,eAAeW,EAAQ;AAAA,kBACvB,OAAOA,EAAQ;AAAA,gBAAA;AAAA,cACjB;AAAA,YACF,CACD;AACO,YAAAlB,EAAAgB,EAAgB,oBAAoBG,CAAc;AAAA,UAAA;AAAA,QAC5D,CACD;AAAA,MACH,GAaQ,UAAA,gBAAA3B,EAAC4B,KAAK,eAAc,UACjB,UACCtB,KAGE,gBAAAuB,EAAAC,GAAA,EAAA,UAAA;AAAA,QAAA,gBAAA9B,EAAC+B,GAAK,EAAA;AAAA,0BACLC,GAAQ,EAAA;AAAA,0BACRC,GAAc,EAAA;AAAA,0BACdC,GAAQ,CAAA,CAAA;AAAA,MAAA,EACX,CAAA,EAEJ,CAAA,EACF,CAAA;AAAA,IAAA;AAAA,EAAA,GAEJ;AAEJ;AAEApC,EAAc,OAAOiC;AACrBjC,EAAc,UAAUkC;AACxBlC,EAAc,OAAOmC;AACrBnC,EAAc,UAAUoC;"}
1
+ {"version":3,"file":"SignatureForm.js","sources":["../../../../../src/components/Employee/DocumentSigner/SignatureForm/SignatureForm.tsx"],"sourcesContent":["import { useEmployeeFormsGetPdfSuspense } from '@gusto/embedded-api/react-query/employeeFormsGetPdf'\nimport { useEmployeeFormsSignMutation } from '@gusto/embedded-api/react-query/employeeFormsSign'\nimport { useEmployeeFormsGetSuspense } from '@gusto/embedded-api/react-query/employeeFormsGet'\nimport { Form as FormComponent } from './Form'\nimport { Head } from './Head'\nimport { Actions } from './Actions'\nimport { Preview } from './Preview'\nimport { SignatureFormProvider } from './useSignatureForm'\nimport {\n BaseComponent,\n type BaseComponentInterface,\n type CommonComponentInterface,\n} from '@/components/Base/Base'\nimport { useBase } from '@/components/Base/useBase'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { Flex } from '@/components/Common'\nimport type { SignatureFormInputs } from '@/components/Common/SignatureForm'\nimport { SignatureForm as SharedSignatureForm } from '@/components/Common/SignatureForm'\n\ninterface SignatureFormProps extends CommonComponentInterface {\n employeeId: string\n formId: string\n}\n\nexport function SignatureForm(props: SignatureFormProps & BaseComponentInterface) {\n return (\n <BaseComponent {...props}>\n <Root {...props} />\n </BaseComponent>\n )\n}\n\nfunction Root({ employeeId, formId, className, children }: SignatureFormProps) {\n useI18n('Employee.DocumentSigner')\n const { onEvent, baseSubmitHandler } = useBase()\n\n const { data } = useEmployeeFormsGetSuspense({ employeeId, formId })\n const form = data.form!\n\n const {\n data: { formPdf },\n } = useEmployeeFormsGetPdfSuspense({ employeeId, formId: form.uuid })\n const pdfUrl = formPdf!.documentUrl\n\n const { mutateAsync: signForm, isPending: isSignFormPending } = useEmployeeFormsSignMutation()\n\n const handleBack = () => {\n onEvent(componentEvents.CANCEL)\n }\n\n const handleSubmit = async (data: SignatureFormInputs) => {\n await baseSubmitHandler(data, async payload => {\n if (form.uuid) {\n const { form: signFormResult } = await signForm({\n request: {\n employeeId,\n formId: form.uuid,\n requestBody: {\n signatureText: payload.signature,\n agree: payload.confirmSignature,\n },\n },\n })\n onEvent(componentEvents.EMPLOYEE_SIGN_FORM, signFormResult)\n }\n })\n }\n\n return (\n <section className={className}>\n <SignatureFormProvider\n value={{\n pdfUrl,\n handleBack,\n form,\n isPending: isSignFormPending,\n }}\n >\n <SharedSignatureForm onSubmit={handleSubmit}>\n <Flex flexDirection=\"column\">\n {children ? (\n children\n ) : (\n <>\n <Head />\n <Preview />\n <FormComponent />\n <Actions />\n </>\n )}\n </Flex>\n </SharedSignatureForm>\n </SignatureFormProvider>\n </section>\n )\n}\n\nSignatureForm.Head = Head\nSignatureForm.Preview = Preview\nSignatureForm.Form = FormComponent\nSignatureForm.Actions = Actions\n"],"names":["SignatureForm","props","jsx","BaseComponent","Root","employeeId","formId","className","children","useI18n","onEvent","baseSubmitHandler","useBase","data","useEmployeeFormsGetSuspense","form","formPdf","useEmployeeFormsGetPdfSuspense","pdfUrl","signForm","isSignFormPending","useEmployeeFormsSignMutation","SignatureFormProvider","componentEvents","SharedSignatureForm","payload","signFormResult","Flex","jsxs","Fragment","Head","Preview","FormComponent","Actions"],"mappings":";;;;;;;;;;;;;;;AAyBO,SAASA,EAAcC,GAAoD;AAE9E,SAAA,gBAAAC,EAACC,KAAe,GAAGF,GACjB,4BAACG,GAAM,EAAA,GAAGH,GAAO,EACnB,CAAA;AAEJ;AAEA,SAASG,EAAK,EAAE,YAAAC,GAAY,QAAAC,GAAQ,WAAAC,GAAW,UAAAC,KAAgC;AAC7E,EAAAC,EAAQ,yBAAyB;AACjC,QAAM,EAAE,SAAAC,GAAS,mBAAAC,EAAkB,IAAIC,EAAQ,GAEzC,EAAE,MAAAC,EAAK,IAAIC,EAA4B,EAAE,YAAAT,GAAY,QAAAC,GAAQ,GAC7DS,IAAOF,EAAK,MAEZ;AAAA,IACJ,MAAM,EAAE,SAAAG,EAAQ;AAAA,EAAA,IACdC,EAA+B,EAAE,YAAAZ,GAAY,QAAQU,EAAK,MAAM,GAC9DG,IAASF,EAAS,aAElB,EAAE,aAAaG,GAAU,WAAWC,EAAA,IAAsBC,EAA6B;AAyB3F,SAAA,gBAAAnB,EAAC,aAAQ,WAAAK,GACP,UAAA,gBAAAL;AAAA,IAACoB;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,QAAAJ;AAAA,Q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