@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.
- package/CHANGELOG.md +18 -0
- package/dist/components/Common/FieldLayout/FieldLayout.js +6 -6
- package/dist/components/Common/Fieldset/Fieldset.js +6 -6
- package/dist/components/Common/HorizontalFieldLayout/HorizontalFieldLayout.js +6 -6
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js +58 -49
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js.map +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js +14 -10
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.module.scss.js.map +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBoxTypes.d.ts +4 -0
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +5 -3
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +5 -3
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +7 -5
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +5 -3
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
- package/dist/components/Company/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/List.js +11 -8
- package/dist/components/Company/DocumentSigner/DocumentList/List.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +5 -3
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +10 -8
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +8 -6
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +5 -3
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +5 -3
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +5 -3
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +5 -3
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +5 -3
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +5 -3
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js +116 -116
- package/dist/components/Employee/Compensation/shared/useJobForm/useJobForm.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.d.ts +4 -0
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js +19 -19
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/DocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js +16 -13
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/List.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +5 -3
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.d.ts +4 -0
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentSigner.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +75 -71
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +137 -138
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js +1 -1
- package/dist/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.d.ts +8 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +174 -161
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.d.ts +2 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js +42 -41
- package/dist/components/Payroll/PayrollOverview/PayrollOverviewPresentation.js.map +1 -1
- package/dist/components/Payroll/helpers.d.ts +0 -15
- package/dist/components/Payroll/helpers.js +13 -18
- package/dist/components/Payroll/helpers.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +10 -8
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/i18n/en/Company.DocumentList.json.js +34 -32
- package/dist/i18n/en/Company.DocumentList.json.js.map +1 -1
- package/dist/i18n/en/Employee.DocumentSigner.json.js +24 -22
- package/dist/i18n/en/Employee.DocumentSigner.json.js.map +1 -1
- package/dist/i18n/en/Payroll.PayrollOverview.json.js +5 -5
- package/dist/i18n/types.d.ts +311 -1
- package/dist/style.css +1 -1
- 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,EAAOC,CAAY;AAC3C,EAAAI,EAAgB,UAAUJ;AAE1B,QAAMK,IAAsBC,EAAQ,MAC3BN,GAAc,eAAe,IAAI,OAAK,EAAE,IAAI,KAAK,CAAA,GACvD,CAACA,GAAc,aAAa,CAAC,GAE1BO,IAAuBD,EAA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,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,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;AA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,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
|
|
2
|
-
import { usePayrollsSubmitMutation as
|
|
3
|
-
import { usePayrollsCancelMutation as
|
|
4
|
-
import { usePayrollsGet as
|
|
5
|
-
import { keepPreviousData as
|
|
6
|
-
import { useTranslation as
|
|
7
|
-
import { useBankAccountsGetSuspense as
|
|
8
|
-
import { useWireInRequestsGet as
|
|
9
|
-
import { useState as
|
|
10
|
-
import { useGustoEmbeddedContext as
|
|
11
|
-
import { payrollsGetPayStub as
|
|
12
|
-
import { useErrorBoundary as
|
|
13
|
-
import { ConfirmWireDetails as
|
|
14
|
-
import { canCancelPayroll as
|
|
15
|
-
import { PrintChecks as
|
|
16
|
-
import { PayrollOverviewPresentation as
|
|
17
|
-
import { PayrollOverviewStatus as
|
|
18
|
-
import { useCompanyPaymentSpeed as
|
|
19
|
-
import { PAYROLL_PROCESSING_STATUS as
|
|
20
|
-
import { BaseComponent as
|
|
21
|
-
import { useBase as
|
|
22
|
-
import { useComponentDictionary as
|
|
23
|
-
import { readableStreamToBlob as
|
|
24
|
-
import
|
|
25
|
-
import { useDateFormatter as
|
|
26
|
-
import { useComponentContext as
|
|
27
|
-
import { renderErrorList as
|
|
28
|
-
import { Flex as
|
|
29
|
-
import { usePagination as
|
|
30
|
-
import { PayrollLoading as
|
|
31
|
-
const
|
|
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
|
-
),
|
|
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
|
|
40
|
-
return /* @__PURE__ */ l(
|
|
39
|
+
function Lt(s) {
|
|
40
|
+
return /* @__PURE__ */ l(Be, { ...s, children: /* @__PURE__ */ l(He, { ...s, children: s.children }) });
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const He = ({
|
|
43
43
|
companyId: s,
|
|
44
44
|
payrollId: n,
|
|
45
|
-
dictionary:
|
|
45
|
+
dictionary: O,
|
|
46
46
|
onEvent: o,
|
|
47
|
-
alerts:
|
|
48
|
-
withReimbursements:
|
|
49
|
-
ConfirmWireDetailsComponent:
|
|
47
|
+
alerts: Y,
|
|
48
|
+
withReimbursements: M = !0,
|
|
49
|
+
ConfirmWireDetailsComponent: F = Oe,
|
|
50
|
+
readOnly: P = !1
|
|
50
51
|
}) => {
|
|
51
|
-
|
|
52
|
-
const { baseSubmitHandler:
|
|
53
|
-
defaultItemsPerPage:
|
|
54
|
-
}), { data:
|
|
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:
|
|
60
|
-
per:
|
|
60
|
+
page: K,
|
|
61
|
+
per: z,
|
|
61
62
|
sortBy: "last_name"
|
|
62
63
|
},
|
|
63
64
|
{
|
|
64
|
-
refetchInterval:
|
|
65
|
-
placeholderData:
|
|
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 =
|
|
71
|
+
), e = S?.payrollShow, Q = je(e?.submissionBlockers), w = Ve(e?.creditBlockers), { data: X } = De(
|
|
71
72
|
{
|
|
72
|
-
wireInRequestUuid:
|
|
73
|
+
wireInRequestUuid: w || ""
|
|
73
74
|
},
|
|
74
|
-
{ enabled: !!
|
|
75
|
-
),
|
|
75
|
+
{ enabled: !!w }
|
|
76
|
+
), v = X?.wireInRequest, q = () => {
|
|
76
77
|
o(c.RUN_PAYROLL_EDIT);
|
|
77
|
-
},
|
|
78
|
-
|
|
78
|
+
}, Z = w && /* @__PURE__ */ l(
|
|
79
|
+
F,
|
|
79
80
|
{
|
|
80
81
|
companyId: s,
|
|
81
|
-
wireInId:
|
|
82
|
+
wireInId: w,
|
|
82
83
|
onEvent: (t, r) => {
|
|
83
|
-
t ===
|
|
84
|
+
t === Te.PAYROLL_WIRE_FORM_DONE && f(!0), o(t, r);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, [
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
const t =
|
|
94
|
-
|
|
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:
|
|
98
|
-
content: /* @__PURE__ */ l(
|
|
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
|
-
}, [
|
|
106
|
-
e && (e.processingRequest?.status ===
|
|
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
|
-
}),
|
|
110
|
+
}), D([
|
|
110
111
|
{
|
|
111
112
|
type: "success",
|
|
112
|
-
title:
|
|
113
|
-
content:
|
|
114
|
-
amount:
|
|
115
|
-
date:
|
|
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),
|
|
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:
|
|
124
|
-
content: /* @__PURE__ */
|
|
125
|
-
/* @__PURE__ */ l(
|
|
126
|
-
/* @__PURE__ */ l(
|
|
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),
|
|
130
|
+
]), f(!1), b(!1), h(!1)));
|
|
130
131
|
}, [
|
|
131
132
|
e?.processingRequest?.status,
|
|
132
133
|
e?.processed,
|
|
133
|
-
|
|
134
|
+
u,
|
|
134
135
|
o,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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:
|
|
144
|
+
const { data: ee } = he({
|
|
143
145
|
companyId: s
|
|
144
|
-
}),
|
|
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(
|
|
147
|
-
if (
|
|
148
|
-
if (
|
|
149
|
-
return /* @__PURE__ */ l(
|
|
150
|
-
throw new Error(
|
|
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
|
|
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
|
|
157
|
+
const a = r.amount ?? 0;
|
|
156
158
|
return t[r.name] = {
|
|
157
|
-
employee: (t[r.name]?.employee ?? 0) + (r.employer ? 0 :
|
|
158
|
-
employer: (t[r.name]?.employer ?? 0) + (r.employer ?
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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:
|
|
222
|
-
alerts:
|
|
223
|
-
submissionBlockers:
|
|
224
|
-
selectedUnblockOptions:
|
|
233
|
+
bankAccount: te,
|
|
234
|
+
taxes: le,
|
|
235
|
+
alerts: de,
|
|
236
|
+
submissionBlockers: Q,
|
|
237
|
+
selectedUnblockOptions: U,
|
|
225
238
|
onUnblockOptionChange: (t, r) => {
|
|
226
|
-
|
|
239
|
+
G((a) => ({ ...a, [t]: r }));
|
|
227
240
|
},
|
|
228
|
-
wireInConfirmationRequest:
|
|
229
|
-
printChecksBanner:
|
|
230
|
-
withReimbursements:
|
|
231
|
-
paymentSpeed:
|
|
232
|
-
pagination:
|
|
241
|
+
wireInConfirmationRequest: Z,
|
|
242
|
+
printChecksBanner: $,
|
|
243
|
+
withReimbursements: M,
|
|
244
|
+
paymentSpeed: re,
|
|
245
|
+
pagination: ae
|
|
233
246
|
}
|
|
234
247
|
);
|
|
235
248
|
};
|
|
236
249
|
export {
|
|
237
|
-
|
|
250
|
+
Lt as PayrollOverview
|
|
238
251
|
};
|
|
239
252
|
//# sourceMappingURL=PayrollOverview.js.map
|