refactor(web): remove typescript

This commit is contained in:
Ali BARIN
2024-02-27 15:23:23 +00:00
parent 636870a075
commit b3ae2d2748
337 changed files with 2067 additions and 4997 deletions

View File

@@ -1,4 +1,3 @@
import type { IApp, IField, IJSONObject } from 'types';
import LoadingButton from '@mui/lab/LoadingButton';
import Alert from '@mui/material/Alert';
import Dialog from '@mui/material/Dialog';
@@ -6,32 +5,21 @@ import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import * as React from 'react';
import { FieldValues, SubmitHandler } from 'react-hook-form';
import { useNavigate, useSearchParams } from 'react-router-dom';
import AppAuthClientsDialog from 'components/AppAuthClientsDialog/index.ee';
import InputCreator from 'components/InputCreator';
import * as URLS from 'config/urls';
import useAuthenticateApp from 'hooks/useAuthenticateApp.ee';
import useFormatMessage from 'hooks/useFormatMessage';
import { generateExternalLink } from '../../helpers/translationValues';
import { generateExternalLink } from 'helpers/translationValues';
import { Form } from './style';
type AddAppConnectionProps = {
onClose: (response: Record<string, unknown>) => void;
application: IApp;
connectionId?: string;
};
export default function AddAppConnection(
props: AddAppConnectionProps
): React.ReactElement {
export default function AddAppConnection(props) {
const { application, connectionId, onClose } = props;
const { name, authDocUrl, key, auth } = application;
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const formatMessage = useFormatMessage();
const [error, setError] = React.useState<IJSONObject | null>(null);
const [error, setError] = React.useState(null);
const [inProgress, setInProgress] = React.useState(false);
const hasConnection = Boolean(connectionId);
const useShared = searchParams.get('shared') === 'true';
@@ -42,7 +30,6 @@ export default function AddAppConnection(
appAuthClientId,
useShared: !!appAuthClientId,
});
React.useEffect(function relayProviderData() {
if (window.opener) {
window.opener.postMessage({
@@ -52,51 +39,41 @@ export default function AddAppConnection(
window.close();
}
}, []);
React.useEffect(
function initiateSharedAuthenticationForGivenAuthClient() {
if (!appAuthClientId) return;
if (!authenticate) return;
const asyncAuthenticate = async () => {
await authenticate();
navigate(URLS.APP_CONNECTIONS(key));
};
asyncAuthenticate();
},
[appAuthClientId, authenticate]
[appAuthClientId, authenticate],
);
const handleClientClick = (appAuthClientId: string) =>
const handleClientClick = (appAuthClientId) =>
navigate(URLS.APP_ADD_CONNECTION_WITH_AUTH_CLIENT_ID(key, appAuthClientId));
const handleAuthClientsDialogClose = () =>
navigate(URLS.APP_CONNECTIONS(key));
const submitHandler: SubmitHandler<FieldValues> = React.useCallback(
const submitHandler = React.useCallback(
async (data) => {
if (!authenticate) return;
setInProgress(true);
try {
const response = await authenticate({
fields: data,
});
onClose(response as Record<string, unknown>);
onClose(response);
} catch (err) {
const error = err as IJSONObject;
const error = err;
console.log(error);
setError((error.graphQLErrors as IJSONObject[])?.[0]);
setError(error.graphQLErrors?.[0]);
} finally {
setInProgress(false);
}
},
[authenticate]
[authenticate],
);
if (useShared)
return (
<AppAuthClientsDialog
@@ -105,9 +82,7 @@ export default function AddAppConnection(
onClientClick={handleClientClick}
/>
);
if (appAuthClientId) return <React.Fragment />;
return (
<Dialog open={true} onClose={onClose} data-test="add-app-connection-dialog">
<DialogTitle>
@@ -142,7 +117,7 @@ export default function AddAppConnection(
<DialogContent>
<DialogContentText tabIndex={-1} component="div">
<Form onSubmit={submitHandler}>
{auth?.fields?.map((field: IField) => (
{auth?.fields?.map((field) => (
<InputCreator key={field.key} schema={field} />
))}

View File

@@ -1,6 +1,5 @@
import { styled } from '@mui/material/styles';
import BaseForm from 'components/Form';
export const Form = styled(BaseForm)(({ theme }) => ({
display: 'flex',
flexDirection: 'column',