-
Notifications
You must be signed in to change notification settings - Fork 12k
chore: apply useQuery
on InviteUsers
#35861
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
6 commits
Select commit
Hold shift + click to select a range
548bfcd
refactor: endpoint call with `useQuery` and handle result states
juliajforesti 5b3e082
chore: review
juliajforesti 81944a9
chore: review code repetition
juliajforesti cd7f56f
chore: add stories and a11y test
juliajforesti 96212eb
fix: a11y
juliajforesti 342df8f
test: add InviteUsers unit tests
juliajforesti 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
30 changes: 30 additions & 0 deletions
30
apps/meteor/client/views/room/contextualBar/RoomMembers/InviteUsers/InviteUsers.spec.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,30 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { composeStories } from '@storybook/react'; | ||
import { render } from '@testing-library/react'; | ||
import { axe } from 'jest-axe'; | ||
|
||
import * as stories from './InviteUsers.stories'; | ||
|
||
const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]); | ||
|
||
beforeEach(() => { | ||
jest.mock('react', () => ({ | ||
...jest.requireActual('react'), | ||
useId: () => 1, | ||
})); | ||
}); | ||
|
||
test.each(testCases)(`renders %s without crashing`, async (_storyname, Story) => { | ||
const view = render(<Story />); | ||
expect(view.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
test.each(testCases)('%s should have no a11y violations', async (_storyname, Story) => { | ||
const { container } = render(<Story />); | ||
|
||
/** | ||
** Disable 'nested-interactive' rule because our `Select` component is still not a11y compliant | ||
**/ | ||
const results = await axe(container, { rules: { 'nested-interactive': { enabled: false } } }); | ||
expect(results).toHaveNoViolations(); | ||
}); |
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
50 changes: 6 additions & 44 deletions
50
apps/meteor/client/views/room/contextualBar/RoomMembers/InviteUsers/InviteUsers.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 |
---|---|---|
@@ -1,58 +1,20 @@ | ||
import { Callout } from '@rocket.chat/fuselage'; | ||
import type { ReactElement } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import EditInviteLink from './EditInviteLink'; | ||
import InviteLink from './InviteLink'; | ||
import { | ||
ContextualbarHeader, | ||
ContextualbarTitle, | ||
ContextualbarBack, | ||
ContextualbarClose, | ||
ContextualbarScrollableContent, | ||
} from '../../../../../components/Contextualbar'; | ||
import InviteUsersWrapper from './InviteUsersWrapper'; | ||
|
||
type InviteUsersProps = { | ||
onClickBackMembers?: () => void; | ||
onClickBackLink?: () => void; | ||
onClickNewLink: (daysAndMaxUses: { days: string; maxUses: string }) => void; | ||
onClose: () => void; | ||
isEditing: boolean; | ||
daysAndMaxUses: { days: string; maxUses: string }; | ||
onClickEdit: () => void; | ||
captionText: string; | ||
linkText: string; | ||
error?: Error; | ||
}; | ||
|
||
const InviteUsers = ({ | ||
onClickBackMembers, | ||
onClickBackLink, | ||
onClickNewLink, | ||
onClose, | ||
isEditing, | ||
onClickEdit, | ||
daysAndMaxUses, | ||
captionText, | ||
linkText, | ||
error, | ||
}: InviteUsersProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<> | ||
<ContextualbarHeader> | ||
{(onClickBackMembers || onClickBackLink) && <ContextualbarBack onClick={isEditing ? onClickBackLink : onClickBackMembers} />} | ||
<ContextualbarTitle>{t('Invite_Users')}</ContextualbarTitle> | ||
{onClose && <ContextualbarClose onClick={onClose} />} | ||
</ContextualbarHeader> | ||
<ContextualbarScrollableContent> | ||
{error && <Callout type='danger'>{error.toString()}</Callout>} | ||
{isEditing && !error && <EditInviteLink onClickNewLink={onClickNewLink} daysAndMaxUses={daysAndMaxUses} />} | ||
{!isEditing && !error && <InviteLink captionText={captionText} onClickEdit={onClickEdit} linkText={linkText} />} | ||
</ContextualbarScrollableContent> | ||
</> | ||
); | ||
}; | ||
const InviteUsers = ({ onClickBackMembers, onClose, onClickEdit, captionText, linkText }: InviteUsersProps): ReactElement => ( | ||
<InviteUsersWrapper onClickBack={onClickBackMembers} onClose={onClose}> | ||
<InviteLink captionText={captionText} onClickEdit={onClickEdit} linkText={linkText} /> | ||
</InviteUsersWrapper> | ||
); | ||
|
||
export default InviteUsers; |
21 changes: 21 additions & 0 deletions
21
apps/meteor/client/views/room/contextualBar/RoomMembers/InviteUsers/InviteUsersEdit.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,21 @@ | ||
import type { ReactElement } from 'react'; | ||
|
||
import EditInviteLink from './EditInviteLink'; | ||
import InviteUsersWrapper from './InviteUsersWrapper'; | ||
|
||
type InviteUsersEditProps = { | ||
onClickBackLink?: () => void; | ||
onClickNewLink: (daysAndMaxUses: { days: string; maxUses: string }) => void; | ||
onClose: () => void; | ||
daysAndMaxUses: { days: string; maxUses: string }; | ||
}; | ||
|
||
const InviteUsersEdit = ({ onClickBackLink, onClickNewLink, onClose, daysAndMaxUses }: InviteUsersEditProps): ReactElement => { | ||
return ( | ||
<InviteUsersWrapper onClickBack={onClickBackLink} onClose={onClose}> | ||
<EditInviteLink onClickNewLink={onClickNewLink} daysAndMaxUses={daysAndMaxUses} /> | ||
</InviteUsersWrapper> | ||
); | ||
}; | ||
|
||
export default InviteUsersEdit; |
18 changes: 18 additions & 0 deletions
18
apps/meteor/client/views/room/contextualBar/RoomMembers/InviteUsers/InviteUsersError.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,18 @@ | ||
import { Callout } from '@rocket.chat/fuselage'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import InviteUsersWrapper from './InviteUsersWrapper'; | ||
|
||
type InviteUsersProps = { | ||
onClose: () => void; | ||
error: Error; | ||
onClickBack?: (() => void) | undefined; | ||
}; | ||
|
||
const InviteUsersError = ({ onClose, error, onClickBack }: InviteUsersProps): ReactElement => ( | ||
<InviteUsersWrapper onClose={onClose} onClickBack={onClickBack}> | ||
<Callout type='danger'>{(error || '').toString()}</Callout> | ||
</InviteUsersWrapper> | ||
); | ||
|
||
export default InviteUsersError; |
17 changes: 17 additions & 0 deletions
17
apps/meteor/client/views/room/contextualBar/RoomMembers/InviteUsers/InviteUsersLoading.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,17 @@ | ||
import { Skeleton } from '@rocket.chat/fuselage'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import InviteUsersWrapper from './InviteUsersWrapper'; | ||
|
||
type InviteUsersProps = { | ||
onClose: () => void; | ||
onClickBack: (() => void) | undefined; | ||
}; | ||
|
||
const InviteUsersLoading = ({ onClose, onClickBack: onClickBackMembers }: InviteUsersProps): ReactElement => ( | ||
<InviteUsersWrapper onClose={onClose} onClickBack={onClickBackMembers}> | ||
<Skeleton w='full' /> | ||
dougfabris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</InviteUsersWrapper> | ||
); | ||
|
||
export default InviteUsersLoading; |
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.
Uh oh!
There was an error while loading. Please reload this page.