Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .reports/embedded-react-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,13 @@ export const componentEvents: {
readonly CONTRACTOR_PAYMENT_CANCEL: "contractor/payments/cancel";
readonly CONTRACTOR_PAYMENT_EXIT: "contractor/payments/exit";
readonly CONTRACTOR_PAYMENT_RFI_RESPOND: "contractor/payments/rfi/respond";
readonly PRINT_CHECKS_START: "payroll/printChecks/start";
readonly PRINT_CHECKS_GENERATE_START: "payroll/printChecks/generate/start";
readonly PRINT_CHECKS_GENERATE_SUCCEEDED: "payroll/printChecks/generate/succeeded";
readonly PRINT_CHECKS_GENERATE_FAILED: "payroll/printChecks/generate/failed";
readonly PRINT_CHECKS_RETRY: "payroll/printChecks/retry";
readonly PRINT_CHECKS_CANCEL: "payroll/printChecks/cancel";
readonly PRINT_CHECKS_CLOSE: "payroll/printChecks/close";
readonly RECOVERY_CASE_RESOLVE: "recoveryCase/resolve";
readonly RECOVERY_CASE_RESUBMIT: "recoveryCase/resubmit";
readonly RECOVERY_CASE_RESUBMIT_CANCEL: "recoveryCase/resubmit/cancel";
Expand Down Expand Up @@ -4993,6 +5000,10 @@ export interface Resources {
// (undocumented)
'Payroll.PayrollReceipts': Translations.PayrollPayrollReceipts
// (undocumented)
'Payroll.PrintChecksFailure': Translations.PayrollPrintChecksFailure
// (undocumented)
'Payroll.PrintChecksSummary': Translations.PayrollPrintChecksSummary
// (undocumented)
'Payroll.RecoveryCasesList': Translations.PayrollRecoveryCasesList
// (undocumented)
'Payroll.RecoveryCasesResubmit': Translations.PayrollRecoveryCasesResubmit
Expand Down
35 changes: 35 additions & 0 deletions docs/reference/Translations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5234,6 +5234,39 @@ Translation keys for the `Payroll.PayrollReceipts` i18n namespace.

***

<a id="payrollprintchecksfailure"></a>

### PayrollPrintChecksFailure

Translation keys for the `Payroll.PrintChecksFailure` i18n namespace.

#### Properties

| Property | Default value |
| ------ | ------ |
| <a id="property-payrollprintchecksfailureclosecta"></a> `closeCta` | `"Close"` |
| <a id="property-payrollprintchecksfailurefailedtitle"></a> `failedTitle` | `"We couldn't generate your checks"` |
| <a id="property-payrollprintchecksfailureretrycta"></a> `retryCta` | `"Try again"` |

***

<a id="payrollprintcheckssummary"></a>

### PayrollPrintChecksSummary

Translation keys for the `Payroll.PrintChecksSummary` i18n namespace.

#### Properties

| Property | Default value |
| ------ | ------ |
| <a id="property-payrollprintcheckssummaryclosecta"></a> `closeCta` | `"Close"` |
| <a id="property-payrollprintcheckssummarysucceededdescription"></a> `succeededDescription` | `"The download should have started automatically. If not, use the link below."` |
| <a id="property-payrollprintcheckssummarysucceededtitle"></a> `succeededTitle` | `"Your checks are ready"` |
| <a id="property-payrollprintcheckssummaryviewcheckscta"></a> `viewChecksCta` | `"View checks"` |

***

<a id="payrollrecoverycaseslist"></a>

### PayrollRecoveryCasesList
Expand Down Expand Up @@ -5606,6 +5639,8 @@ yields that namespace's keys. Backs i18next `t()` typing and `ResourceDictionary
| <a id="property-resourcespayrollpayrolllist"></a> `Payroll.PayrollList` | [`PayrollPayrollList`](#payrollpayrolllist) |
| <a id="property-resourcespayrollpayrolloverview"></a> `Payroll.PayrollOverview` | [`PayrollPayrollOverview`](#payrollpayrolloverview) |
| <a id="property-resourcespayrollpayrollreceipts"></a> `Payroll.PayrollReceipts` | [`PayrollPayrollReceipts`](#payrollpayrollreceipts) |
| <a id="property-resourcespayrollprintchecksfailure"></a> `Payroll.PrintChecksFailure` | [`PayrollPrintChecksFailure`](#payrollprintchecksfailure) |
| <a id="property-resourcespayrollprintcheckssummary"></a> `Payroll.PrintChecksSummary` | [`PayrollPrintChecksSummary`](#payrollprintcheckssummary) |
| <a id="property-resourcespayrollrecoverycaseslist"></a> `Payroll.RecoveryCasesList` | [`PayrollRecoveryCasesList`](#payrollrecoverycaseslist) |
| <a id="property-resourcespayrollrecoverycasesresubmit"></a> `Payroll.RecoveryCasesResubmit` | [`PayrollRecoveryCasesResubmit`](#payrollrecoverycasesresubmit) |
| <a id="property-resourcespayrolltransition"></a> `Payroll.Transition` | [`PayrollTransition`](#payrolltransition) |
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ import { componentEvents, EmployeeOnboarding } from '@gusto/embedded-react-sdk'
| `PAYROLL_WIRE_INSTRUCTIONS_DONE` | `"payroll/wire/instructions/done"` |
| `PAYROLL_WIRE_INSTRUCTIONS_SELECT` | `"payroll/wire/instructions/select"` |
| `PAYROLL_WIRE_START_TRANSFER` | `"payroll/wire/startTransfer"` |
| `PRINT_CHECKS_CANCEL` | `"payroll/printChecks/cancel"` |
| `PRINT_CHECKS_CLOSE` | `"payroll/printChecks/close"` |
| `PRINT_CHECKS_GENERATE_FAILED` | `"payroll/printChecks/generate/failed"` |
| `PRINT_CHECKS_GENERATE_START` | `"payroll/printChecks/generate/start"` |
| `PRINT_CHECKS_GENERATE_SUCCEEDED` | `"payroll/printChecks/generate/succeeded"` |
| `PRINT_CHECKS_RETRY` | `"payroll/printChecks/retry"` |
| `PRINT_CHECKS_START` | `"payroll/printChecks/start"` |
| `RECOVERY_CASE_RESOLVE` | `"recoveryCase/resolve"` |
| `RECOVERY_CASE_RESUBMIT` | `"recoveryCase/resubmit"` |
| `RECOVERY_CASE_RESUBMIT_CANCEL` | `"recoveryCase/resubmit/cancel"` |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Suspense } from 'react'
import { fn } from 'storybook/test'
import { MockBaseProvider } from '../../../../../.storybook/helpers/MockBaseProvider'
import { PrintChecksFailure } from './PrintChecksFailure'
import { useI18n } from '@/i18n'

function I18nLoader({ children }: { children: React.ReactNode }) {
useI18n('Payroll.PrintChecksFailure')
return <>{children}</>
}

export default {
title: 'Domain/Payroll/PrintChecksFailure',
decorators: [
(Story: React.ComponentType) => (
<Suspense fallback={<div>Loading translations...</div>}>
<I18nLoader>
<MockBaseProvider>
<Story />
</MockBaseProvider>
</I18nLoader>
</Suspense>
Comment on lines +16 to +22

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: i think there should be a global configuration for this already so we don't have to reimplement for every story?

),
],
}

export const Default = () => (
<>
<PrintChecksFailure
errorMessage="Cannot generate checks on an unprocessed payroll"
onEvent={fn().mockName('onEvent')}
/>
<PrintChecksFailure.Footer onEvent={fn().mockName('onEvent')} />
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it, vi } from 'vitest'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { PrintChecksFailure } from './PrintChecksFailure'
import { renderWithProviders } from '@/test-utils/renderWithProviders'
import { printChecksEvents } from '@/shared/constants'

describe('PrintChecksFailure', () => {
const user = userEvent.setup()

it('renders the error message', async () => {
renderWithProviders(
<PrintChecksFailure
errorMessage="Cannot generate checks on an unprocessed payroll"
onEvent={vi.fn()}
/>,
)

expect(await screen.findByText("We couldn't generate your checks")).toBeInTheDocument()
expect(screen.getByText('Cannot generate checks on an unprocessed payroll')).toBeInTheDocument()
})

it('fires PRINT_CHECKS_RETRY when the retry button is clicked', async () => {
const onEvent = vi.fn()
renderWithProviders(<PrintChecksFailure onEvent={onEvent} />)

await user.click(await screen.findByRole('button', { name: 'Try again' }))

expect(onEvent).toHaveBeenCalledWith(printChecksEvents.PRINT_CHECKS_RETRY)
})

it('fires PRINT_CHECKS_CLOSE when the Footer close button is clicked', async () => {
const onEvent = vi.fn()
renderWithProviders(<PrintChecksFailure.Footer onEvent={onEvent} />)

await user.click(await screen.findByRole('button', { name: 'Close' }))

expect(onEvent).toHaveBeenCalledWith(printChecksEvents.PRINT_CHECKS_CLOSE)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useTranslation } from 'react-i18next'
import { BaseComponent, type BaseComponentInterface } from '@/components/Base'
import type { OnEventType } from '@/components/Base/useBase'
import { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'
import { useComponentDictionary, useI18n } from '@/i18n'
import { ActionsLayout, Flex } from '@/components/Common'
import { printChecksEvents, type EventType } from '@/shared/constants'

interface PrintChecksFailureProps extends BaseComponentInterface<'Payroll.PrintChecksFailure'> {
errorMessage?: string
}

/** @internal */
export function PrintChecksFailure(props: PrintChecksFailureProps) {
return (
<BaseComponent {...props}>
<Root {...props}>{props.children}</Root>
</BaseComponent>
)
}

const Root = ({ dictionary, errorMessage, onEvent }: PrintChecksFailureProps) => {
useComponentDictionary('Payroll.PrintChecksFailure', dictionary)
useI18n('Payroll.PrintChecksFailure')
const { t } = useTranslation('Payroll.PrintChecksFailure')
const { Alert, Button } = useComponentContext()

return (
<Flex flexDirection="column" gap={16}>
<Alert status="error" disableScrollIntoView label={t('failedTitle')}>
{errorMessage}
</Alert>
<Button
variant="secondary"
onClick={() => {
onEvent(printChecksEvents.PRINT_CHECKS_RETRY)
}}
>
{t('retryCta')}
</Button>
</Flex>
)
}

const Footer = ({ onEvent }: { onEvent: OnEventType<EventType, unknown> }) => {
useI18n('Payroll.PrintChecksFailure')
const { t } = useTranslation('Payroll.PrintChecksFailure')
const { Button } = useComponentContext()

return (
<ActionsLayout>
<Button
variant="secondary"
onClick={() => {
onEvent(printChecksEvents.PRINT_CHECKS_CLOSE)
}}
>
{t('closeCta')}
</Button>
</ActionsLayout>
)
}
PrintChecksFailure.Footer = Footer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PrintChecksFailure } from './PrintChecksFailure'
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Suspense } from 'react'
import { fn } from 'storybook/test'
import { MockBaseProvider } from '../../../../../.storybook/helpers/MockBaseProvider'
import { PrintChecksSummary } from './PrintChecksSummary'
import { useI18n } from '@/i18n'

function I18nLoader({ children }: { children: React.ReactNode }) {
useI18n('Payroll.PrintChecksSummary')
return <>{children}</>
}

export default {
title: 'Domain/Payroll/PrintChecksSummary',
decorators: [
(Story: React.ComponentType) => (
<Suspense fallback={<div>Loading translations...</div>}>
<I18nLoader>
<MockBaseProvider>
<Story />
</MockBaseProvider>
</I18nLoader>
</Suspense>
Comment on lines +15 to +22

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same on this one, i feel like this is a global config somewhere?

),
],
}

export const Default = () => (
<>
<PrintChecksSummary
documentUrl="https://example.com/checks.pdf"
onEvent={fn().mockName('onEvent')}
/>
<PrintChecksSummary.Footer onEvent={fn().mockName('onEvent')} />
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it, vi } from 'vitest'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { PrintChecksSummary } from './PrintChecksSummary'
import { renderWithProviders } from '@/test-utils/renderWithProviders'
import { printChecksEvents } from '@/shared/constants'

describe('PrintChecksSummary', () => {
const user = userEvent.setup()

it('renders a link to the document when a documentUrl is provided', async () => {
renderWithProviders(
<PrintChecksSummary documentUrl="https://example.com/checks.pdf" onEvent={vi.fn()} />,
)

expect(await screen.findByText('Your checks are ready')).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'View checks' })).toHaveAttribute(
'href',
'https://example.com/checks.pdf',
)
})

it('omits the link when no documentUrl is provided', async () => {
renderWithProviders(<PrintChecksSummary onEvent={vi.fn()} />)

expect(await screen.findByText('Your checks are ready')).toBeInTheDocument()
expect(screen.queryByRole('link', { name: 'View checks' })).toBeNull()
})

it('fires PRINT_CHECKS_CLOSE when the Footer close button is clicked', async () => {
const onEvent = vi.fn()
renderWithProviders(<PrintChecksSummary.Footer onEvent={onEvent} />)

await user.click(await screen.findByRole('button', { name: 'Close' }))

expect(onEvent).toHaveBeenCalledWith(printChecksEvents.PRINT_CHECKS_CLOSE)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useTranslation } from 'react-i18next'
import { BaseComponent, type BaseComponentInterface } from '@/components/Base'
import type { OnEventType } from '@/components/Base/useBase'
import { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'
import { useComponentDictionary, useI18n } from '@/i18n'
import { ActionsLayout, Flex } from '@/components/Common'
import { printChecksEvents, type EventType } from '@/shared/constants'

interface PrintChecksSummaryProps extends BaseComponentInterface<'Payroll.PrintChecksSummary'> {
documentUrl?: string
}

/** @internal */
export function PrintChecksSummary(props: PrintChecksSummaryProps) {
return (
<BaseComponent {...props}>
<Root {...props}>{props.children}</Root>
</BaseComponent>
)
}

const Root = ({ dictionary, documentUrl }: PrintChecksSummaryProps) => {
useComponentDictionary('Payroll.PrintChecksSummary', dictionary)
useI18n('Payroll.PrintChecksSummary')
const { t } = useTranslation('Payroll.PrintChecksSummary')
const { Heading, Text, Link } = useComponentContext()

return (
<Flex flexDirection="column" gap={16}>
<Heading as="h2">{t('succeededTitle')}</Heading>
<Text variant="supporting">{t('succeededDescription')}</Text>
{documentUrl && (
<Link href={documentUrl} target="_blank" rel="noreferrer">
{t('viewChecksCta')}
</Link>
)}
</Flex>
)
}

const Footer = ({ onEvent }: { onEvent: OnEventType<EventType, unknown> }) => {
useI18n('Payroll.PrintChecksSummary')
const { t } = useTranslation('Payroll.PrintChecksSummary')
const { Button } = useComponentContext()

return (
<ActionsLayout>
<Button
variant="secondary"
onClick={() => {
onEvent(printChecksEvents.PRINT_CHECKS_CLOSE)
}}
>
{t('closeCta')}
</Button>
</ActionsLayout>
)
}
PrintChecksSummary.Footer = Footer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PrintChecksSummary } from './PrintChecksSummary'
5 changes: 5 additions & 0 deletions src/i18n/en/Payroll.PrintChecksFailure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"failedTitle": "We couldn't generate your checks",
"retryCta": "Try again",
"closeCta": "Close"
}
6 changes: 6 additions & 0 deletions src/i18n/en/Payroll.PrintChecksSummary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"succeededTitle": "Your checks are ready",
"succeededDescription": "The download should have started automatically. If not, use the link below.",
"viewChecksCta": "View checks",
"closeCta": "Close"
}
Loading
Loading