-
Notifications
You must be signed in to change notification settings - Fork 1
Add Static Banner #799
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
Open
caleballdrin
wants to merge
11
commits into
main
Choose a base branch
from
add-banner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Static Banner #799
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e35e849
add static banner
caleballdrin 92c0b20
Fix test and add useeffect
caleballdrin 848699a
organizations type graphql
caleballdrin 0ca95b4
Merge branch 'add-banner' of https://github.com/CruGlobal/mpdx-react …
caleballdrin ed4e90a
Add test data mocks and use loading before showing banner
caleballdrin 78cb0f0
Add tests and add useMemo for checking the organization
caleballdrin 4a91583
Add SHOW_BANNER env to the readme
caleballdrin 1ed981b
Update static banner warning message text
caleballdrin 17d3998
Move shouldShowBanner inside component
caleballdrin 21adbe4
Refactor tests for static banner and move process.env out of component
caleballdrin a52647a
Simplify tests
caleballdrin 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { render, waitFor } from '@testing-library/react'; | ||
| import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
| import { GetUsersOrganizationsQuery } from './getOrganizationType.generated'; | ||
| import { StaticBanner } from './StaticBanner'; | ||
|
|
||
| const mockResponseNonCru = { | ||
| GetUsersOrganizations: { | ||
| userOrganizationAccounts: [ | ||
| { | ||
| organization: { | ||
| organizationType: 'Non-Cru', | ||
| }, | ||
| }, | ||
| { | ||
| organization: { | ||
| organizationType: 'Non-Cru', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| const mockResponseCru = { | ||
| GetUsersOrganizations: { | ||
| userOrganizationAccounts: [ | ||
| { | ||
| organization: { | ||
| organizationType: 'Cru', | ||
| }, | ||
| }, | ||
| { | ||
| organization: { | ||
| organizationType: 'Non-Cru', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| test('static banner displays for user in Non-Cru org', async () => { | ||
| const { queryByTestId } = render( | ||
| <GqlMockedProvider<{ | ||
| GetUsersOrganizations: GetUsersOrganizationsQuery; | ||
| }> | ||
| mocks={{ | ||
| mockResponseNonCru, | ||
| }} | ||
| > | ||
| <StaticBanner /> | ||
| </GqlMockedProvider>, | ||
| ); | ||
|
|
||
| await waitFor(() => | ||
| expect(queryByTestId('nonCruOrgReminder')).toBeInTheDocument(), | ||
| ); | ||
| }); | ||
|
|
||
| test('static banner does not display for user in a Cru org', async () => { | ||
| const { queryByTestId } = render( | ||
| <GqlMockedProvider<{ | ||
| GetUsersOrganizations: GetUsersOrganizationsQuery; | ||
| }> | ||
| mocks={{ | ||
| mockResponseCru, | ||
| }} | ||
| > | ||
| <StaticBanner /> | ||
| </GqlMockedProvider>, | ||
| ); | ||
|
|
||
| await waitFor(() => | ||
| expect(queryByTestId('nonCruOrgReminder')).not.toBeInTheDocument(), | ||
| ); | ||
| }); |
caleballdrin marked this conversation as resolved.
Show resolved
Hide resolved
|
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, { useMemo } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import Alert from '@mui/material/Alert'; | ||
| import { Link } from '@mui/material'; | ||
| import { useGetUsersOrganizationsQuery } from './getOrganizationType.generated'; | ||
|
|
||
| interface StaticBannerProps { | ||
| severity?: 'error' | 'info' | 'success' | 'warning'; | ||
| } | ||
|
|
||
| export const StaticBanner: React.FC<StaticBannerProps> = ({ | ||
| severity = 'warning', | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const { data, loading } = useGetUsersOrganizationsQuery(); | ||
| const nonCruUser = useMemo(() => { | ||
| const foundCruOrg = data?.userOrganizationAccounts.some( | ||
| (org) => | ||
| org.organization.organizationType === 'Cru-International' || | ||
| org.organization.organizationType === 'Cru', | ||
| ); | ||
| return !foundCruOrg; | ||
| }, [data]); | ||
|
|
||
| return ( | ||
| <div data-testid="staticBanner"> | ||
| {!loading && nonCruUser ? ( | ||
| <Alert severity={severity}> | ||
| {t( | ||
| `Due to data privacy regulations and costs, Cru will no longer be able to host MPDX data for non-Cru/non-CCCI ministries. `, | ||
| )} | ||
| <b> | ||
| {t( | ||
| `Your data in MPDX will be deleted if you don’t export from MPDX by January 31, 2024,`, | ||
| )} | ||
| </b> | ||
| {t( | ||
| ` or let us know why you might need an extension. For more information and to take action, read `, | ||
| )} | ||
| <Link | ||
| data-testid="nonCruOrgReminder" | ||
| href="https://docs.google.com/document/d/18TnQGmshg71l3J9Gd-4ltjIjhK2PLtuG_Vc94bt6xzE/" | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| > | ||
| {t('this communication.')} | ||
| </Link> | ||
| </Alert> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| }; |
7 changes: 7 additions & 0 deletions
7
src/components/Shared/staticBanner/getOrganizationType.graphql
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,7 @@ | ||
| query GetUsersOrganizations { | ||
| userOrganizationAccounts { | ||
| organization { | ||
| organizationType | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.