2019-12-16 08:49:10 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { SocialLoginType } from "ee/constants/SocialLogin";
|
|
|
|
|
import { getSocialLoginButtonProps } from "ee/utils/signupHelpers";
|
|
|
|
|
import type { EventName } from "ee/utils/analyticsUtilTypes";
|
|
|
|
|
import AnalyticsUtil from "ee/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";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { Button } from "@appsmith/ads";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { isTenantConfig } from "ee/utils/adminSettingsHelpers";
|
2024-05-15 05:41:47 +00:00
|
|
|
import { useSelector } from "react-redux";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getTenantConfig } from "ee/selectors/tenantSelectors";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
const ThirdPartyAuthWrapper = styled.div`
|
|
|
|
|
display: flex;
|
2023-05-19 18:37:06 +00:00
|
|
|
gap: var(--ads-v2-spaces-3);
|
2024-04-17 16:16:44 +00:00
|
|
|
width: 100%;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)`
|
|
|
|
|
flex: 1 0 171px;
|
2021-01-27 06:12:32 +00:00
|
|
|
`;
|
|
|
|
|
|
2020-03-11 13:59:46 +00:00
|
|
|
type SignInType = "SIGNIN" | "SIGNUP";
|
|
|
|
|
|
2024-04-17 16:16:44 +00:00
|
|
|
const startIcon: {
|
|
|
|
|
[key: string]: string;
|
|
|
|
|
} = {
|
|
|
|
|
Google: "google-colored",
|
|
|
|
|
Github: "github-fill",
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function SocialLoginButton(props: {
|
2019-12-16 08:49:10 +00:00
|
|
|
logo: string;
|
|
|
|
|
name: string;
|
|
|
|
|
url: string;
|
2020-03-11 13:59:46 +00:00
|
|
|
type: SignInType;
|
2021-04-28 10:28:39 +00:00
|
|
|
}) {
|
2024-05-15 05:41:47 +00:00
|
|
|
const tenantConfiguration = useSelector(getTenantConfig);
|
2020-08-03 14:18:48 +00:00
|
|
|
const location = useLocation();
|
|
|
|
|
const queryParams = new URLSearchParams(location.search);
|
|
|
|
|
let url = props.url;
|
2021-05-18 05:52:54 +00:00
|
|
|
const redirectUrl = queryParams.get("redirectUrl");
|
|
|
|
|
if (redirectUrl != null) {
|
|
|
|
|
url += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
|
2020-08-03 14:18:48 +00:00
|
|
|
}
|
2024-05-15 05:41:47 +00:00
|
|
|
|
|
|
|
|
let buttonLabel = props.name;
|
|
|
|
|
|
|
|
|
|
if (props.name && isTenantConfig(props.name)) {
|
|
|
|
|
buttonLabel = tenantConfiguration[props.name];
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
return (
|
2024-04-17 16:16:44 +00:00
|
|
|
<StyledButton
|
2020-08-03 14:18:48 +00:00
|
|
|
href={url}
|
2023-05-19 18:37:06 +00:00
|
|
|
kind="secondary"
|
2020-03-11 13:59:46 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
let eventName: EventName = "LOGIN_CLICK";
|
|
|
|
|
if (props.type === "SIGNUP") {
|
|
|
|
|
eventName = "SIGNUP_CLICK";
|
|
|
|
|
}
|
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(),
|
|
|
|
|
});
|
|
|
|
|
}}
|
2023-05-19 18:37:06 +00:00
|
|
|
renderAs="a"
|
|
|
|
|
size="md"
|
2023-06-12 05:21:18 +00:00
|
|
|
startIcon={
|
|
|
|
|
["Google", "Github"].includes(props.name)
|
2024-04-17 16:16:44 +00:00
|
|
|
? startIcon[props.name]
|
2023-06-12 05:21:18 +00:00
|
|
|
: "key-2-line"
|
|
|
|
|
}
|
2020-03-11 13:59:46 +00:00
|
|
|
>
|
2022-04-21 06:14:02 +00:00
|
|
|
<div className="login-method" data-testid={`login-with-${props.name}`}>
|
2024-05-15 05:41:47 +00:00
|
|
|
{buttonLabel}
|
2022-01-07 06:08:17 +00:00
|
|
|
</div>
|
2024-04-17 16:16:44 +00:00
|
|
|
</StyledButton>
|
2019-12-16 08:49:10 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
|
2023-04-30 06:22:42 +00:00
|
|
|
function ThirdPartyAuth(props: {
|
2020-03-11 13:59:46 +00:00
|
|
|
logins: SocialLoginType[];
|
|
|
|
|
type: SignInType;
|
2021-04-28 10:28:39 +00:00
|
|
|
}) {
|
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>;
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
export default ThirdPartyAuth;
|