2020-04-19 20:45:09 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
2020-08-12 14:24:29 +00:00
|
|
|
import i18n from 'i18next';
|
|
|
|
import { withTranslation } from 'react-i18next';
|
2020-04-19 20:45:09 +00:00
|
|
|
|
2020-04-26 13:32:50 +00:00
|
|
|
import { remSize } from '../../../theme';
|
2020-04-19 20:45:09 +00:00
|
|
|
|
2020-05-26 20:17:24 +00:00
|
|
|
import { GithubIcon, GoogleIcon } from '../../../common/icons';
|
2020-04-19 20:45:09 +00:00
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
|
|
|
const authUrls = {
|
2020-05-11 20:28:18 +00:00
|
|
|
github: '/auth/github',
|
|
|
|
google: '/auth/google'
|
2020-04-19 20:45:09 +00:00
|
|
|
};
|
|
|
|
|
2020-05-11 20:28:18 +00:00
|
|
|
const icons = {
|
2020-05-19 16:31:36 +00:00
|
|
|
github: GithubIcon,
|
|
|
|
google: GoogleIcon
|
2020-04-19 20:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const services = {
|
2020-05-11 20:28:18 +00:00
|
|
|
github: 'github',
|
|
|
|
google: 'google'
|
2020-04-19 20:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)`
|
|
|
|
width: ${remSize(300)};
|
|
|
|
`;
|
|
|
|
|
2020-08-12 14:24:29 +00:00
|
|
|
function SocialAuthButton({ service, t }) {
|
2020-05-11 20:28:18 +00:00
|
|
|
const ServiceIcon = icons[service];
|
2020-08-12 14:24:29 +00:00
|
|
|
const labels = {
|
|
|
|
github: t('SocialAuthButton.Github'),
|
|
|
|
google: t('SocialAuthButton.Google')
|
|
|
|
};
|
2020-04-19 20:45:09 +00:00
|
|
|
return (
|
|
|
|
<StyledButton
|
2020-08-12 14:24:29 +00:00
|
|
|
iconBefore={<ServiceIcon aria-label={t('SocialAuthButton.LogoARIA', { serviceauth: service })} />}
|
2020-04-19 20:45:09 +00:00
|
|
|
href={authUrls[service]}
|
|
|
|
>
|
2020-05-19 16:31:36 +00:00
|
|
|
{labels[service]}
|
2020-04-19 20:45:09 +00:00
|
|
|
</StyledButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SocialAuthButton.services = services;
|
|
|
|
|
|
|
|
SocialAuthButton.propTypes = {
|
2020-08-12 14:24:29 +00:00
|
|
|
service: PropTypes.oneOf(['github', 'google']).isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2020-04-19 20:45:09 +00:00
|
|
|
};
|
|
|
|
|
2020-08-12 14:24:29 +00:00
|
|
|
const SocialAuthButtonPublic = withTranslation()(SocialAuthButton);
|
|
|
|
SocialAuthButtonPublic.services = services;
|
|
|
|
export default SocialAuthButtonPublic;
|