Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 8c58466

Browse files
authored
Merge pull request #4681 from withspectrum/accessible-login
Accessible login
2 parents 27f9f4d + 6e52178 commit 8c58466

File tree

8 files changed

+41
-93
lines changed

8 files changed

+41
-93
lines changed

src/components/fullscreenView/index.js

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React, { Component } from 'react';
23
import {
34
ClusterOne,
@@ -6,9 +7,15 @@ import {
67
ClusterFour,
78
} from '../../components/illustrations';
89
import Icon from '../../components/icons';
9-
import { FullscreenViewContainer, Illustrations, Close } from './style';
10+
import { FullscreenViewContainer, Illustrations, CloseLink } from './style';
1011
import { ESC } from 'src/helpers/keycodes';
11-
class FullscreenView extends Component {
12+
13+
type Props = {
14+
closePath: string,
15+
children: any,
16+
};
17+
18+
class FullscreenView extends Component<Props> {
1219
componentDidMount() {
1320
document.addEventListener('keydown', this.handleKeyPress, false);
1421
}
@@ -17,44 +24,29 @@ class FullscreenView extends Component {
1724
document.removeEventListener('keydown', this.handleKeyPress, false);
1825
}
1926

20-
handleKeyPress = e => {
21-
const { close, noCloseButton } = this.props;
22-
23-
// if we don't want the user to close the onboarding flow - when they
24-
// are setting a username - ignore esc key presses
25-
if (noCloseButton) return;
26-
27+
handleKeyPress = (e: any) => {
28+
const { closePath } = this.props;
2729
// if person taps esc, close the dialog
28-
if (e.keyCode === ESC) {
29-
return close();
30+
if (closePath && e.keyCode === ESC) {
31+
return (window.location = closePath);
3032
}
3133
};
3234

3335
render() {
34-
const {
35-
close,
36-
hasBackground,
37-
children,
38-
noCloseButton,
39-
showBackgroundOnMobile = true,
40-
} = this.props;
36+
const { closePath, children } = this.props;
4137

4238
return (
4339
<FullscreenViewContainer>
44-
{!noCloseButton && (
45-
<Close onClick={close}>
46-
<Icon glyph={'view-close'} size={32} />
47-
</Close>
48-
)}
49-
50-
{hasBackground && (
51-
<Illustrations showBackgroundOnMobile={showBackgroundOnMobile}>
52-
<ClusterOne src="/img/cluster-2.svg" role="presentation" />
53-
<ClusterTwo src="/img/cluster-1.svg" role="presentation" />
54-
<ClusterThree src="/img/cluster-5.svg" role="presentation" />
55-
<ClusterFour src="/img/cluster-4.svg" role="presentation" />
56-
</Illustrations>
57-
)}
40+
<CloseLink href={closePath}>
41+
<Icon glyph={'view-close'} size={32} />
42+
</CloseLink>
43+
44+
<Illustrations>
45+
<ClusterOne src="/img/cluster-2.svg" role="presentation" />
46+
<ClusterTwo src="/img/cluster-1.svg" role="presentation" />
47+
<ClusterThree src="/img/cluster-5.svg" role="presentation" />
48+
<ClusterFour src="/img/cluster-4.svg" role="presentation" />
49+
</Illustrations>
5850

5951
{children}
6052
</FullscreenViewContainer>

src/components/fullscreenView/style.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ export const FullscreenViewContainer = styled.div`
2424
export const Illustrations = styled.span`
2525
z-index: ${zIndex.background};
2626
27-
${p =>
28-
!p.showBackgroundOnMobile &&
29-
css`
30-
@media screen and (max-width: 768px) {
31-
display: none;
32-
}
33-
`};
27+
@media screen and (max-width: 768px) {
28+
display: none;
29+
}
3430
`;
3531

36-
export const Close = styled.div`
32+
export const CloseLink = styled.a`
3733
color: ${theme.text.default};
3834
position: absolute;
3935
top: 8px;

src/components/upsell/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const UpsellMiniCreateCommunity = () => {
9292
// to create a community rather than joining communities - if they choose
9393
// to go down the path of creating a community, clicking on the 'get started'
9494
// button will close the new user onboarding
95-
export const UpsellCreateCommunity = ({ close }: { close: Function }) => {
95+
export const UpsellCreateCommunity = () => {
9696
const title = 'Create a community';
9797
const subtitle = 'Building communities on Spectrum is easy and free forever';
9898

src/routes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { withCurrentUser } from 'src/components/withCurrentUser';
3232
import Maintenance from 'src/components/maintenance';
3333
import type { GetUserType } from 'shared/graphql/queries/user/getUser';
3434
import RedirectOldThreadRoute from './views/thread/redirect-old-route';
35+
import NewUserOnboarding from './views/newUserOnboarding';
3536

3637
/* prettier-ignore */
3738
const Explore = Loadable({
@@ -267,6 +268,8 @@ class Routes extends React.Component<Props> {
267268
<Redirect
268269
to={`/users/${currentUser.username}/settings`}
269270
/>
271+
) : currentUser && !currentUser.username ? (
272+
<NewUserOnboarding />
270273
) : isLoadingCurrentUser ? null : (
271274
<Login redirectPath={`${CLIENT_URL}/me/settings`} />
272275
)

src/views/communityLogin/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Login extends React.Component<Props> {
6868
const { brandedLogin } = community;
6969

7070
return (
71-
<FullscreenView hasBackground noCloseButton={true} close={null}>
71+
<FullscreenView closePath={`${CLIENT_URL}`}>
7272
<FullscreenContent
7373
data-cy="community-login-page"
7474
style={{ justifyContent: 'center' }}
@@ -117,14 +117,14 @@ export class Login extends React.Component<Props> {
117117

118118
if (isLoading) {
119119
return (
120-
<FullscreenView>
120+
<FullscreenView closePath={CLIENT_URL}>
121121
<Loading />
122122
</FullscreenView>
123123
);
124124
}
125125

126126
return (
127-
<FullscreenView close={this.escape}>
127+
<FullscreenView closePath={CLIENT_URL}>
128128
<ViewError
129129
refresh
130130
heading={'We had trouble finding this community'}

src/views/dashboard/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ class Dashboard extends React.Component<Props, State> {
112112
if (user) {
113113
// if the user hasn't joined any communities yet, we have nothing to show them on the dashboard. So instead just render the onboarding step to upsell popular communities to join
114114
if (user.communityConnection.edges.length === 0) {
115-
return (
116-
<NewUserOnboarding
117-
noCloseButton
118-
close={() => {}}
119-
currentUser={user}
120-
/>
121-
);
115+
return <NewUserOnboarding currentUser={user} />;
122116
}
123117

124118
// at this point we have succesfully validated a user, and the user has both a username and joined communities - we can show their thread feed!

src/views/login/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from './style';
1616
import queryString from 'query-string';
1717
import { track, events } from 'src/helpers/analytics';
18+
import { CLIENT_URL } from 'src/api/constants';
1819

1920
type Props = {
2021
redirectPath: ?string,
@@ -46,12 +47,7 @@ export class Login extends React.Component<Props> {
4647
: 'Spectrum is a place where communities can share, discuss, and grow together. Sign in below to get in on the conversation.';
4748

4849
return (
49-
<FullscreenView
50-
hasBackground
51-
// $FlowFixMe
52-
noCloseButton={!this.props.close}
53-
close={this.props.close && this.props.close}
54-
>
50+
<FullscreenView closePath={CLIENT_URL}>
5551
<FullscreenContent
5652
data-cy="login-page"
5753
style={{ justifyContent: 'center' }}

src/views/newUserOnboarding/index.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ import { track, events } from 'src/helpers/analytics';
2525
import type { UserInfoType } from 'shared/graphql/fragments/user/userInfo';
2626
import type { CommunityInfoType } from 'shared/graphql/fragments/community/communityInfo';
2727
import { isDesktopApp } from 'src/helpers/desktop-app-utils';
28+
import { SERVER_URL } from 'src/api/constants';
2829

2930
type StateProps = {|
3031
community: CommunityInfoType,
3132
|};
3233

3334
type Props = StateProps & {|
3435
currentUser: UserInfoType,
35-
close: Function,
36-
noCloseButton: boolean,
3736
|};
3837

3938
type ActiveStep =
@@ -89,18 +88,9 @@ class NewUserOnboarding extends Component<Props, State> {
8988

9089
saveUsername = () => {
9190
const { community } = this.props;
92-
9391
track(events.USER_ONBOARDING_SET_USERNAME);
94-
9592
if (!isDesktopApp()) return this.toStep('appsUpsell');
9693

97-
// if the user signed up via a community, channel, or thread view, the first
98-
// thing they will be asked to do is set a username. After they save their
99-
// username, they should proceed to the 'joinFirstCommunity' step; otherwise
100-
// we can just close the onboarding
101-
if (community) {
102-
return this.props.close();
103-
}
10494
return this.toStep('joinFirstCommunity');
10595
};
10696

@@ -123,29 +113,11 @@ class NewUserOnboarding extends Component<Props, State> {
123113
// or decrement the joinedCommunities count in state
124114
let newCount = joinedCommunities + number;
125115
this.setState({ joinedCommunities: newCount });
126-
127-
// if the user signed up from a community, channel, or thread view,
128-
// they will see an onboarding step to join that community they were
129-
// viewing in order to complete their onboarding. when they do join
130-
// that community, we pass a finish argument which will push them forward
131-
// in the onboarding flow
132-
if (done) {
133-
return this.props.close();
134-
}
135116
};
136117

137118
appUpsellComplete = () => {
138119
const { community } = this.props;
139120

140-
// if the user signed up via a community, channel, or thread view, the first
141-
// thing they will be asked to do is set a username. After they save their
142-
// username, they should proceed to the 'joinFirstCommunity' step; otherwise
143-
// we can just close the onboarding
144-
if (!community) return this.props.close();
145-
// if the user signed in via a comunity, channel, or thread view, but they
146-
// are already members of that community, we can escape the onboarding
147-
if (community.communityPermissions.isMember) return this.props.close();
148-
149121
// if the user signed up via a community, channel, or thread view and
150122
// has not yet joined that community, move them to that step in the onboarding
151123
return this.toStep('joinFirstCommunity');
@@ -192,12 +164,7 @@ class NewUserOnboarding extends Component<Props, State> {
192164
};
193165

194166
return (
195-
<FullscreenView
196-
hasBackground
197-
showBackgroundOnMobile={false}
198-
close={this.props.close}
199-
noCloseButton={this.props.noCloseButton}
200-
>
167+
<FullscreenView closePath={`${SERVER_URL}/auth/logout`}>
201168
<OnboardingContainer>
202169
<OnboardingContent>
203170
<IconContainer>
@@ -228,7 +195,7 @@ class NewUserOnboarding extends Component<Props, State> {
228195
curatedContentType={'top-communities-by-members'}
229196
/>
230197
<CreateUpsellContainer extra={joinedCommunities > 0}>
231-
<UpsellCreateCommunity close={this.props.close} />
198+
<UpsellCreateCommunity />
232199
</CreateUpsellContainer>
233200

234201
<StickyRow hasJoined={joinedCommunities > 0}>

0 commit comments

Comments
 (0)