-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add member validation alert (#1350)
* feat: add member validation alert * fix: add test to check presence of the banner * fix: remove empty useEffect in main component * fix: apply review comments * fix: allow legacy members to exist and don't show them the banner
- Loading branch information
Showing
21 changed files
with
158 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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,31 @@ | ||
import { | ||
MEMBER_VALIDATION_BANNER_CLOSE_BUTTON_ID, | ||
MEMBER_VALIDATION_BANNER_ID, | ||
} from '@/config/selectors'; | ||
|
||
import { | ||
LEGACY_NOT_VALIDATED_MEMBER, | ||
NOT_VALIDATED_MEMBER, | ||
VALIDATED_MEMBER, | ||
} from '../fixtures/members'; | ||
|
||
describe('Member validation banner', () => { | ||
it('Shows banner when member is not validated', () => { | ||
cy.setUpApi({ currentMember: NOT_VALIDATED_MEMBER }); | ||
cy.visit('/'); | ||
cy.get(`#${MEMBER_VALIDATION_BANNER_ID}`).should('be.visible'); | ||
cy.get(`#${MEMBER_VALIDATION_BANNER_CLOSE_BUTTON_ID}`).click(); | ||
}); | ||
|
||
it('Does not show banner when member is validated', () => { | ||
cy.setUpApi({ currentMember: VALIDATED_MEMBER }); | ||
cy.visit('/'); | ||
cy.get(`#${MEMBER_VALIDATION_BANNER_ID}`).should('not.exist'); | ||
}); | ||
|
||
it('Does not show banner when member is legacy', () => { | ||
cy.setUpApi({ currentMember: LEGACY_NOT_VALIDATED_MEMBER }); | ||
cy.visit('/'); | ||
cy.get(`#${MEMBER_VALIDATION_BANNER_ID}`).should('not.exist'); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ export const MEMBERS: Record<string, MemberForTest> = { | |
lang: 'fr', | ||
emailFreq: 'never', | ||
}, | ||
isValidated: true, | ||
}), | ||
BOB: { | ||
...MemberFactory({ | ||
|
@@ -80,10 +81,19 @@ export const MEMBERS: Record<string, MemberForTest> = { | |
email: '[email protected]', | ||
createdAt: '2021-04-13 14:56:34.749946', | ||
updatedAt: '2021-04-13 14:56:34.749946', | ||
isValidated: false, | ||
}), | ||
}; | ||
|
||
export const CURRENT_USER = MEMBERS.ANNA; | ||
export const NOT_VALIDATED_MEMBER = MEMBERS.GARRY; | ||
export const VALIDATED_MEMBER = MEMBERS.ANNA; | ||
export const LEGACY_NOT_VALIDATED_MEMBER = { | ||
...NOT_VALIDATED_MEMBER, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
isValidated: undefined, | ||
}; | ||
|
||
export const MOCK_SESSIONS = [ | ||
{ id: MEMBERS.BOB.id, token: 'bob-token', createdAt: Date.now() }, | ||
|
This file contains 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 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,76 @@ | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { | ||
Alert, | ||
AlertTitle, | ||
IconButton, | ||
Link as MUILink, | ||
Stack, | ||
} from '@mui/material'; | ||
|
||
import { XIcon } from 'lucide-react'; | ||
|
||
import { useBuilderTranslation } from '@/config/i18n'; | ||
import { hooks } from '@/config/queryClient'; | ||
import { | ||
MEMBER_VALIDATION_BANNER_CLOSE_BUTTON_ID, | ||
MEMBER_VALIDATION_BANNER_ID, | ||
} from '@/config/selectors'; | ||
import { BUILDER } from '@/langs/constants'; | ||
|
||
import useModalStatus from '../hooks/useModalStatus'; | ||
|
||
const DOCUMENTATION_ORIGIN = 'https://graasp.github.io/docs'; | ||
const MEMBER_VALIDATION_DOCUMENTATION_LINK = '/user/account/validation'; | ||
const buildLocalizedDocumentationOrigin = (lang: string = 'en') => { | ||
switch (lang) { | ||
case 'en': | ||
return DOCUMENTATION_ORIGIN; | ||
default: | ||
return `${DOCUMENTATION_ORIGIN}/${lang}`; | ||
} | ||
}; | ||
// eslint-disable-next-line arrow-body-style | ||
const buildLocalizedDocumentationLink = (lang: string): string => { | ||
// english does not use a path prefix | ||
return `${buildLocalizedDocumentationOrigin(lang)}${MEMBER_VALIDATION_DOCUMENTATION_LINK}`; | ||
}; | ||
|
||
const MemberValidationBanner = (): JSX.Element | false => { | ||
const { isOpen, closeModal } = useModalStatus({ | ||
isInitiallyOpen: true, | ||
}); | ||
const { t, i18n } = useBuilderTranslation(); | ||
const { data: member } = hooks.useCurrentMember(); | ||
|
||
// banner should not be shown when the member does not have the property | ||
if (isOpen && member && 'isValidated' in member && !member.isValidated) { | ||
return ( | ||
<Alert | ||
id={MEMBER_VALIDATION_BANNER_ID} | ||
severity="warning" | ||
action={ | ||
<IconButton | ||
id={MEMBER_VALIDATION_BANNER_CLOSE_BUTTON_ID} | ||
onClick={closeModal} | ||
> | ||
<XIcon /> | ||
</IconButton> | ||
} | ||
> | ||
<AlertTitle>{t(BUILDER.MEMBER_VALIDATION_TITLE)}</AlertTitle> | ||
<Stack gap={1}> | ||
{t(BUILDER.MEMBER_VALIDATION_DESCRIPTION)} | ||
<MUILink | ||
component={Link} | ||
to={buildLocalizedDocumentationLink(i18n.language)} | ||
> | ||
{t(BUILDER.MEMBER_VALIDATION_LINK_TEXT)} | ||
</MUILink> | ||
</Stack> | ||
</Alert> | ||
); | ||
} | ||
return false; | ||
}; | ||
export default MemberValidationBanner; |
This file contains 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.