File size: 3,520 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
// @flow
import * as React from 'react';
import compose from 'recompose/compose';
import FullscreenView from 'src/components/fullscreenView';
import LoginButtonSet from 'src/components/loginButtonSet';
import { CommunityAvatar } from 'src/components/avatar';
import { CLIENT_URL } from 'src/api/constants';
import {
Title,
Subtitle,
LoginImageContainer,
FullscreenContent,
CodeOfConduct,
} from './style';
import viewNetworkHandler, {
type ViewNetworkHandlerType,
} from 'src/components/viewNetworkHandler';
import {
getCommunityByMatch,
type GetCommunityType,
} from 'shared/graphql/queries/community/getCommunity';
import queryString from 'query-string';
import { LoadingView, ErrorView } from 'src/views/viewHelpers';
import { OutlineButton } from 'src/components/button';
type Props = {
data: {
community: GetCommunityType,
},
...$Exact<ViewNetworkHandlerType>,
history: Object,
location: Object,
match: Object,
redirectPath: ?string,
};
type State = {
redirectPath: ?string,
};
export class Login extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
redirectPath: props.redirectPath,
};
}
escape = () => {
this.props.history.push(`/${this.props.match.params.communitySlug}`);
};
componentDidMount() {
const { location, redirectPath } = this.props;
if (redirectPath) {
this.setState({ redirectPath });
}
if (location && !redirectPath) {
const searchObj = queryString.parse(this.props.location.search);
this.setState({ redirectPath: searchObj.r });
}
}
render() {
const {
data: { community },
isLoading,
match,
} = this.props;
const { redirectPath } = this.state;
if (community && community.id) {
return (
<FullscreenView closePath={`${CLIENT_URL}`}>
<FullscreenContent
data-cy="community-login-page"
style={{ justifyContent: 'center' }}
>
<LoginImageContainer>
<CommunityAvatar
community={community}
showHoverProfile={false}
size={88}
/>
</LoginImageContainer>
<Title>Log in</Title>
<Subtitle>
Spectrum is a place where communities can share, discuss, and grow
together. Sign in below to get in on the conversation.
</Subtitle>
<LoginButtonSet
redirectPath={
redirectPath || `${CLIENT_URL}/${match.params.communitySlug}`
}
signinType={'signin'}
githubOnly
/>
<OutlineButton
css={{ width: '100%' }}
to={`/login?r=${redirectPath ||
`${CLIENT_URL}/${match.params.communitySlug}`}`}
>
Existing user? Click here to log in
</OutlineButton>
<CodeOfConduct>
By using Spectrum, you agree to our{' '}
<a
href="https://github.com/withspectrum/code-of-conduct"
target="_blank"
rel="noopener noreferrer"
>
Code of Conduct
</a>
</CodeOfConduct>
</FullscreenContent>
</FullscreenView>
);
}
if (isLoading) return <LoadingView />;
return <ErrorView />;
}
}
export default compose(
getCommunityByMatch,
viewNetworkHandler
)(Login);
|