2020-04-19 22:45:09 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
2020-04-26 15:32:50 +02:00
|
|
|
import { remSize } from '../../../theme';
|
2020-04-19 22:45:09 +02:00
|
|
|
|
2020-05-26 22:17:24 +02:00
|
|
|
import { GithubIcon, GoogleIcon } from '../../../common/icons';
|
2020-04-19 22:45:09 +02:00
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
|
|
|
const authUrls = {
|
2020-05-11 22:28:18 +02:00
|
|
|
github: '/auth/github',
|
|
|
|
google: '/auth/google'
|
2020-04-19 22:45:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const labels = {
|
2020-05-11 22:28:18 +02:00
|
|
|
github: 'Login with GitHub',
|
|
|
|
google: 'Login with Google'
|
|
|
|
};
|
|
|
|
|
|
|
|
const icons = {
|
2020-05-19 18:31:36 +02:00
|
|
|
github: GithubIcon,
|
|
|
|
google: GoogleIcon
|
2020-04-19 22:45:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const services = {
|
2020-05-11 22:28:18 +02:00
|
|
|
github: 'github',
|
|
|
|
google: 'google'
|
2020-04-19 22:45:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)`
|
|
|
|
width: ${remSize(300)};
|
|
|
|
`;
|
|
|
|
|
|
|
|
function SocialAuthButton({ service }) {
|
2020-05-11 22:28:18 +02:00
|
|
|
const ServiceIcon = icons[service];
|
2020-04-19 22:45:09 +02:00
|
|
|
return (
|
|
|
|
<StyledButton
|
2020-05-19 18:31:36 +02:00
|
|
|
iconBefore={<ServiceIcon aria-label={`${service} logo`} />}
|
2020-04-19 22:45:09 +02:00
|
|
|
href={authUrls[service]}
|
|
|
|
>
|
2020-05-19 18:31:36 +02:00
|
|
|
{labels[service]}
|
2020-04-19 22:45:09 +02:00
|
|
|
</StyledButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SocialAuthButton.services = services;
|
|
|
|
|
|
|
|
SocialAuthButton.propTypes = {
|
2020-05-11 22:28:18 +02:00
|
|
|
service: PropTypes.oneOf(['github', 'google']).isRequired
|
2020-04-19 22:45:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default SocialAuthButton;
|