@gusto/embedded-react-sdk 0.55.2 → 0.55.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/components/Common/FieldLayout/FieldLayout.js +6 -6
  3. package/dist/components/Common/Fieldset/Fieldset.js +6 -6
  4. package/dist/components/Common/HorizontalFieldLayout/HorizontalFieldLayout.js +6 -6
  5. package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js +58 -49
  6. package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js.map +1 -1
  7. package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js +14 -10
  8. package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js.map +1 -1
  9. package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBoxTypes.d.ts +4 -0
  10. package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +5 -3
  11. package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
  12. package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +5 -3
  13. package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
  14. package/dist/components/Company/AssignSignatory/useAssignSignatory.js +7 -5
  15. package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
  16. package/dist/components/Company/BankAccount/BankAccountForm/context.js +5 -3
  17. package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
  18. package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
  19. package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
  20. package/dist/components/Company/DocumentSigner/DocumentList/List.js +11 -8
  21. package/dist/components/Company/DocumentSigner/DocumentList/List.js.map +1 -1
  22. package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +5 -3
  23. package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
  24. package/dist/components/Company/FederalTaxes/useFederalTaxes.js +10 -8
  25. package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
  26. package/dist/components/Company/Industry/Context.js +8 -6
  27. package/dist/components/Company/Industry/Context.js.map +1 -1
  28. package/dist/components/Company/Locations/LocationForm/useLocationForm.js +5 -3
  29. package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
  30. package/dist/components/Company/Locations/LocationsList/useLocationsList.js +5 -3
  31. package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
  32. package/dist/components/Company/OnboardingOverview/context.js +5 -3
  33. package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
  34. package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +5 -3
  35. package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
  36. package/dist/components/Company/StateTaxes/StateTaxesList/context.js +5 -3
  37. package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
  38. package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +5 -3
  39. package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
  40. package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js +116 -116
  41. package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js.map +1 -1
  42. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
  43. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js +19 -19
  44. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
  45. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js +16 -13
  46. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js.map +1 -1
  47. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +5 -3
  48. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
  49. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.d.ts +4 -0
  50. package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.js.map +1 -1
  51. package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +75 -71
  52. package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
  53. package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +137 -138
  54. package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
  55. package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +1 -1
  56. package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
  57. package/dist/components/Payroll/PayrollOverview/PayrollOverview.d.ts +8 -1
  58. package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +174 -161
  59. package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
  60. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.d.ts +2 -1
  61. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js +42 -41
  62. package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js.map +1 -1
  63. package/dist/components/Payroll/helpers.d.ts +0 -15
  64. package/dist/components/Payroll/helpers.js +13 -18
  65. package/dist/components/Payroll/helpers.js.map +1 -1
  66. package/dist/components/Payroll/usePreparedPayrollData.js +10 -8
  67. package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
  68. package/dist/i18n/en/Company.DocumentList.json.js +34 -32
  69. package/dist/i18n/en/Company.DocumentList.json.js.map +1 -1
  70. package/dist/i18n/en/Employee.DocumentSigner.json.js +24 -22
  71. package/dist/i18n/en/Employee.DocumentSigner.json.js.map +1 -1
  72. package/dist/i18n/en/Payroll.PayrollOverview.json.js +5 -5
  73. package/dist/i18n/types.d.ts +311 -1
  74. package/dist/style.css +1 -1
  75. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"usePayrollConfigurationData.js","sources":["../../../../src/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { useEmployeesList } from '@gusto/embedded-api/react-query/employeesList'\nimport { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { payrollsPrepare } from '@gusto/embedded-api/funcs/payrollsPrepare'\nimport { employeesGet } from '@gusto/embedded-api/funcs/employeesGet'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport type { PayrollEmployeeCompensationsType } from '@gusto/embedded-api/models/components/payrollemployeecompensationstype'\nimport type { Employee } from '@gusto/embedded-api/models/components/employee'\nimport type { PayrollPayPeriodType } from '@gusto/embedded-api/models/components/payrollpayperiodtype'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport type { PayrollCategory } from '../payrollTypes'\nimport { derivePayrollCategory } from '../payrollTypes'\nimport type { PaginationControlProps } from '@/components/Common/PaginationControl/PaginationControlTypes'\nimport { usePagination } from '@/hooks/usePagination/usePagination'\n\ninterface UsePayrollConfigurationDataParams {\n companyId: string\n payrollId: string\n isCalculating?: boolean\n excludedEmployeeUuids?: string[]\n}\n\ninterface UsePayrollConfigurationDataReturn {\n employeeCompensations: PayrollEmployeeCompensationsType[]\n employeeDetails: Employee[]\n payPeriod: PayrollPayPeriodType | undefined\n paySchedule: PayScheduleShow | undefined\n payrollCategory: PayrollCategory\n pagination: PaginationControlProps\n isLoading: boolean\n isAlreadyProcessed: boolean\n refetch: () => Promise<void>\n}\n\n/** @internal */\nexport const PREPARE_QUERY_KEY = 'payroll-prepare'\nconst FIVE_MINUTES = 5 * 60 * 1000\nconst PREPARE_MAX_ATTEMPTS = 3\n\nconst isAlreadyProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/** @internal */\nexport function usePayrollConfigurationData({\n companyId,\n payrollId,\n isCalculating = false,\n excludedEmployeeUuids = [],\n}: UsePayrollConfigurationDataParams): UsePayrollConfigurationDataReturn {\n const gustoClient = useGustoEmbeddedContext()\n const queryClient = useQueryClient()\n\n const { currentPage, itemsPerPage, getPaginationProps } = usePagination({\n defaultItemsPerPage: 10,\n })\n const [displayedEmployees, setDisplayedEmployees] = useState<Employee[]>([])\n const [isDataInSync, setIsDataInSync] = useState(false)\n const hasInitialDataRef = useRef(false)\n\n const { data: employeeData, isFetching: isFetchingEmployeeData } = useEmployeesList(\n {\n companyId,\n payrollUuid: payrollId,\n per: itemsPerPage,\n page: currentPage,\n sortBy: 'name',\n },\n { placeholderData: keepPreviousData },\n )\n\n const employeeDataRef = useRef(employeeData)\n employeeDataRef.current = employeeData\n\n const listedEmployeeUuids = useMemo(() => {\n return employeeData?.showEmployees?.map(e => e.uuid) || []\n }, [employeeData?.showEmployees])\n\n const missingExcludedUuids = useMemo(() => {\n const listedSet = new Set(listedEmployeeUuids)\n return excludedEmployeeUuids.filter(uuid => !listedSet.has(uuid))\n }, [excludedEmployeeUuids, listedEmployeeUuids])\n\n const employeeUuids = useMemo(() => {\n if (currentPage === 1) {\n return [...listedEmployeeUuids, ...missingExcludedUuids]\n }\n return listedEmployeeUuids\n }, [listedEmployeeUuids, missingExcludedUuids, currentPage])\n\n const employeeUuidsKey = useMemo(() => employeeUuids.join(','), [employeeUuids])\n\n const {\n data: prepareData,\n error: prepareError,\n isLoading: isPrepareLoading,\n isFetching: isPrepareFetching,\n } = useQuery({\n queryKey: [PREPARE_QUERY_KEY, payrollId, employeeUuidsKey],\n queryFn: async ({ signal }) => {\n const result = await payrollsPrepare(\n gustoClient,\n {\n companyId,\n payrollId,\n sortBy: 'last_name',\n requestBody: {\n employeeUuids,\n },\n },\n { signal },\n )\n\n if (!result.ok) {\n throw result.error\n }\n\n return result.value.payrollPrepared\n },\n enabled: employeeUuids.length > 0 && !isCalculating,\n staleTime: FIVE_MINUTES,\n placeholderData: keepPreviousData,\n // An \"already processed\" prepare failure is terminal — retrying it wastes time. Other\n // errors (network blips, etc.) still get the standard retry treatment.\n retry: (failureCount, error) =>\n !isAlreadyProcessedError(error) && failureCount < PREPARE_MAX_ATTEMPTS,\n })\n\n const isAlreadyProcessed = isAlreadyProcessedError(prepareError)\n\n useEffect(() => {\n return () => {\n void queryClient.cancelQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }\n }, [queryClient, payrollId])\n\n useEffect(() => {\n if (isCalculating) {\n void queryClient.cancelQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }\n }, [isCalculating, queryClient, payrollId])\n\n const excludedUuidsKey = useMemo(() => missingExcludedUuids.join(','), [missingExcludedUuids])\n\n const { data: excludedEmployeeDetails } = useQuery({\n queryKey: ['excluded-employee-details', excludedUuidsKey],\n queryFn: async () => {\n const results = await Promise.all(\n missingExcludedUuids.map(uuid => employeesGet(gustoClient, { employeeId: uuid })),\n )\n const failedResult = results.find(result => !result.ok)\n if (failedResult) {\n throw failedResult.error\n }\n\n return results\n .filter(result => result.ok)\n .map(result => result.value.employee)\n .filter((e): e is Employee => e != null)\n },\n enabled: missingExcludedUuids.length > 0 && !isCalculating,\n staleTime: FIVE_MINUTES,\n })\n\n const syncData = useCallback(() => {\n const currentEmployeeData = employeeDataRef.current\n if (!currentEmployeeData?.showEmployees || !prepareData?.employeeCompensations) {\n setIsDataInSync(false)\n return\n }\n\n const currentUuids = currentEmployeeData.showEmployees.map(e => e.uuid)\n const preparedUuids = new Set(prepareData.employeeCompensations.map(c => c.employeeUuid))\n const allListedInSync =\n currentUuids.length > 0 && currentUuids.every(uuid => preparedUuids.has(uuid))\n\n if (allListedInSync) {\n const mergedEmployees = [...currentEmployeeData.showEmployees]\n if (currentPage === 1 && excludedEmployeeDetails?.length) {\n const listedSet = new Set(currentUuids)\n for (const employee of excludedEmployeeDetails) {\n if (!listedSet.has(employee.uuid)) {\n mergedEmployees.push(employee)\n }\n }\n }\n setDisplayedEmployees(mergedEmployees)\n setIsDataInSync(true)\n hasInitialDataRef.current = true\n } else {\n setIsDataInSync(false)\n }\n }, [prepareData?.employeeCompensations, excludedEmployeeDetails, currentPage])\n\n useEffect(() => {\n syncData()\n }, [syncData])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: prepareData?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!prepareData?.payPeriod?.payScheduleUuid,\n },\n )\n\n const handleRefetch = useCallback(async () => {\n await queryClient.invalidateQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }, [queryClient, payrollId])\n\n const isInitialLoading = isPrepareLoading && !hasInitialDataRef.current\n const isPaginating = isPrepareFetching && hasInitialDataRef.current\n const isPaginationFetching = isFetchingEmployeeData || isPaginating || !isDataInSync\n const isLoading =\n isInitialLoading || isPayScheduleLoading || (!employeeData && isFetchingEmployeeData)\n\n const headers = employeeData?.httpMeta.response.headers ?? new Headers()\n const pagination: PaginationControlProps = getPaginationProps(headers, isPaginationFetching)\n\n return {\n employeeCompensations: prepareData?.employeeCompensations ?? [],\n employeeDetails: displayedEmployees,\n payPeriod: prepareData?.payPeriod,\n paySchedule: payScheduleData?.payScheduleShow,\n payrollCategory: derivePayrollCategory(prepareData ?? {}),\n pagination,\n isLoading,\n isAlreadyProcessed,\n refetch: handleRefetch,\n }\n}\n"],"names":["PREPARE_QUERY_KEY","FIVE_MINUTES","PREPARE_MAX_ATTEMPTS","isAlreadyProcessedError","error","UnprocessableEntityError","e","usePayrollConfigurationData","companyId","payrollId","isCalculating","excludedEmployeeUuids","gustoClient","useGustoEmbeddedContext","queryClient","useQueryClient","currentPage","itemsPerPage","getPaginationProps","usePagination","displayedEmployees","setDisplayedEmployees","useState","isDataInSync","setIsDataInSync","hasInitialDataRef","useRef","employeeData","isFetchingEmployeeData","useEmployeesList","keepPreviousData","employeeDataRef","listedEmployeeUuids","useMemo","missingExcludedUuids","listedSet","uuid","employeeUuids","employeeUuidsKey","prepareData","prepareError","isPrepareLoading","isPrepareFetching","useQuery","signal","result","payrollsPrepare","failureCount","isAlreadyProcessed","useEffect","excludedUuidsKey","excludedEmployeeDetails","results","employeesGet","failedResult","syncData","useCallback","currentEmployeeData","currentUuids","preparedUuids","c","mergedEmployees","employee","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","handleRefetch","isInitialLoading","isPaginating","isPaginationFetching","isLoading","headers","pagination","derivePayrollCategory"],"mappings":";;;;;;;;;;AAqCO,MAAMA,IAAoB,mBAC3BC,IAAe,MAAS,KACxBC,KAAuB,GAEvBC,IAA0B,CAACC,MACzBA,aAAiBC,KAChBD,EAAM,OAAO,KAAK,CAAAE,MAAKA,EAAE,aAAa,mBAAmB,IADP;AAKpD,SAASC,GAA4B;AAAA,EAC1C,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,uBAAAC,IAAwB,CAAA;AAC1B,GAAyE;AACvE,QAAMC,IAAcC,GAAA,GACdC,IAAcC,GAAA,GAEd,EAAE,aAAAC,GAAa,cAAAC,GAAc,oBAAAC,EAAA,IAAuBC,GAAc;AAAA,IACtE,qBAAqB;AAAA,EAAA,CACtB,GACK,CAACC,GAAoBC,CAAqB,IAAIC,EAAqB,CAAA,CAAE,GACrE,CAACC,GAAcC,CAAe,IAAIF,EAAS,EAAK,GAChDG,IAAoBC,EAAO,EAAK,GAEhC,EAAE,MAAMC,GAAc,YAAYC,MAA2BC;AAAA,IACjE;AAAA,MACE,WAAArB;AAAA,MACA,aAAaC;AAAA,MACb,KAAKQ;AAAA,MACL,MAAMD;AAAA,MACN,QAAQ;AAAA,IAAA;AAAA,IAEV,EAAE,iBAAiBc,EAAA;AAAA,EAAiB,GAGhCC,IAAkBL,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AAS,SAAS,WAAW,IAAI,QAAA,GACzD6C,IAAqCtD,EAAmBqD,GAASF,CAAoB;AAE3F,SAAO;AAAA,IACL,uBAAuB9B,GAAa,yBAAyB,CAAA;AAAA,IAC7D,iBAAiBnB;AAAA,IACjB,WAAWmB,GAAa;AAAA,IACxB,aAAawB,GAAiB;AAAA,IAC9B,iBAAiBU,GAAsBlC,KAAe,EAAE;AAAA,IACxD,YAAAiC;AAAA,IACA,WAAAF;AAAA,IACA,oBAAAtB;AAAA,IACA,SAASkB;AAAA,EAAA;AAEb;"}
1
+ {"version":3,"file":"usePayrollConfigurationData.js","sources":["../../../../src/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { useEmployeesList } from '@gusto/embedded-api/react-query/employeesList'\nimport { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { payrollsPrepare } from '@gusto/embedded-api/funcs/payrollsPrepare'\nimport { employeesGet } from '@gusto/embedded-api/funcs/employeesGet'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport type { PayrollEmployeeCompensationsType } from '@gusto/embedded-api/models/components/payrollemployeecompensationstype'\nimport type { Employee } from '@gusto/embedded-api/models/components/employee'\nimport type { PayrollPayPeriodType } from '@gusto/embedded-api/models/components/payrollpayperiodtype'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport type { PayrollCategory } from '../payrollTypes'\nimport { derivePayrollCategory } from '../payrollTypes'\nimport type { PaginationControlProps } from '@/components/Common/PaginationControl/PaginationControlTypes'\nimport { usePagination } from '@/hooks/usePagination/usePagination'\n\ninterface UsePayrollConfigurationDataParams {\n companyId: string\n payrollId: string\n isCalculating?: boolean\n excludedEmployeeUuids?: string[]\n}\n\ninterface UsePayrollConfigurationDataReturn {\n employeeCompensations: PayrollEmployeeCompensationsType[]\n employeeDetails: Employee[]\n payPeriod: PayrollPayPeriodType | undefined\n paySchedule: PayScheduleShow | undefined\n payrollCategory: PayrollCategory\n pagination: PaginationControlProps\n isLoading: boolean\n isAlreadyProcessed: boolean\n refetch: () => Promise<void>\n}\n\n/** @internal */\nexport const PREPARE_QUERY_KEY = 'payroll-prepare'\nconst FIVE_MINUTES = 5 * 60 * 1000\nconst PREPARE_MAX_ATTEMPTS = 3\n\nconst isAlreadyProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/** @internal */\nexport function usePayrollConfigurationData({\n companyId,\n payrollId,\n isCalculating = false,\n excludedEmployeeUuids = [],\n}: UsePayrollConfigurationDataParams): UsePayrollConfigurationDataReturn {\n const gustoClient = useGustoEmbeddedContext()\n const queryClient = useQueryClient()\n\n const { currentPage, itemsPerPage, getPaginationProps } = usePagination({\n defaultItemsPerPage: 25,\n })\n const [displayedEmployees, setDisplayedEmployees] = useState<Employee[]>([])\n const [isDataInSync, setIsDataInSync] = useState(false)\n const hasInitialDataRef = useRef(false)\n\n const { data: employeeData, isFetching: isFetchingEmployeeData } = useEmployeesList(\n {\n companyId,\n payrollUuid: payrollId,\n per: itemsPerPage,\n page: currentPage,\n sortBy: 'name',\n },\n { placeholderData: keepPreviousData },\n )\n\n const employeeDataRef = useRef(employeeData)\n employeeDataRef.current = employeeData\n\n const listedEmployeeUuids = useMemo(() => {\n return employeeData?.showEmployees?.map(e => e.uuid) || []\n }, [employeeData?.showEmployees])\n\n const missingExcludedUuids = useMemo(() => {\n const listedSet = new Set(listedEmployeeUuids)\n return excludedEmployeeUuids.filter(uuid => !listedSet.has(uuid))\n }, [excludedEmployeeUuids, listedEmployeeUuids])\n\n const employeeUuids = useMemo(() => {\n if (currentPage === 1) {\n return [...listedEmployeeUuids, ...missingExcludedUuids]\n }\n return listedEmployeeUuids\n }, [listedEmployeeUuids, missingExcludedUuids, currentPage])\n\n const employeeUuidsKey = useMemo(() => employeeUuids.join(','), [employeeUuids])\n\n const {\n data: prepareData,\n error: prepareError,\n isLoading: isPrepareLoading,\n isFetching: isPrepareFetching,\n } = useQuery({\n queryKey: [PREPARE_QUERY_KEY, payrollId, employeeUuidsKey],\n queryFn: async ({ signal }) => {\n const result = await payrollsPrepare(\n gustoClient,\n {\n companyId,\n payrollId,\n sortBy: 'last_name',\n requestBody: {\n employeeUuids,\n },\n },\n { signal },\n )\n\n if (!result.ok) {\n throw result.error\n }\n\n return result.value.payrollPrepared\n },\n enabled: employeeUuids.length > 0 && !isCalculating,\n staleTime: FIVE_MINUTES,\n placeholderData: keepPreviousData,\n // An \"already processed\" prepare failure is terminal — retrying it wastes time. Other\n // errors (network blips, etc.) still get the standard retry treatment.\n retry: (failureCount, error) =>\n !isAlreadyProcessedError(error) && failureCount < PREPARE_MAX_ATTEMPTS,\n })\n\n const isAlreadyProcessed = isAlreadyProcessedError(prepareError)\n\n useEffect(() => {\n return () => {\n void queryClient.cancelQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }\n }, [queryClient, payrollId])\n\n useEffect(() => {\n if (isCalculating) {\n void queryClient.cancelQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }\n }, [isCalculating, queryClient, payrollId])\n\n const excludedUuidsKey = useMemo(() => missingExcludedUuids.join(','), [missingExcludedUuids])\n\n const { data: excludedEmployeeDetails } = useQuery({\n queryKey: ['excluded-employee-details', excludedUuidsKey],\n queryFn: async () => {\n const results = await Promise.all(\n missingExcludedUuids.map(uuid => employeesGet(gustoClient, { employeeId: uuid })),\n )\n const failedResult = results.find(result => !result.ok)\n if (failedResult) {\n throw failedResult.error\n }\n\n return results\n .filter(result => result.ok)\n .map(result => result.value.employee)\n .filter((e): e is Employee => e != null)\n },\n enabled: missingExcludedUuids.length > 0 && !isCalculating,\n staleTime: FIVE_MINUTES,\n })\n\n const syncData = useCallback(() => {\n const currentEmployeeData = employeeDataRef.current\n if (!currentEmployeeData?.showEmployees || !prepareData?.employeeCompensations) {\n setIsDataInSync(false)\n return\n }\n\n const currentUuids = currentEmployeeData.showEmployees.map(e => e.uuid)\n const preparedUuids = new Set(prepareData.employeeCompensations.map(c => c.employeeUuid))\n const allListedInSync =\n currentUuids.length > 0 && currentUuids.every(uuid => preparedUuids.has(uuid))\n\n if (allListedInSync) {\n const mergedEmployees = [...currentEmployeeData.showEmployees]\n if (currentPage === 1 && excludedEmployeeDetails?.length) {\n const listedSet = new Set(currentUuids)\n for (const employee of excludedEmployeeDetails) {\n if (!listedSet.has(employee.uuid)) {\n mergedEmployees.push(employee)\n }\n }\n }\n setDisplayedEmployees(mergedEmployees)\n setIsDataInSync(true)\n hasInitialDataRef.current = true\n } else {\n setIsDataInSync(false)\n }\n }, [prepareData?.employeeCompensations, excludedEmployeeDetails, currentPage])\n\n useEffect(() => {\n syncData()\n }, [syncData])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: prepareData?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!prepareData?.payPeriod?.payScheduleUuid,\n },\n )\n\n const handleRefetch = useCallback(async () => {\n await queryClient.invalidateQueries({\n queryKey: [PREPARE_QUERY_KEY, payrollId],\n })\n }, [queryClient, payrollId])\n\n const isInitialLoading = isPrepareLoading && !hasInitialDataRef.current\n const isPaginating = isPrepareFetching && hasInitialDataRef.current\n const isPaginationFetching = isFetchingEmployeeData || isPaginating || !isDataInSync\n const isLoading =\n isInitialLoading || isPayScheduleLoading || (!employeeData && isFetchingEmployeeData)\n\n const headers = employeeData?.httpMeta.response.headers ?? new Headers()\n const pagination: PaginationControlProps = getPaginationProps(headers, isPaginationFetching)\n\n return {\n employeeCompensations: prepareData?.employeeCompensations ?? [],\n employeeDetails: displayedEmployees,\n payPeriod: prepareData?.payPeriod,\n paySchedule: payScheduleData?.payScheduleShow,\n payrollCategory: derivePayrollCategory(prepareData ?? {}),\n pagination,\n isLoading,\n isAlreadyProcessed,\n refetch: handleRefetch,\n }\n}\n"],"names":["PREPARE_QUERY_KEY","FIVE_MINUTES","PREPARE_MAX_ATTEMPTS","isAlreadyProcessedError","error","UnprocessableEntityError","e","usePayrollConfigurationData","companyId","payrollId","isCalculating","excludedEmployeeUuids","gustoClient","useGustoEmbeddedContext","queryClient","useQueryClient","currentPage","itemsPerPage","getPaginationProps","usePagination","displayedEmployees","setDisplayedEmployees","useState","isDataInSync","setIsDataInSync","hasInitialDataRef","useRef","employeeData","isFetchingEmployeeData","useEmployeesList","keepPreviousData","employeeDataRef","listedEmployeeUuids","useMemo","missingExcludedUuids","listedSet","uuid","employeeUuids","employeeUuidsKey","prepareData","prepareError","isPrepareLoading","isPrepareFetching","useQuery","signal","result","payrollsPrepare","failureCount","isAlreadyProcessed","useEffect","excludedUuidsKey","excludedEmployeeDetails","results","employeesGet","failedResult","syncData","useCallback","currentEmployeeData","currentUuids","preparedUuids","c","mergedEmployees","employee","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","handleRefetch","isInitialLoading","isPaginating","isPaginationFetching","isLoading","headers","pagination","derivePayrollCategory"],"mappings":";;;;;;;;;;AAqCO,MAAMA,IAAoB,mBAC3BC,IAAe,MAAS,KACxBC,KAAuB,GAEvBC,IAA0B,CAACC,MACzBA,aAAiBC,KAChBD,EAAM,OAAO,KAAK,CAAAE,MAAKA,EAAE,aAAa,mBAAmB,IADP;AAKpD,SAASC,GAA4B;AAAA,EAC1C,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,uBAAAC,IAAwB,CAAA;AAC1B,GAAyE;AACvE,QAAMC,IAAcC,GAAA,GACdC,IAAcC,GAAA,GAEd,EAAE,aAAAC,GAAa,cAAAC,GAAc,oBAAAC,EAAA,IAAuBC,GAAc;AAAA,IACtE,qBAAqB;AAAA,EAAA,CACtB,GACK,CAAC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IAAgBV,EAAY,YAAY;AAC5C,UAAM1C,EAAY,kBAAkB;AAAA,MAClC,UAAU,CAACd,GAAmBS,CAAS;AAAA,IAAA,CACxC;AAAA,EACH,GAAG,CAACK,GAAaL,CAAS,CAAC,GAErB0D,IAAmB1B,KAAoB,CAAChB,EAAkB,SAC1D2C,IAAe1B,KAAqBjB,EAAkB,SACtD4C,IAAuBzC,KAA0BwC,KAAgB,CAAC7C,GAClE+C,IACJH,KAAoBH,KAAyB,CAACrC,KAAgBC,GAE1D2C,IAAU5C,GAAc,SAAS,SAAS,WAAW,IAAI,QAAA,GACzD6C,IAAqCtD,EAAmBqD,GAASF,CAAoB;AAE3F,SAAO;AAAA,IACL,uBAAuB9B,GAAa,yBAAyB,CAAA;AAAA,IAC7D,iBAAiBnB;AAAA,IACjB,WAAWmB,GAAa;AAAA,IACxB,aAAawB,GAAiB;AAAA,IAC9B,iBAAiBU,GAAsBlC,KAAe,EAAE;AAAA,IACxD,YAAAiC;AAAA,IACA,WAAAF;AAAA,IACA,oBAAAtB;AAAA,IACA,SAASkB;AAAA,EAAA;AAEb;"}
@@ -17,6 +17,12 @@ export interface PayrollOverviewProps extends BaseComponentInterface<'Payroll.Pa
17
17
  withReimbursements?: boolean;
18
18
  /** Custom component to replace the default wire details confirmation UI. */
19
19
  ConfirmWireDetailsComponent?: ConfirmWireDetailsComponentType;
20
+ /**
21
+ * Hides the edit and cancel actions, leaving submit and receipt/paystub actions available.
22
+ * Use for a deep link to a specific payroll where editing shouldn't be offered. Defaults to
23
+ * `false`.
24
+ */
25
+ readOnly?: boolean;
20
26
  }
21
27
  /**
22
28
  * Final review screen for a calculated payroll before submission, with submit, cancel,
@@ -28,7 +34,8 @@ export interface PayrollOverviewProps extends BaseComponentInterface<'Payroll.Pa
28
34
  * uncalculated payroll throws. Unresolved submission blockers (e.g. fast-ACH threshold,
29
35
  * wire-in funding) are surfaced inline and the submit action stays disabled until each
30
36
  * blocker has a selected unblock option. While the payroll is processing, the component
31
- * polls until success or failure and emits the corresponding event.
37
+ * polls until success or failure and emits the corresponding event. Pass `readOnly` to hide
38
+ * the edit and cancel actions while keeping submit available.
32
39
  *
33
40
  * @events
34
41
  * | Event | Description | Data |
@@ -1,239 +1,252 @@
1
- import { jsx as l, jsxs as le } from "react/jsx-runtime";
2
- import { usePayrollsSubmitMutation as ce } from "@gusto/embedded-api/react-query/payrollsSubmit";
3
- import { usePayrollsCancelMutation as ue } from "@gusto/embedded-api/react-query/payrollsCancel";
4
- import { usePayrollsGet as me } from "@gusto/embedded-api/react-query/payrollsGet";
5
- import { keepPreviousData as pe } from "@tanstack/react-query";
6
- import { useTranslation as fe } from "react-i18next";
7
- import { useBankAccountsGetSuspense as de } from "@gusto/embedded-api/react-query/bankAccountsGet";
8
- import { useWireInRequestsGet as Pe } from "@gusto/embedded-api/react-query/wireInRequestsGet";
9
- import { useState as u, useEffect as L } from "react";
10
- import { useGustoEmbeddedContext as ye } from "@gusto/embedded-api/react-query/_context";
11
- import { payrollsGetPayStub as be } from "@gusto/embedded-api/funcs/payrollsGetPayStub";
12
- import { useErrorBoundary as Re } from "react-error-boundary";
13
- import { ConfirmWireDetails as we } from "../ConfirmWireDetails/ConfirmWireDetails.js";
14
- import { canCancelPayroll as Se } from "../helpers.js";
15
- import { PrintChecks as Oe } from "../PrintChecks/PrintChecks.js";
16
- import { PayrollOverviewPresentation as ge } from "./PayrollOverviewPresentation.js";
17
- import { PayrollOverviewStatus as m } from "./PayrollOverviewTypes.js";
18
- import { useCompanyPaymentSpeed as he } from "../../../hooks/useCompanyPaymentSpeed.js";
19
- import { PAYROLL_PROCESSING_STATUS as w, componentEvents as c, PAYROLL_RESOLVABLE_SUBMISSION_BLOCKER_TYPES as Le, payrollWireEvents as _e } from "../../../shared/constants.js";
20
- import { BaseComponent as De } from "../../Base/Base.js";
21
- import { useBase as Ce } from "../../Base/useBase.js";
22
- import { useComponentDictionary as ke, useI18n as Ue } from "../../../i18n/I18n.js";
23
- import { readableStreamToBlob as Ee } from "../../../helpers/readableStreamToBlob.js";
24
- import Ae from "../../../hooks/useNumberFormatter.js";
25
- import { useDateFormatter as Be } from "../../../hooks/useDateFormatter.js";
26
- import { useComponentContext as Te } from "../../../contexts/ComponentAdapter/useComponentContext.js";
27
- import { renderErrorList as ve } from "../../../helpers/apiErrorToList.js";
28
- import { Flex as qe } from "../../Common/Flex/Flex.js";
29
- import { usePagination as Ne } from "../../../hooks/usePagination/usePagination.js";
30
- import { PayrollLoading as q } from "../../Common/PayrollLoading/PayrollLoading.js";
31
- const Ie = (s = []) => s.filter(
1
+ import { jsx as l, jsxs as ye } from "react/jsx-runtime";
2
+ import { usePayrollsSubmitMutation as Pe } from "@gusto/embedded-api/react-query/payrollsSubmit";
3
+ import { usePayrollsCancelMutation as be } from "@gusto/embedded-api/react-query/payrollsCancel";
4
+ import { usePayrollsGet as Re } from "@gusto/embedded-api/react-query/payrollsGet";
5
+ import { keepPreviousData as Se } from "@tanstack/react-query";
6
+ import { useTranslation as we } from "react-i18next";
7
+ import { useBankAccountsGetSuspense as he } from "@gusto/embedded-api/react-query/bankAccountsGet";
8
+ import { useWireInRequestsGet as De } from "@gusto/embedded-api/react-query/wireInRequestsGet";
9
+ import { useState as p, useEffect as _ } from "react";
10
+ import { useGustoEmbeddedContext as ge } from "@gusto/embedded-api/react-query/_context";
11
+ import { payrollsGetPayStub as Le } from "@gusto/embedded-api/funcs/payrollsGetPayStub";
12
+ import { useErrorBoundary as _e } from "react-error-boundary";
13
+ import { ConfirmWireDetails as Oe } from "../ConfirmWireDetails/ConfirmWireDetails.js";
14
+ import { canCancelPayroll as Ce } from "../helpers.js";
15
+ import { PrintChecks as ke } from "../PrintChecks/PrintChecks.js";
16
+ import { PayrollOverviewPresentation as Ue } from "./PayrollOverviewPresentation.js";
17
+ import { PayrollOverviewStatus as d } from "./PayrollOverviewTypes.js";
18
+ import { useCompanyPaymentSpeed as Ae } from "../../../hooks/useCompanyPaymentSpeed.js";
19
+ import { PAYROLL_PROCESSING_STATUS as y, componentEvents as c, PAYROLL_RESOLVABLE_SUBMISSION_BLOCKER_TYPES as Ee, payrollWireEvents as Te } from "../../../shared/constants.js";
20
+ import { BaseComponent as Be } from "../../Base/Base.js";
21
+ import { useBase as ve } from "../../Base/useBase.js";
22
+ import { useComponentDictionary as qe, useI18n as Ne } from "../../../i18n/I18n.js";
23
+ import { readableStreamToBlob as We } from "../../../helpers/readableStreamToBlob.js";
24
+ import Ie from "../../../hooks/useNumberFormatter.js";
25
+ import { useDateFormatter as Ye } from "../../../hooks/useDateFormatter.js";
26
+ import { useComponentContext as Me } from "../../../contexts/ComponentAdapter/useComponentContext.js";
27
+ import { renderErrorList as Fe } from "../../../helpers/apiErrorToList.js";
28
+ import { Flex as xe } from "../../Common/Flex/Flex.js";
29
+ import { usePagination as Ge } from "../../../hooks/usePagination/usePagination.js";
30
+ import { PayrollLoading as I } from "../../Common/PayrollLoading/PayrollLoading.js";
31
+ const je = (s = []) => s.filter(
32
32
  (n) => n.status === "unresolved" && n.unblockOptions && n.unblockOptions.length > 0
33
- ), Ye = (s = []) => {
33
+ ), Ve = (s = []) => {
34
34
  const n = s.find((o) => o.status === "unresolved");
35
35
  return n?.unblockOptions ? n.unblockOptions.find(
36
36
  (o) => o.unblockType === "submit_wire"
37
37
  )?.metadata.wireInRequestUuid : void 0;
38
38
  };
39
- function Ot(s) {
40
- return /* @__PURE__ */ l(De, { ...s, children: /* @__PURE__ */ l(We, { ...s, children: s.children }) });
39
+ function Lt(s) {
40
+ return /* @__PURE__ */ l(Be, { ...s, children: /* @__PURE__ */ l(He, { ...s, children: s.children }) });
41
41
  }
42
- const We = ({
42
+ const He = ({
43
43
  companyId: s,
44
44
  payrollId: n,
45
- dictionary: _,
45
+ dictionary: O,
46
46
  onEvent: o,
47
- alerts: N,
48
- withReimbursements: I = !0,
49
- ConfirmWireDetailsComponent: Y = we
47
+ alerts: Y,
48
+ withReimbursements: M = !0,
49
+ ConfirmWireDetailsComponent: F = Oe,
50
+ readOnly: P = !1
50
51
  }) => {
51
- ke("Payroll.PayrollOverview", _), Ue("Payroll.PayrollOverview");
52
- const { baseSubmitHandler: D } = Ce(), { t: a } = fe("Payroll.PayrollOverview"), [p, d] = u(!1), [W, S] = u(!1), [M, O] = u(N || []), [C, F] = u({}), [P, f] = u(!1), { showBoundary: G } = Re(), k = Ae("currency"), y = Be(), { Button: x, UnorderedList: j, Text: U } = Te(), [E, g] = u(m.Viewing), { currentPage: V, itemsPerPage: H, getPaginationProps: K } = Ne({
53
- defaultItemsPerPage: 10
54
- }), { data: b, isFetching: A } = me(
52
+ qe("Payroll.PayrollOverview", O), Ne("Payroll.PayrollOverview");
53
+ const { baseSubmitHandler: C } = ve(), { t: i } = we("Payroll.PayrollOverview"), [u, b] = p(!1), [k, h] = p(!1), [x, D] = p(Y || []), [U, G] = p({}), [R, f] = p(!1), { showBoundary: j } = _e(), A = Ie("currency"), m = Ye(), { Button: V, UnorderedList: H, Text: E } = Me(), [T, g] = p(d.Viewing), { currentPage: K, itemsPerPage: z, getPaginationProps: J } = Ge({
54
+ defaultItemsPerPage: 25
55
+ }), { data: S, isFetching: B } = Re(
55
56
  {
56
57
  companyId: s,
57
58
  payrollId: n,
58
59
  include: ["taxes", "benefits", "deductions", "totals", "payroll_taxes"],
59
- page: V,
60
- per: H,
60
+ page: K,
61
+ per: z,
61
62
  sortBy: "last_name"
62
63
  },
63
64
  {
64
- refetchInterval: p ? 5e3 : !1,
65
- placeholderData: pe,
65
+ refetchInterval: u ? 5e3 : !1,
66
+ placeholderData: Se,
66
67
  // Always refetch on mount so a partner QueryClient with a non-zero `staleTime`
67
68
  // can't serve a stale pre-calculation snapshot without refetching. SDK-1018.
68
69
  refetchOnMount: "always"
69
70
  }
70
- ), e = b?.payrollShow, z = Ie(e?.submissionBlockers), R = Ye(e?.creditBlockers), { data: J } = Pe(
71
+ ), e = S?.payrollShow, Q = je(e?.submissionBlockers), w = Ve(e?.creditBlockers), { data: X } = De(
71
72
  {
72
- wireInRequestUuid: R || ""
73
+ wireInRequestUuid: w || ""
73
74
  },
74
- { enabled: !!R }
75
- ), B = J?.wireInRequest, T = () => {
75
+ { enabled: !!w }
76
+ ), v = X?.wireInRequest, q = () => {
76
77
  o(c.RUN_PAYROLL_EDIT);
77
- }, Q = R && /* @__PURE__ */ l(
78
- Y,
78
+ }, Z = w && /* @__PURE__ */ l(
79
+ F,
79
80
  {
80
81
  companyId: s,
81
- wireInId: R,
82
+ wireInId: w,
82
83
  onEvent: (t, r) => {
83
- t === _e.PAYROLL_WIRE_FORM_DONE && f(!0), o(t, r);
84
+ t === Te.PAYROLL_WIRE_FORM_DONE && f(!0), o(t, r);
84
85
  }
85
86
  }
86
- ), X = /* @__PURE__ */ l(Oe, { companyId: s, payrollId: n, onEvent: o });
87
- L(() => {
88
- B?.status === "pending_review" && !P && f(!0);
89
- }, [B?.status, P]);
90
- const h = e?.checkDate;
91
- L(() => {
92
- if (h && P) {
93
- const t = y.formatShortWithYear(h);
94
- O([
87
+ ), $ = /* @__PURE__ */ l(ke, { companyId: s, payrollId: n, onEvent: o });
88
+ _(() => {
89
+ v?.status === "pending_review" && !R && f(!0);
90
+ }, [v?.status, R]);
91
+ const L = e?.checkDate;
92
+ _(() => {
93
+ if (L && R) {
94
+ const t = m.formatShortWithYear(L);
95
+ D([
95
96
  {
96
97
  type: "success",
97
- title: a("alerts.wireDetailsSubmittedTitle"),
98
- content: /* @__PURE__ */ l(U, { children: a("alerts.wireDetailsSubmittedMessage", { checkDate: t }) }),
98
+ title: i("alerts.wireDetailsSubmittedTitle"),
99
+ content: /* @__PURE__ */ l(E, { children: i("alerts.wireDetailsSubmittedMessage", { checkDate: t }) }),
99
100
  onDismiss: () => {
100
101
  f(!1);
101
102
  }
102
103
  }
103
104
  ]);
104
105
  }
105
- }, [P, h, a, y, U]), L(() => {
106
- e && (e.processingRequest?.status === w.submitting && !p && d(!0), p && (e.processed === !0 || e.processingRequest?.status === w.submit_success) && (o(c.RUN_PAYROLL_PROCESSED, {
106
+ }, [R, L, i, m, E]), _(() => {
107
+ e && (e.processingRequest?.status === y.submitting && !u && b(!0), u && (e.processed === !0 || e.processingRequest?.status === y.submit_success) && (o(c.RUN_PAYROLL_PROCESSED, {
107
108
  payPeriod: e.payPeriod,
108
109
  payrollUuid: n
109
- }), O([
110
+ }), D([
110
111
  {
111
112
  type: "success",
112
- title: a("alerts.payrollProcessedTitle"),
113
- content: a("alerts.payrollProcessedMessage", {
114
- amount: k(Number(e.totals?.companyDebit)),
115
- date: y.formatShortWithYear(
113
+ title: i("alerts.payrollProcessedTitle"),
114
+ content: i("alerts.payrollProcessedMessage", {
115
+ amount: A(Number(e.totals?.companyDebit)),
116
+ date: m.formatShortWithYear(
116
117
  e.payrollStatusMeta?.expectedDebitTime ?? e.payrollDeadline
117
118
  )
118
119
  })
119
120
  }
120
- ]), f(!1), d(!1), S(!1)), p && e.processingRequest?.status === w.processing_failed && (o(c.RUN_PAYROLL_PROCESSING_FAILED), O([
121
+ ]), f(!1), b(!1), h(!1)), u && e.processingRequest?.status === y.processing_failed && (o(c.RUN_PAYROLL_PROCESSING_FAILED), D([
121
122
  {
122
123
  type: "error",
123
- title: a("alerts.payrollProcessingFailedTitle"),
124
- content: /* @__PURE__ */ le(qe, { flexDirection: "column", gap: 16, children: [
125
- /* @__PURE__ */ l(j, { items: ve(e.processingRequest.errors ?? []) }),
126
- /* @__PURE__ */ l(x, { variant: "secondary", onClick: T, children: a("alerts.payrollProcessingFailedCtaLabel") })
124
+ title: i("alerts.payrollProcessingFailedTitle"),
125
+ content: /* @__PURE__ */ ye(xe, { flexDirection: "column", gap: 16, children: [
126
+ /* @__PURE__ */ l(H, { items: Fe(e.processingRequest.errors ?? []) }),
127
+ !P && /* @__PURE__ */ l(V, { variant: "secondary", onClick: q, children: i("alerts.payrollProcessingFailedCtaLabel") })
127
128
  ] })
128
129
  }
129
- ]), f(!1), d(!1), S(!1)));
130
+ ]), f(!1), b(!1), h(!1)));
130
131
  }, [
131
132
  e?.processingRequest?.status,
132
133
  e?.processed,
133
- p,
134
+ u,
134
135
  o,
135
- a,
136
- y,
137
- k,
136
+ i,
137
+ m,
138
+ A,
138
139
  e?.totals?.companyDebit,
139
140
  e?.payrollStatusMeta?.expectedDebitTime,
140
- e?.payrollDeadline
141
+ e?.payrollDeadline,
142
+ P
141
143
  ]);
142
- const { data: Z } = de({
144
+ const { data: ee } = he({
143
145
  companyId: s
144
- }), $ = Z.companyBankAccounts?.[0], { paymentSpeed: ee } = he(s), { mutateAsync: te, isPending: re } = ce(), { mutateAsync: se } = ue(), oe = ye();
146
+ }), te = ee.companyBankAccounts?.[0], { paymentSpeed: re } = Ae(s), { mutateAsync: se, isPending: oe } = Pe(), { mutateAsync: ne } = be(), ie = ge();
145
147
  if (!e)
146
- return /* @__PURE__ */ l(q, { title: a("dataLoadingTitle") });
147
- if (E === m.Viewing && !e.calculatedAt) {
148
- if (A)
149
- return /* @__PURE__ */ l(q, { title: a("dataLoadingTitle") });
150
- throw new Error(a("alerts.payrollNotCalculated"));
148
+ return /* @__PURE__ */ l(I, { title: i("dataLoadingTitle") });
149
+ if (T === d.Viewing && !e.calculatedAt) {
150
+ if (B)
151
+ return /* @__PURE__ */ l(I, { title: i("dataLoadingTitle") });
152
+ throw new Error(i("alerts.payrollNotCalculated"));
151
153
  }
152
- const ne = K(b.httpMeta.response.headers, A), ie = e.payrollTaxes?.reduce(
154
+ const ae = J(S.httpMeta.response.headers, B), le = e.payrollTaxes?.reduce(
153
155
  (t, r) => {
154
156
  if (!r.name) return t;
155
- const i = r.amount ?? 0;
157
+ const a = r.amount ?? 0;
156
158
  return t[r.name] = {
157
- employee: (t[r.name]?.employee ?? 0) + (r.employer ? 0 : i),
158
- employer: (t[r.name]?.employer ?? 0) + (r.employer ? i : 0)
159
+ employee: (t[r.name]?.employee ?? 0) + (r.employer ? 0 : a),
160
+ employer: (t[r.name]?.employer ?? 0) + (r.employer ? a : 0)
159
161
  }, t;
160
162
  },
161
163
  {}
162
- ) || {};
163
- return /* @__PURE__ */ l(
164
- ge,
165
- {
166
- onEdit: T,
167
- onSubmit: async () => {
168
- await D(b, async () => {
169
- const t = await te({
170
- request: {
171
- companyId: s,
172
- payrollId: n,
173
- requestBody: {
174
- submissionBlockers: Object.entries(C).filter(
175
- ([r]) => Le.includes(r)
176
- ).map(([r, i]) => ({
177
- blockerType: r,
178
- selectedOption: i
179
- }))
180
- }
181
- }
182
- });
183
- o(c.RUN_PAYROLL_SUBMITTING), o(c.RUN_PAYROLL_SUBMITTED, t), d(!0), S(!0);
184
- });
185
- },
186
- onCancel: async () => {
187
- g(m.Cancelling), await D(b, async () => {
188
- try {
189
- const t = await se({
190
- request: {
191
- companyId: s,
192
- payrollId: n
193
- }
194
- });
195
- g(m.Cancelled), o(c.RUN_PAYROLL_CANCELLED, t);
196
- } catch (t) {
197
- throw g(m.Viewing), t;
164
+ ) || {}, ce = async () => {
165
+ g(d.Cancelling), await C(S, async () => {
166
+ try {
167
+ const t = await ne({
168
+ request: {
169
+ companyId: s,
170
+ payrollId: n
198
171
  }
199
172
  });
200
- },
201
- onPayrollReceipt: () => {
202
- o(c.RUN_PAYROLL_RECEIPT_GET, { payrollId: n });
203
- },
204
- onPaystubDownload: async (t) => {
205
- const r = window.open("", "_blank");
206
- try {
207
- const i = await be(oe, { payrollId: n, employeeId: t });
208
- if (!i.value?.responseStream)
209
- throw new Error(a("alerts.paystubPdfError"));
210
- const ae = await Ee(i.value.responseStream, "application/pdf"), v = URL.createObjectURL(ae);
211
- r && (r.location.href = v), o(c.RUN_PAYROLL_PDF_PAYSTUB_VIEWED, { employeeId: t }), URL.revokeObjectURL(v);
212
- } catch (i) {
213
- r && r.close(), G(i instanceof Error ? i : new Error(String(i)));
173
+ g(d.Cancelled), o(c.RUN_PAYROLL_CANCELLED, t);
174
+ } catch (t) {
175
+ throw g(d.Viewing), t;
176
+ }
177
+ });
178
+ }, ue = () => {
179
+ o(c.RUN_PAYROLL_RECEIPT_GET, { payrollId: n });
180
+ }, me = async (t) => {
181
+ const r = window.open("", "_blank");
182
+ try {
183
+ const a = await Le(ie, { payrollId: n, employeeId: t });
184
+ if (!a.value?.responseStream)
185
+ throw new Error(i("alerts.paystubPdfError"));
186
+ const fe = await We(a.value.responseStream, "application/pdf"), W = URL.createObjectURL(fe);
187
+ r && (r.location.href = W), o(c.RUN_PAYROLL_PDF_PAYSTUB_VIEWED, { employeeId: t }), URL.revokeObjectURL(W);
188
+ } catch (a) {
189
+ r && r.close(), j(a instanceof Error ? a : new Error(String(a)));
190
+ }
191
+ }, pe = async () => {
192
+ await C(S, async () => {
193
+ const t = await se({
194
+ request: {
195
+ companyId: s,
196
+ payrollId: n,
197
+ requestBody: {
198
+ submissionBlockers: Object.entries(U).filter(
199
+ ([r]) => Ee.includes(r)
200
+ ).map(([r, a]) => ({
201
+ blockerType: r,
202
+ selectedOption: a
203
+ }))
204
+ }
214
205
  }
215
- },
216
- status: re || W ? m.Submitting : E,
217
- isProcessed: e.processed === !0 || e.processingRequest?.status === w.submit_success,
218
- canCancel: Se(e),
206
+ });
207
+ o(c.RUN_PAYROLL_SUBMITTING), o(c.RUN_PAYROLL_SUBMITTED, t), b(!0), h(!0);
208
+ });
209
+ }, N = (() => {
210
+ if (!(k || u) && !(e.processed || e.processingRequest?.status === y.submit_success) && e.checkDate && e.payrollDeadline)
211
+ return {
212
+ type: "info",
213
+ title: i("alerts.directDepositDeadline", {
214
+ payDate: m.formatShortWithWeekday(e.checkDate),
215
+ ...m.formatWithTime(e.payrollDeadline)
216
+ }),
217
+ content: i("alerts.directDepositDeadlineText")
218
+ };
219
+ })(), de = [...x, ...N ? [N] : []];
220
+ return /* @__PURE__ */ l(
221
+ Ue,
222
+ {
223
+ onEdit: q,
224
+ onSubmit: pe,
225
+ onCancel: ce,
226
+ onPayrollReceipt: ue,
227
+ onPaystubDownload: me,
228
+ status: oe || k ? d.Submitting : T,
229
+ isProcessed: e.processed === !0 || e.processingRequest?.status === y.submit_success,
230
+ canCancel: Ce(e) && !P,
231
+ canEdit: !P,
219
232
  payrollData: e,
220
- bankAccount: $,
221
- taxes: ie,
222
- alerts: M,
223
- submissionBlockers: z,
224
- selectedUnblockOptions: C,
233
+ bankAccount: te,
234
+ taxes: le,
235
+ alerts: de,
236
+ submissionBlockers: Q,
237
+ selectedUnblockOptions: U,
225
238
  onUnblockOptionChange: (t, r) => {
226
- F((i) => ({ ...i, [t]: r }));
239
+ G((a) => ({ ...a, [t]: r }));
227
240
  },
228
- wireInConfirmationRequest: Q,
229
- printChecksBanner: X,
230
- withReimbursements: I,
231
- paymentSpeed: ee,
232
- pagination: ne
241
+ wireInConfirmationRequest: Z,
242
+ printChecksBanner: $,
243
+ withReimbursements: M,
244
+ paymentSpeed: re,
245
+ pagination: ae
233
246
  }
234
247
  );
235
248
  };
236
249
  export {
237
- Ot as PayrollOverview
250
+ Lt as PayrollOverview
238
251
  };
239
252
  //# sourceMappingURL=PayrollOverview.js.map