2020-05-27 09:43:28 -04:00
|
|
|
import React from 'react'
|
2020-06-07 15:29:09 -04:00
|
|
|
import { IconName } from '../../../../common/fork-awesome/fork-awesome-icon'
|
2020-05-27 09:43:28 -04:00
|
|
|
import { SocialLinkButton } from './social-link-button/social-link-button'
|
2020-05-14 09:41:38 -04:00
|
|
|
|
2020-05-16 14:59:59 -04:00
|
|
|
export enum OneClickType {
|
2020-05-27 09:43:28 -04:00
|
|
|
'DROPBOX' = 'dropbox',
|
|
|
|
'FACEBOOK' = 'facebook',
|
|
|
|
'GITHUB' = 'github',
|
|
|
|
'GITLAB' = 'gitlab',
|
|
|
|
'GOOGLE' = 'google',
|
|
|
|
'OAUTH2' = 'oauth2',
|
|
|
|
'SAML' = 'saml',
|
|
|
|
'TWITTER' = 'twitter'
|
2020-05-14 09:41:38 -04:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:59:59 -04:00
|
|
|
type OneClick2Map = (oneClickType: OneClickType) => {
|
2020-05-27 09:43:28 -04:00
|
|
|
name: string,
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: IconName,
|
2020-05-27 09:43:28 -04:00
|
|
|
className: string,
|
|
|
|
url: string
|
2020-05-14 09:41:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const buildBackendAuthUrl = (backendName: string) => {
|
2020-05-27 09:43:28 -04:00
|
|
|
return `https://localhost:3000/auth/${backendName}`
|
|
|
|
}
|
2020-05-14 09:41:38 -04:00
|
|
|
|
2020-05-16 14:59:59 -04:00
|
|
|
const getMetadata: OneClick2Map = (oneClickType: OneClickType) => {
|
2020-05-27 09:43:28 -04:00
|
|
|
switch (oneClickType) {
|
|
|
|
case OneClickType.DROPBOX:
|
|
|
|
return {
|
|
|
|
name: 'Dropbox',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'dropbox',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-dropbox',
|
|
|
|
url: buildBackendAuthUrl('dropbox')
|
|
|
|
}
|
|
|
|
case OneClickType.FACEBOOK:
|
|
|
|
return {
|
|
|
|
name: 'Facebook',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'facebook',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-facebook',
|
|
|
|
url: buildBackendAuthUrl('facebook')
|
|
|
|
}
|
|
|
|
case OneClickType.GITHUB:
|
|
|
|
return {
|
|
|
|
name: 'GitHub',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'github',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-github',
|
|
|
|
url: buildBackendAuthUrl('github')
|
|
|
|
}
|
|
|
|
case OneClickType.GITLAB:
|
|
|
|
return {
|
|
|
|
name: 'GitLab',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'gitlab',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-gitlab',
|
|
|
|
url: buildBackendAuthUrl('gitlab')
|
|
|
|
}
|
|
|
|
case OneClickType.GOOGLE:
|
|
|
|
return {
|
|
|
|
name: 'Google',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'google',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-google',
|
|
|
|
url: buildBackendAuthUrl('google')
|
|
|
|
}
|
|
|
|
case OneClickType.OAUTH2:
|
|
|
|
return {
|
|
|
|
name: 'OAuth2',
|
|
|
|
icon: 'address-card',
|
|
|
|
className: 'btn-primary',
|
|
|
|
url: buildBackendAuthUrl('oauth2')
|
|
|
|
}
|
|
|
|
case OneClickType.SAML:
|
|
|
|
return {
|
|
|
|
name: 'SAML',
|
|
|
|
icon: 'users',
|
|
|
|
className: 'btn-success',
|
|
|
|
url: buildBackendAuthUrl('saml')
|
|
|
|
}
|
|
|
|
case OneClickType.TWITTER:
|
|
|
|
return {
|
|
|
|
name: 'Twitter',
|
2020-05-31 16:21:32 -04:00
|
|
|
icon: 'twitter',
|
2020-05-27 09:43:28 -04:00
|
|
|
className: 'btn-social-twitter',
|
|
|
|
url: buildBackendAuthUrl('twitter')
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return {
|
|
|
|
name: '',
|
|
|
|
icon: 'exclamation',
|
|
|
|
className: '',
|
|
|
|
url: '#'
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 09:41:38 -04:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:59:59 -04:00
|
|
|
export interface ViaOneClickProps {
|
2020-05-27 09:43:28 -04:00
|
|
|
oneClickType: OneClickType;
|
|
|
|
optionalName?: string;
|
2020-05-14 09:41:38 -04:00
|
|
|
}
|
|
|
|
|
2020-05-27 09:43:28 -04:00
|
|
|
const ViaOneClick: React.FC<ViaOneClickProps> = ({ oneClickType, optionalName }) => {
|
|
|
|
const { name, icon, className, url } = getMetadata(oneClickType)
|
|
|
|
const text = optionalName || name
|
|
|
|
return (
|
|
|
|
<SocialLinkButton
|
|
|
|
backgroundClass={className}
|
|
|
|
icon={icon}
|
|
|
|
href={url}
|
|
|
|
title={text}
|
|
|
|
>
|
|
|
|
{text}
|
|
|
|
</SocialLinkButton>
|
|
|
|
)
|
2020-05-14 09:41:38 -04:00
|
|
|
}
|
|
|
|
|
2020-05-27 09:43:28 -04:00
|
|
|
export { ViaOneClick }
|