2021-10-19 13:08:25 +02:00
|
|
|
import SimpleAuth from '../SimpleAuth/SimpleAuth';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { AuthenticationCustomComponent } from 'component/user/AuthenticationCustomComponent';
|
2023-01-04 10:17:13 +01:00
|
|
|
import PasswordAuth from '../PasswordAuth';
|
|
|
|
import HostedAuth from '../HostedAuth';
|
2022-02-10 17:04:10 +01:00
|
|
|
import DemoAuth from '../DemoAuth/DemoAuth';
|
2021-10-19 13:08:25 +02:00
|
|
|
import {
|
|
|
|
SIMPLE_TYPE,
|
|
|
|
DEMO_TYPE,
|
|
|
|
PASSWORD_TYPE,
|
|
|
|
HOSTED_TYPE,
|
2022-03-28 10:49:59 +02:00
|
|
|
} from 'constants/authTypes';
|
2023-01-04 10:17:13 +01:00
|
|
|
import SecondaryLoginActions from '../common/SecondaryLoginActions';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useQueryParams from 'hooks/useQueryParams';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2022-05-02 15:52:41 +02:00
|
|
|
import { Alert } from '@mui/material';
|
2022-03-28 10:49:59 +02:00
|
|
|
import { useAuthDetails } from 'hooks/api/getters/useAuth/useAuthDetails';
|
2022-04-08 13:13:45 +02:00
|
|
|
import { AUTH_PAGE_ID } from 'utils/testIds';
|
2023-01-11 10:24:11 +01:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
2021-10-19 13:08:25 +02:00
|
|
|
|
2022-02-21 14:05:11 +01:00
|
|
|
interface IAuthenticationProps {
|
|
|
|
redirect: string;
|
2023-01-11 10:24:11 +01:00
|
|
|
invited?: boolean;
|
2022-02-21 14:05:11 +01:00
|
|
|
}
|
2022-04-08 13:13:45 +02:00
|
|
|
|
2023-01-11 10:24:11 +01:00
|
|
|
const Authentication = ({
|
|
|
|
redirect,
|
|
|
|
invited = false,
|
|
|
|
}: IAuthenticationProps) => {
|
2022-02-10 17:04:10 +01:00
|
|
|
const { authDetails } = useAuthDetails();
|
2021-10-19 13:08:25 +02:00
|
|
|
const params = useQueryParams();
|
|
|
|
const error = params.get('errorMsg');
|
2023-01-11 10:24:11 +01:00
|
|
|
const { trackEvent } = usePlausibleTracker();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (invited) {
|
|
|
|
trackEvent('invite', {
|
|
|
|
props: {
|
|
|
|
eventType: 'user created',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [invited, trackEvent]);
|
2022-04-08 13:13:45 +02:00
|
|
|
|
|
|
|
if (!authDetails) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-19 13:08:25 +02:00
|
|
|
|
|
|
|
let content;
|
|
|
|
if (authDetails.type === PASSWORD_TYPE) {
|
|
|
|
content = (
|
|
|
|
<>
|
2022-02-21 14:05:11 +01:00
|
|
|
<PasswordAuth authDetails={authDetails} redirect={redirect} />
|
2021-10-19 13:08:25 +02:00
|
|
|
<ConditionallyRender
|
2022-01-26 13:28:51 +01:00
|
|
|
condition={!authDetails.defaultHidden}
|
2021-10-19 13:08:25 +02:00
|
|
|
show={<SecondaryLoginActions />}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else if (authDetails.type === SIMPLE_TYPE) {
|
2022-02-21 14:05:11 +01:00
|
|
|
content = <SimpleAuth authDetails={authDetails} redirect={redirect} />;
|
2021-10-19 13:08:25 +02:00
|
|
|
} else if (authDetails.type === DEMO_TYPE) {
|
2022-02-21 14:05:11 +01:00
|
|
|
content = <DemoAuth authDetails={authDetails} redirect={redirect} />;
|
2021-10-19 13:08:25 +02:00
|
|
|
} else if (authDetails.type === HOSTED_TYPE) {
|
|
|
|
content = (
|
|
|
|
<>
|
2022-02-21 14:05:11 +01:00
|
|
|
<HostedAuth authDetails={authDetails} redirect={redirect} />
|
2021-10-19 13:08:25 +02:00
|
|
|
<ConditionallyRender
|
2022-01-26 13:28:51 +01:00
|
|
|
condition={!authDetails.defaultHidden}
|
2021-10-19 13:08:25 +02:00
|
|
|
show={<SecondaryLoginActions />}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
2022-02-22 13:55:47 +01:00
|
|
|
content = <AuthenticationCustomComponent authDetails={authDetails} />;
|
2021-10-19 13:08:25 +02:00
|
|
|
}
|
2022-04-08 13:13:45 +02:00
|
|
|
|
2021-10-19 13:08:25 +02:00
|
|
|
return (
|
|
|
|
<>
|
2022-04-08 13:13:45 +02:00
|
|
|
<div style={{ maxWidth: '350px' }} data-testid={AUTH_PAGE_ID}>
|
2021-10-19 13:08:25 +02:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(error)}
|
2023-10-02 14:25:46 +02:00
|
|
|
show={<Alert severity='error'>{error}</Alert>}
|
2021-10-19 13:08:25 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{content}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Authentication;
|