-
Notifications
You must be signed in to change notification settings - Fork 65
feat(task): Create CampaginErrorDialog Component #670
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7d8e322
Update OutdialCall CSS
73d6e8b
Merge branch 'next' into next
brain-frog b0f7ba6
Add labels
6d39f62
Merge branch 'next' of github.com:brain-frog/widgets into next
e0773f6
Merge branch 'webex:next' into next
brain-frog ab7169f
Merge branch 'next' of github.com:brain-frog/widgets into next
aa08727
Merge branch 'next' of github.com:brain-frog/widgets into next
e5beb92
Create CampaignErrorDialog Component
04717f3
Merge branch 'next' into cai-7665
brain-frog b39778f
PR Comment Update
4cfaf99
Aria Label and onClose nit
103eb0a
Add snapshot tests
1d37122
Native close handling
40593de
Merge branch 'next' into cai-7665
brain-frog 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
26 changes: 26 additions & 0 deletions
26
...er/cc-components/src/components/task/CampaignErrorDialog/campaign-error-dialog.style.scss
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,26 @@ | ||
| .campaign-error-dialog { | ||
| width: 25rem; | ||
| border-radius: 0.5rem; | ||
| border-color: transparent; | ||
| padding: 1rem; | ||
| box-shadow: 0rem 0.25rem 0.5rem 0rem rgba(0, 0, 0, 0.16), 0rem 0rem 0.0625rem 0rem rgba(0, 0, 0, 0.16); | ||
|
|
||
| &::backdrop { | ||
| background-color: rgba(0, 0, 0, 0.5); | ||
| } | ||
|
|
||
| .campaign-error-dialog-title { | ||
| margin: 0; | ||
| flex: 1; | ||
| } | ||
|
|
||
| .campaign-error-dialog-message { | ||
| margin-bottom: 1.5rem; | ||
| } | ||
|
|
||
| .campaign-error-dialog-actions { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| gap: 0.5rem; | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
...ct-center/cc-components/src/components/task/CampaignErrorDialog/campaign-error-dialog.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,70 @@ | ||
| import React, {useEffect, useRef} from 'react'; | ||
| import {Button, Text} from '@momentum-design/components/dist/react'; | ||
| import {CampaignErrorDialogProps, ERROR_TITLES, ERROR_MESSAGE} from './campaign-error-dialog.types'; | ||
| import {withMetrics} from '@webex/cc-ui-logging'; | ||
| import './campaign-error-dialog.style.scss'; | ||
|
|
||
| const CampaignErrorDialog: React.FunctionComponent<CampaignErrorDialogProps> = ({errorType, isOpen, onClose}) => { | ||
| const dialogRef = useRef<HTMLDialogElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| const dialog = dialogRef.current; | ||
| if (!dialog) return; | ||
|
|
||
| if (isOpen && !dialog.open) { | ||
| dialog.showModal(); | ||
| } else if (!isOpen && dialog.open) { | ||
| dialog.close(); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| useEffect(() => { | ||
| const dialog = dialogRef.current; | ||
| if (!dialog) return; | ||
|
|
||
| const handleClose = () => { | ||
| if (isOpen) { | ||
| onClose(); | ||
| } | ||
| }; | ||
|
|
||
| dialog.addEventListener('close', handleClose); | ||
| return () => dialog.removeEventListener('close', handleClose); | ||
| }, [isOpen, onClose]); | ||
|
|
||
| return ( | ||
| <dialog | ||
| ref={dialogRef} | ||
| className="campaign-error-dialog" | ||
| data-testid="campaign-error-dialog" | ||
|
brain-frog marked this conversation as resolved.
|
||
| aria-labelledby="campaign-error-dialog-title" | ||
|
brain-frog marked this conversation as resolved.
|
||
| > | ||
| <Text | ||
| id="campaign-error-dialog-title" | ||
| tagname="h2" | ||
| type="body-large-bold" | ||
| className="campaign-error-dialog-title" | ||
| data-testid="campaign-error-dialog-title" | ||
| > | ||
| {ERROR_TITLES[errorType]} | ||
| </Text> | ||
| <Text | ||
| id="campaign-error-dialog-message" | ||
| tagname="p" | ||
| type="body-midsize-regular" | ||
| className="campaign-error-dialog-message" | ||
| data-testid="campaign-error-dialog-message" | ||
| > | ||
| {ERROR_MESSAGE} | ||
| </Text> | ||
| <div className="campaign-error-dialog-actions"> | ||
| <Button onClick={onClose} data-testid="campaign-error-dialog-ok-button"> | ||
| OK | ||
| </Button> | ||
| </div> | ||
| </dialog> | ||
| ); | ||
| }; | ||
|
|
||
| const CampaignErrorDialogWithMetrics = withMetrics(CampaignErrorDialog, 'CampaignErrorDialog'); | ||
| export default CampaignErrorDialogWithMetrics; | ||
16 changes: 16 additions & 0 deletions
16
...nter/cc-components/src/components/task/CampaignErrorDialog/campaign-error-dialog.types.ts
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,16 @@ | ||
| export type CampaignErrorType = 'ACCEPT_FAILED' | 'SKIP_FAILED' | 'REMOVE_FAILED'; | ||
|
|
||
| export interface CampaignErrorDialogProps { | ||
| errorType: CampaignErrorType; | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export const ERROR_TITLES: Record<CampaignErrorType, string> = { | ||
| ACCEPT_FAILED: "Can't accept contact", | ||
| SKIP_FAILED: "Can't skip contact", | ||
| REMOVE_FAILED: "Can't remove contact", | ||
| }; | ||
|
|
||
| export const ERROR_MESSAGE = | ||
| 'We ran into an issue connecting you with this contact. Check your network connection and try again.'; |
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
137 changes: 137 additions & 0 deletions
137
...components/task/CampaignErrorDialog/__snapshots__/campaign-error-dialog.snapshot.tsx.snap
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,137 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CampaignErrorDialog Snapshots Rendering should match snapshot for ACCEPT_FAILED error type 1`] = ` | ||
| <div> | ||
| <dialog | ||
| aria-labelledby="campaign-error-dialog-title" | ||
| class="campaign-error-dialog" | ||
| data-testid="campaign-error-dialog" | ||
| > | ||
| <mdc-text | ||
| class="campaign-error-dialog-title" | ||
| data-testid="campaign-error-dialog-title" | ||
| id="campaign-error-dialog-title" | ||
| > | ||
| Can't accept contact | ||
| </mdc-text> | ||
| <mdc-text | ||
| class="campaign-error-dialog-message" | ||
| data-testid="campaign-error-dialog-message" | ||
| id="campaign-error-dialog-message" | ||
| > | ||
| We ran into an issue connecting you with this contact. Check your network connection and try again. | ||
| </mdc-text> | ||
| <div | ||
| class="campaign-error-dialog-actions" | ||
| > | ||
| <mdc-button | ||
| data-testid="campaign-error-dialog-ok-button" | ||
| > | ||
| OK | ||
| </mdc-button> | ||
| </div> | ||
| </dialog> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`CampaignErrorDialog Snapshots Rendering should match snapshot for REMOVE_FAILED error type 1`] = ` | ||
| <div> | ||
| <dialog | ||
| aria-labelledby="campaign-error-dialog-title" | ||
| class="campaign-error-dialog" | ||
| data-testid="campaign-error-dialog" | ||
| > | ||
| <mdc-text | ||
| class="campaign-error-dialog-title" | ||
| data-testid="campaign-error-dialog-title" | ||
| id="campaign-error-dialog-title" | ||
| > | ||
| Can't remove contact | ||
| </mdc-text> | ||
| <mdc-text | ||
| class="campaign-error-dialog-message" | ||
| data-testid="campaign-error-dialog-message" | ||
| id="campaign-error-dialog-message" | ||
| > | ||
| We ran into an issue connecting you with this contact. Check your network connection and try again. | ||
| </mdc-text> | ||
| <div | ||
| class="campaign-error-dialog-actions" | ||
| > | ||
| <mdc-button | ||
| data-testid="campaign-error-dialog-ok-button" | ||
| > | ||
| OK | ||
| </mdc-button> | ||
| </div> | ||
| </dialog> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`CampaignErrorDialog Snapshots Rendering should match snapshot for SKIP_FAILED error type 1`] = ` | ||
| <div> | ||
| <dialog | ||
| aria-labelledby="campaign-error-dialog-title" | ||
| class="campaign-error-dialog" | ||
| data-testid="campaign-error-dialog" | ||
| > | ||
| <mdc-text | ||
| class="campaign-error-dialog-title" | ||
| data-testid="campaign-error-dialog-title" | ||
| id="campaign-error-dialog-title" | ||
| > | ||
| Can't skip contact | ||
| </mdc-text> | ||
| <mdc-text | ||
| class="campaign-error-dialog-message" | ||
| data-testid="campaign-error-dialog-message" | ||
| id="campaign-error-dialog-message" | ||
| > | ||
| We ran into an issue connecting you with this contact. Check your network connection and try again. | ||
| </mdc-text> | ||
| <div | ||
| class="campaign-error-dialog-actions" | ||
| > | ||
| <mdc-button | ||
| data-testid="campaign-error-dialog-ok-button" | ||
| > | ||
| OK | ||
| </mdc-button> | ||
| </div> | ||
| </dialog> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`CampaignErrorDialog Snapshots Rendering should match snapshot when dialog is closed 1`] = ` | ||
| <div> | ||
| <dialog | ||
| aria-labelledby="campaign-error-dialog-title" | ||
| class="campaign-error-dialog" | ||
| data-testid="campaign-error-dialog" | ||
| > | ||
| <mdc-text | ||
| class="campaign-error-dialog-title" | ||
| data-testid="campaign-error-dialog-title" | ||
| id="campaign-error-dialog-title" | ||
| > | ||
| Can't accept contact | ||
| </mdc-text> | ||
| <mdc-text | ||
| class="campaign-error-dialog-message" | ||
| data-testid="campaign-error-dialog-message" | ||
| id="campaign-error-dialog-message" | ||
| > | ||
| We ran into an issue connecting you with this contact. Check your network connection and try again. | ||
| </mdc-text> | ||
| <div | ||
| class="campaign-error-dialog-actions" | ||
| > | ||
| <mdc-button | ||
| data-testid="campaign-error-dialog-ok-button" | ||
| > | ||
| OK | ||
| </mdc-button> | ||
| </div> | ||
| </dialog> | ||
| </div> | ||
| `; |
53 changes: 53 additions & 0 deletions
53
...c-components/tests/components/task/CampaignErrorDialog/campaign-error-dialog.snapshot.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,53 @@ | ||
| import React from 'react'; | ||
| import {render} from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import CampaignErrorDialogComponent from '../../../../src/components/task/CampaignErrorDialog/campaign-error-dialog'; | ||
| import {CampaignErrorDialogProps} from '../../../../src/components/task/CampaignErrorDialog/campaign-error-dialog.types'; | ||
|
|
||
| // Mock HTMLDialogElement methods | ||
| HTMLDialogElement.prototype.showModal = jest.fn(); | ||
| HTMLDialogElement.prototype.close = jest.fn(); | ||
|
|
||
| describe('CampaignErrorDialog Snapshots', () => { | ||
| const mockOnClose = jest.fn(); | ||
|
|
||
| const defaultProps: CampaignErrorDialogProps = { | ||
| errorType: 'ACCEPT_FAILED', | ||
| isOpen: false, | ||
| onClose: mockOnClose, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (HTMLDialogElement.prototype.showModal as jest.Mock).mockClear(); | ||
| (HTMLDialogElement.prototype.close as jest.Mock).mockClear(); | ||
| }); | ||
|
|
||
| describe('Rendering', () => { | ||
| it('should match snapshot for ACCEPT_FAILED error type', () => { | ||
| const {container} = render( | ||
| <CampaignErrorDialogComponent {...defaultProps} errorType="ACCEPT_FAILED" isOpen={true} /> | ||
| ); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should match snapshot for SKIP_FAILED error type', () => { | ||
| const {container} = render( | ||
| <CampaignErrorDialogComponent {...defaultProps} errorType="SKIP_FAILED" isOpen={true} /> | ||
| ); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should match snapshot for REMOVE_FAILED error type', () => { | ||
| const {container} = render( | ||
| <CampaignErrorDialogComponent {...defaultProps} errorType="REMOVE_FAILED" isOpen={true} /> | ||
| ); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should match snapshot when dialog is closed', () => { | ||
| const {container} = render(<CampaignErrorDialogComponent {...defaultProps} isOpen={false} />); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); |
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.
doesnt momentum have a dialog you can use? and can you make a generic dialog that accepts props and then use that here? That way if we need another one we don't have to do this again
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.
It does! However the momentum-design package has not been updated in 11 months and the changes necessary to use the newer version are large enough that they should be their own story.
I'd be happy to take that story as well.
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.
This PR bumps momentum to latest: #665
Is this dialog component still required after the bump PR is merged?
If not, let's have a ticket to use native momentum dialog instead of this new component
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.
@brain-frog