From 3e8bae2ec3f426c63e64b7f93d49575e94b6aa09 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 16 Dec 2021 23:26:29 +0100 Subject: [PATCH] feat: rework connection test feedback --- .../src/components/AppConnectionRow/index.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/web/src/components/AppConnectionRow/index.tsx b/packages/web/src/components/AppConnectionRow/index.tsx index 45e6cdd1..77c6d60e 100644 --- a/packages/web/src/components/AppConnectionRow/index.tsx +++ b/packages/web/src/components/AppConnectionRow/index.tsx @@ -3,8 +3,11 @@ import { useLazyQuery, useMutation } from '@apollo/client'; import Card from '@mui/material/Card'; import Box from '@mui/material/Box'; import Stack from '@mui/material/Stack'; +import CircularProgress from '@mui/material/CircularProgress'; import CardActionArea from '@mui/material/CardActionArea'; import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; +import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import ErrorIcon from '@mui/icons-material/Error'; import { useSnackbar } from 'notistack'; import { DateTime } from 'luxon'; @@ -30,7 +33,12 @@ const countTranslation = (value: React.ReactNode) => ( function AppConnectionRow(props: AppConnectionRowProps) { const { enqueueSnackbar } = useSnackbar(); - const [testConnection, { called: testCalled, loading: testLoading }] = useLazyQuery(TEST_CONNECTION); + const [verificationVisible, setVerificationVisible] = React.useState(false); + const [testConnection, { called: testCalled, loading: testLoading }] = useLazyQuery(TEST_CONNECTION, { + fetchPolicy: 'network-only', + onCompleted: () => { setTimeout(() => setVerificationVisible(false), 3000); }, + onError: () => { setTimeout(() => setVerificationVisible(false), 3000); }, + }); const [deleteConnection] = useMutation(DELETE_CONNECTION); const formatMessage = useFormatMessage(); @@ -62,6 +70,7 @@ function AppConnectionRow(props: AppConnectionRowProps) { enqueueSnackbar(formatMessage('connection.deletedMessage'), { variant: 'success' }); } else if (action.type === 'test') { + setVerificationVisible(true); testConnection({ variables: { id } }); } }, [deleteConnection, id, testConnection, formatMessage, enqueueSnackbar]); @@ -74,7 +83,6 @@ function AppConnectionRow(props: AppConnectionRowProps) { - {testCalled && !testLoading && (verified ? 'yes' : 'no')} + + {verificationVisible && testCalled && testLoading && ( + <> + + {formatMessage('connection.testing')} + + )} + {verificationVisible && testCalled && !testLoading && verified && ( + <> + + {formatMessage('connection.testSuccessful')} + + )} + {verificationVisible && testCalled && !testLoading && !verified && ( + <> + + {formatMessage('connection.testFailed')} + + )} +