-
Notifications
You must be signed in to change notification settings - Fork 4
feat(SDK-1161): add print-checks terminal screens and event vocabulary #2584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ), | ||
| ], | ||
| } | ||
|
|
||
| export const Default = () => ( | ||
| <> | ||
| <PrintChecksFailure | ||
| errorMessage="Cannot generate checks on an unprocessed payroll" | ||
| onEvent={fn().mockName('onEvent')} | ||
| /> | ||
| <PrintChecksFailure.Footer onEvent={fn().mockName('onEvent')} /> | ||
| </> | ||
| ) | ||
40 changes: 40 additions & 0 deletions
40
src/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| }) |
63 changes: 63 additions & 0 deletions
63
src/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { PrintChecksFailure } from './PrintChecksFailure' |
35 changes: 35 additions & 0 deletions
35
src/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')} /> | ||
| </> | ||
| ) | ||
38 changes: 38 additions & 0 deletions
38
src/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| }) |
59 changes: 59 additions & 0 deletions
59
src/components/Payroll/PrintChecks/PrintChecksSummary/PrintChecksSummary.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { PrintChecksSummary } from './PrintChecksSummary' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?