PromucFlow_constructor/app/client/src/pages/UserAuth/ThirdPartyAuth.tsx
Ankita Kinger ce9c32cb92
chore: Improve code splitting of FE components (#26659)
## Description

Improve code splitting of FE components to avoid minimal changes needed
on EE when CE is modified.

#### PR fixes following issue(s)
Fixes [#24184](https://github.com/appsmithorg/appsmith/issues/24184)

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing

#### How Has This Been Tested?
- [x] Manual
- [ ] JUnit
- [x] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-08-28 21:07:32 +05:30

82 lines
2.3 KiB
TypeScript

import React from "react";
import styled from "styled-components";
import type { SocialLoginType } from "@appsmith/constants/SocialLogin";
import { getSocialLoginButtonProps } from "@appsmith/constants/SocialLogin";
import type { EventName } from "@appsmith/utils/analyticsUtilTypes";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { useLocation } from "react-router-dom";
import PerformanceTracker, {
PerformanceTransactionName,
} from "utils/PerformanceTracker";
import { Button } from "design-system";
const ThirdPartyAuthWrapper = styled.div`
display: flex;
flex-direction: column;
gap: var(--ads-v2-spaces-3);
`;
type SignInType = "SIGNIN" | "SIGNUP";
function SocialLoginButton(props: {
logo: string;
name: string;
url: string;
label?: string;
type: SignInType;
}) {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
let url = props.url;
const redirectUrl = queryParams.get("redirectUrl");
if (redirectUrl != null) {
url += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
}
return (
<Button
href={url}
kind="secondary"
onClick={() => {
let eventName: EventName = "LOGIN_CLICK";
if (props.type === "SIGNUP") {
eventName = "SIGNUP_CLICK";
}
PerformanceTracker.startTracking(
eventName === "SIGNUP_CLICK"
? PerformanceTransactionName.SIGN_UP
: PerformanceTransactionName.LOGIN_CLICK,
{ name: props.name.toUpperCase() },
);
AnalyticsUtil.logEvent(eventName, {
loginMethod: props.name.toUpperCase(),
});
}}
renderAs="a"
size="md"
startIcon={
["Google", "Github"].includes(props.name)
? props.name.toLowerCase() + `-fill`
: "key-2-line"
}
>
<div className="login-method" data-testid={`login-with-${props.name}`}>
{props.label ?? `Continue with ${props.name}`}
</div>
</Button>
);
}
function ThirdPartyAuth(props: {
logins: SocialLoginType[];
type: SignInType;
}) {
const socialLoginButtons = getSocialLoginButtonProps(props.logins).map(
(item) => {
return <SocialLoginButton key={item.name} {...item} type={props.type} />;
},
);
return <ThirdPartyAuthWrapper>{socialLoginButtons}</ThirdPartyAuthWrapper>;
}
export default ThirdPartyAuth;