diff --git a/src/components/direct/hisp/TestCard.tsx b/src/components/direct/hisp/TestCard.tsx index 89782e20..934210e7 100644 --- a/src/components/direct/hisp/TestCard.tsx +++ b/src/components/direct/hisp/TestCard.tsx @@ -6,6 +6,7 @@ import DocumentSelector from './DocumentSelector' import { handleAPICall } from '../test-by-criteria/ServerActions' import CheckCircleIcon from '@mui/icons-material/CheckCircle' import CancelIcon from '@mui/icons-material/Cancel' +import LoadingButton from '../shared/LoadingButton' import { Box, @@ -97,6 +98,8 @@ const TestCard = ({ const [criteriaMet, setCriteriaMet] = useState('') const [testRequestResponses, setTestRequestResponses] = useState('') const [showLogs, setShowLogs] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [isFinished, setIsFinished] = useState(false) const handleDocumentConfirm = (selectedData: SelectedDocument) => { console.log('Confirmed Document', selectedData) @@ -132,6 +135,9 @@ const TestCard = ({ alert('This test requires a CCDA document to be selected. Please select a document before running the test.') } else { try { + setIsLoading(true) + setIsFinished(false) + setCriteriaMet('') const response = await handleAPICall({ testCaseNumber: test.id, sutSmtpAddress: hostname, @@ -151,12 +157,18 @@ const TestCard = ({ year: '2021', hostingcase: 'YES', }) + setIsFinished(true) setCriteriaMet(response.criteriaMet) setTestRequestResponses(JSON.stringify(response.testRequestResponses, null, 2)) console.log('Criteria met: ', response.criteriaMet) console.log('Test Request Responses:', response.testRequestResponses) } catch (error) { console.error('Failed to run test:', error) + } finally { + setIsLoading(false) + setTimeout(() => { + setIsFinished(false) + }, 100) } } } @@ -325,9 +337,15 @@ const TestCard = ({ )} {renderCriteriaMetIcon()} - + diff --git a/src/components/direct/hisp/XDRTestCard.tsx b/src/components/direct/hisp/XDRTestCard.tsx index d44c3598..cd9e20d5 100644 --- a/src/components/direct/hisp/XDRTestCard.tsx +++ b/src/components/direct/hisp/XDRTestCard.tsx @@ -7,6 +7,7 @@ import DynamicTable from './DynamicTable' import { handleAPICall } from '../test-by-criteria/ServerActions' import CheckCircleIcon from '@mui/icons-material/CheckCircle' import CancelIcon from '@mui/icons-material/Cancel' +import LoadingButton from '../shared/LoadingButton' export type TestCaseFields = { name?: string @@ -141,6 +142,8 @@ const TestCard = ({ const [testRequestResponses, setTestRequestResponses] = useState('') const [showLogs, setShowLogs] = useState(false) const [fieldValues, setFieldValues] = useState<{ [key: string]: string }>({}) + const [isLoading, setIsLoading] = useState(false) + const [isFinished, setIsFinished] = useState(false) const [documentDetails] = useState<{ directory: string @@ -175,6 +178,9 @@ const TestCard = ({ const targetEndpointTLS = fieldValues['targetEndpointTLS'] || '' const outgoing_from = fieldValues['outgoing_from'] || '' try { + setIsLoading(true) + setIsFinished(false) + setCriteriaMet('') const response = await handleAPICall({ testCaseNumber: test.id, sutSmtpAddress: hostname, @@ -200,12 +206,18 @@ const TestCard = ({ targetEndpointTLS, outgoing_from, }) + setIsFinished(true) setCriteriaMet(response.criteriaMet) setTestRequestResponses(JSON.stringify(response.testRequestResponses, null, 2)) console.log('Criteria met: ', response.criteriaMet) console.log('Test Request Responses:', response.testRequestResponses) } catch (error) { console.error('Failed to run test:', error) + } finally { + setIsLoading(false) + setTimeout(() => { + setIsFinished(false) + }, 100) } } } @@ -372,9 +384,15 @@ const TestCard = ({ {renderCriteriaMetIcon()} - + diff --git a/src/components/direct/shared/LoadingButton.tsx b/src/components/direct/shared/LoadingButton.tsx new file mode 100644 index 00000000..cfc64df2 --- /dev/null +++ b/src/components/direct/shared/LoadingButton.tsx @@ -0,0 +1,20 @@ +import React, { ReactNode } from 'react' +import { Button, CircularProgress } from '@mui/material' +import CheckIcon from '@mui/icons-material/Check' +import { ButtonProps } from '@mui/material/Button' + +interface LoadingButtonProps extends ButtonProps { + loading: boolean + done: boolean + children: ReactNode +} + +const LoadingButton: React.FC = ({ loading, done, children, ...props }) => { + return ( + + ) +} + +export default LoadingButton diff --git a/src/components/direct/shared/Profile.tsx b/src/components/direct/shared/Profile.tsx index 381686c1..56b4cb6b 100644 --- a/src/components/direct/shared/Profile.tsx +++ b/src/components/direct/shared/Profile.tsx @@ -48,7 +48,7 @@ const Profile: React.FC = ({ id="outlined-vendor-hostname" label="Vendor Hostname/IP" helperText="helper text" - defaultValue="test" + defaultValue="" required onChange={(e) => setHostname(e.target.value)} /> @@ -57,7 +57,7 @@ const Profile: React.FC = ({ id="vendor-email" label="Vendor Direct Email Address" helperText="helper text" - defaultValue="test" + defaultValue="" required onChange={(e) => setEmail(e.target.value)} /> @@ -68,7 +68,7 @@ const Profile: React.FC = ({ id="vendor-username" label="Vendor Username" helperText="helper text" - defaultValue="test" + defaultValue="" required onChange={(e) => setUsername(e.target.value)} /> @@ -77,7 +77,7 @@ const Profile: React.FC = ({ id="vendor-password" label="Vendor Password" helperText="helper text" - defaultValue="test" + defaultValue="" required onChange={(e) => setPassword(e.target.value)} />