From e05436034c3aa1c6fe1c0a61cb2bd21bd47744ae Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 16 Dec 2021 23:25:38 +0100 Subject: [PATCH] feat: add loading state to app connection creation --- .../src/components/AddAppConnection/index.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/web/src/components/AddAppConnection/index.tsx b/packages/web/src/components/AddAppConnection/index.tsx index e211607d..92c07b65 100644 --- a/packages/web/src/components/AddAppConnection/index.tsx +++ b/packages/web/src/components/AddAppConnection/index.tsx @@ -1,11 +1,12 @@ -import { useCallback, useEffect } from 'react'; +import * as React from 'react'; import DialogTitle from '@mui/material/DialogTitle'; import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import Dialog from '@mui/material/Dialog'; -import Button from '@mui/material/Button'; +import LoadingButton from '@mui/lab/LoadingButton'; import { FieldValues, SubmitHandler } from 'react-hook-form'; +import useFormatMessage from 'hooks/useFormatMessage'; import computeAuthStepVariables from 'helpers/computeAuthStepVariables'; import { processStep } from 'helpers/authenticationSteps'; import InputCreator from 'components/InputCreator'; @@ -25,15 +26,18 @@ type Response = { export default function AddAppConnection(props: AddAppConnectionProps){ const { application, connectionId, onClose } = props; const { key, fields, authenticationSteps, reconnectionSteps } = application; + const formatMessage = useFormatMessage(); + const [inProgress, setInProgress] = React.useState(false); - useEffect(() => { + React.useEffect(() => { if (window.opener) { window.opener.postMessage({ source: 'automatisch', payload: window.location.search }); window.close(); } }, []); - const submitHandler: SubmitHandler = useCallback(async (data) => { + const submitHandler: SubmitHandler = React.useCallback(async (data) => { + setInProgress(true); const hasConnection = Boolean(connectionId); const response: Response = { @@ -58,6 +62,7 @@ export default function AddAppConnection(props: AddAppConnectionProps){ stepIndex++; } + setInProgress(false); onClose?.(); }, [connectionId, key, reconnectionSteps, authenticationSteps, onClose]); @@ -70,7 +75,15 @@ export default function AddAppConnection(props: AddAppConnectionProps){
{fields?.map(field => ())} - + + {formatMessage('addAppConnection.submit')} +