2020-04-19 22:45:09 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
2020-08-12 16:24:29 +02:00
|
|
|
import i18n from 'i18next';
|
|
|
|
import { withTranslation } from 'react-i18next';
|
2020-04-19 22:45:09 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-05-11 22:28:18 +02:00
|
|
|
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)};
|
|
|
|
`;
|
|
|
|
|
2020-08-12 16:24:29 +02:00
|
|
|
function SocialAuthButton({ service, t }) {
|
2020-05-11 22:28:18 +02:00
|
|
|
const ServiceIcon = icons[service];
|
2020-08-12 16:24:29 +02:00
|
|
|
const labels = {
|
|
|
|
github: t('SocialAuthButton.Github'),
|
|
|
|
google: t('SocialAuthButton.Google')
|
|
|
|
};
|
2020-04-19 22:45:09 +02:00
|
|
|
return (
|
|
|
|
<StyledButton
|
2020-08-12 16:24:29 +02:00
|
|
|
iconBefore={<ServiceIcon aria-label={t('SocialAuthButton.LogoARIA', { serviceauth: service })} />}
|
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-08-12 16:24:29 +02:00
|
|
|
service: PropTypes.oneOf(['github', 'google']).isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2020-04-19 22:45:09 +02:00
|
|
|
};
|
|
|
|
|
2020-08-12 16:24:29 +02:00
|
|
|
const SocialAuthButtonPublic = withTranslation()(SocialAuthButton);
|
|
|
|
SocialAuthButtonPublic.services = services;
|
|
|
|
export default SocialAuthButtonPublic;
|