feat: introduce reconnect feature for connections

This commit is contained in:
Ali BARIN
2021-10-20 21:01:48 +02:00
parent 258caa81f0
commit ec4dd8a037
16 changed files with 75 additions and 41 deletions

View File

@@ -15,6 +15,7 @@ import { Form } from './style';
type AddAppConnectionProps = {
onClose: () => void;
application: App;
connectionId?: string;
};
type Response = {
@@ -22,8 +23,8 @@ type Response = {
}
export default function AddAppConnection(props: AddAppConnectionProps){
const { application, onClose } = props;
const { key, fields, authenticationSteps } = application;
const { application, connectionId, onClose } = props;
const { key, fields, authenticationSteps, reconnectionSteps } = application;
useEffect(() => {
if (window.opener) {
@@ -33,14 +34,21 @@ export default function AddAppConnection(props: AddAppConnectionProps){
}, []);
const submitHandler: SubmitHandler<FieldValues> = useCallback(async (data) => {
const hasConnection = Boolean(connectionId);
const response: Response = {
key,
connection: {
id: connectionId
},
fields: data,
};
const steps = hasConnection ? reconnectionSteps : authenticationSteps;
let stepIndex = 0;
while (stepIndex < authenticationSteps.length) {
const step = authenticationSteps[stepIndex];
while (stepIndex < steps.length) {
const step = steps[stepIndex];
const variables = computeAuthStepVariables(step, response);
const stepResponse = await processStep(step, variables);
@@ -51,7 +59,7 @@ export default function AddAppConnection(props: AddAppConnectionProps){
}
onClose?.();
}, [authenticationSteps, key, onClose]);
}, [connectionId, key, reconnectionSteps, authenticationSteps, onClose]);
return (
<Dialog open={true} onClose={onClose}>