2019-12-16 08:49:10 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import {
|
|
|
|
|
getSocialLoginButtonProps,
|
|
|
|
|
SocialLoginType,
|
|
|
|
|
} from "constants/SocialLogin";
|
|
|
|
|
import { IntentColors, getBorderCSSShorthand } from "constants/DefaultTheme";
|
2020-03-11 13:59:46 +00:00
|
|
|
import AnalyticsUtil, { EventName } from "utils/AnalyticsUtil";
|
2020-08-03 14:18:48 +00:00
|
|
|
import { useLocation } from "react-router-dom";
|
2020-09-28 06:29:41 +00:00
|
|
|
import PerformanceTracker, {
|
|
|
|
|
PerformanceTransactionName,
|
|
|
|
|
} from "utils/PerformanceTracker";
|
2020-12-30 07:31:20 +00:00
|
|
|
import { setOnboardingState } from "utils/storage";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
const ThirdPartyAuthWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
align-items: flex-end;
|
2020-12-24 04:32:25 +00:00
|
|
|
margin-left: ${(props) => props.theme.authCard.dividerSpacing}px;
|
2019-12-16 08:49:10 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
//TODO(abhinav): Port this to use themes.
|
|
|
|
|
const StyledSocialLoginButton = styled.a`
|
|
|
|
|
width: 200px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2020-12-24 04:32:25 +00:00
|
|
|
border: ${(props) => getBorderCSSShorthand(props.theme.borders[2])};
|
2019-12-16 08:49:10 +00:00
|
|
|
padding: 8px;
|
2020-12-24 04:32:25 +00:00
|
|
|
color: ${(props) => props.theme.colors.textDefault};
|
|
|
|
|
border-radius: ${(props) => props.theme.radii[1]}px;
|
2019-12-16 08:49:10 +00:00
|
|
|
position: relative;
|
|
|
|
|
height: 42px;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
background: ${IntentColors.success};
|
2020-12-24 04:32:25 +00:00
|
|
|
color: ${(props) => props.theme.colors.textOnDarkBG};
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
& > div {
|
|
|
|
|
width: 36px;
|
|
|
|
|
height: 36px;
|
2020-12-24 04:32:25 +00:00
|
|
|
padding: ${(props) => props.theme.radii[1]}px;
|
2019-12-16 08:49:10 +00:00
|
|
|
position: absolute;
|
|
|
|
|
left: 2px;
|
|
|
|
|
top: 2px;
|
|
|
|
|
background: white;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
& img {
|
|
|
|
|
width: 80%;
|
|
|
|
|
height: 80%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
& p {
|
|
|
|
|
display: block;
|
|
|
|
|
margin: 0 0 0 36px;
|
2020-12-24 04:32:25 +00:00
|
|
|
font-size: ${(props) => props.theme.fontSizes[3]}px;
|
|
|
|
|
font-weight: ${(props) => props.theme.fontWeights[3]};
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const SocialLoginTypes: Record<string, string> = {
|
|
|
|
|
GOOGLE: "google",
|
|
|
|
|
GITHUB: "github",
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-11 13:59:46 +00:00
|
|
|
type SignInType = "SIGNIN" | "SIGNUP";
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
const SocialLoginButton = (props: {
|
|
|
|
|
logo: string;
|
|
|
|
|
name: string;
|
|
|
|
|
url: string;
|
2020-03-11 13:59:46 +00:00
|
|
|
type: SignInType;
|
2019-12-16 08:49:10 +00:00
|
|
|
}) => {
|
2020-08-03 14:18:48 +00:00
|
|
|
const location = useLocation();
|
|
|
|
|
const queryParams = new URLSearchParams(location.search);
|
|
|
|
|
let url = props.url;
|
2021-01-06 11:24:16 +00:00
|
|
|
if (queryParams.has("redirectUrl")) {
|
|
|
|
|
url += `?redirectUrl=${queryParams.get("redirectUrl")}`;
|
2020-08-03 14:18:48 +00:00
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
return (
|
2020-03-11 13:59:46 +00:00
|
|
|
<StyledSocialLoginButton
|
2020-08-03 14:18:48 +00:00
|
|
|
href={url}
|
2020-03-11 13:59:46 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
let eventName: EventName = "LOGIN_CLICK";
|
|
|
|
|
if (props.type === "SIGNUP") {
|
|
|
|
|
eventName = "SIGNUP_CLICK";
|
2020-12-30 07:31:20 +00:00
|
|
|
|
|
|
|
|
// Set onboarding flag on signup
|
|
|
|
|
setOnboardingState(true);
|
2020-03-11 13:59:46 +00:00
|
|
|
}
|
2020-09-28 06:29:41 +00:00
|
|
|
PerformanceTracker.startTracking(
|
|
|
|
|
eventName === "SIGNUP_CLICK"
|
|
|
|
|
? PerformanceTransactionName.SIGN_UP
|
|
|
|
|
: PerformanceTransactionName.LOGIN_CLICK,
|
|
|
|
|
{ name: props.name.toUpperCase() },
|
|
|
|
|
);
|
2020-03-11 13:59:46 +00:00
|
|
|
AnalyticsUtil.logEvent(eventName, {
|
|
|
|
|
loginMethod: props.name.toUpperCase(),
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
2019-12-16 08:49:10 +00:00
|
|
|
<div>
|
|
|
|
|
<img alt={` ${props.name} login`} src={props.logo} />
|
|
|
|
|
</div>
|
|
|
|
|
<p>{`Sign in with ${props.name}`}</p>
|
|
|
|
|
</StyledSocialLoginButton>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-11 13:59:46 +00:00
|
|
|
export const ThirdPartyAuth = (props: {
|
|
|
|
|
logins: SocialLoginType[];
|
|
|
|
|
type: SignInType;
|
|
|
|
|
}) => {
|
2019-12-16 08:49:10 +00:00
|
|
|
const socialLoginButtons = getSocialLoginButtonProps(props.logins).map(
|
2020-12-24 04:32:25 +00:00
|
|
|
(item) => {
|
2020-08-03 14:18:48 +00:00
|
|
|
return <SocialLoginButton key={item.name} {...item} type={props.type} />;
|
2019-12-16 08:49:10 +00:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return <ThirdPartyAuthWrapper>{socialLoginButtons}</ThirdPartyAuthWrapper>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ThirdPartyAuth;
|