Skip to content

Commit

Permalink
fix(app): fix ordering of gripper exit so success screen doesn't flash (
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored and Carlos-fernandez committed May 20, 2024
1 parent 3666179 commit 80abf92
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions app/src/organisms/GripperWizardFlows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useNotifyCurrentMaintenanceRun } from '../../resources/maintenance_runs
import { LegacyModalShell } from '../../molecules/LegacyModal'
import { getTopPortalEl } from '../../App/portal'
import { WizardHeader } from '../../molecules/WizardHeader'
import { SimpleWizardBody } from '../../molecules/SimpleWizardBody'
import { FirmwareUpdateModal } from '../FirmwareUpdateModal'
import { getIsOnDevice } from '../../redux/config'
import {
Expand Down Expand Up @@ -115,31 +116,30 @@ export function GripperWizardFlows(
const [isExiting, setIsExiting] = React.useState<boolean>(false)
const [errorMessage, setErrorMessage] = React.useState<null | string>(null)

const { deleteMaintenanceRun } = useDeleteMaintenanceRunMutation({
onSuccess: () => closeFlow(),
onError: () => closeFlow(),
})
const handleClose = (): void => {
if (props?.onComplete != null) props.onComplete()
if (maintenanceRunData != null) {
deleteMaintenanceRun(maintenanceRunData?.data.id)
}
closeFlow()
}

const { deleteMaintenanceRun } = useDeleteMaintenanceRunMutation({})

const handleCleanUpAndClose = (): void => {
setIsExiting(true)
if (maintenanceRunData?.data.id == null) {
closeFlow()
} else {
if (maintenanceRunData?.data.id == null) handleClose()
else {
chainRunCommands(
maintenanceRunData?.data.id,
[{ commandType: 'home' as const, params: {} }],
true
false
)
.then(() => {
deleteMaintenanceRun(maintenanceRunData?.data.id)
setIsExiting(false)
props.onComplete?.()
handleClose()
})
.catch(error => {
console.error(error.message)
deleteMaintenanceRun(maintenanceRunData?.data.id)
setIsExiting(false)
props.onComplete?.()
setIsExiting(true)
setErrorMessage(error.message)
})
}
}
Expand All @@ -156,6 +156,7 @@ export function GripperWizardFlows(
isChainCommandMutationLoading || isCommandLoading || isExiting
}
handleCleanUpAndClose={handleCleanUpAndClose}
handleClose={handleClose}
chainRunCommands={chainRunCommands}
createRunCommand={createMaintenanceCommand}
errorMessage={errorMessage}
Expand All @@ -182,6 +183,7 @@ interface GripperWizardProps {
setErrorMessage: (message: string | null) => void
errorMessage: string | null
handleCleanUpAndClose: () => void
handleClose: () => void
chainRunCommands: ReturnType<
typeof useChainMaintenanceCommands
>['chainRunCommands']
Expand All @@ -198,6 +200,7 @@ export const GripperWizard = (
maintenanceRunId,
createMaintenanceRun,
handleCleanUpAndClose,
handleClose,
chainRunCommands,
attachedGripper,
isCreateLoading,
Expand Down Expand Up @@ -275,6 +278,16 @@ export const GripperWizard = (
isRobotMoving={isRobotMoving}
/>
)
} else if (isExiting && errorMessage != null) {
onExit = handleClose
modalContent = (
<SimpleWizardBody
isSuccess={false}
iconColor={COLORS.red50}
header={t('shared:error_encountered')}
subHeader={errorMessage}
/>
)
} else if (currentStep.section === SECTIONS.BEFORE_BEGINNING) {
onExit = handleCleanUpAndClose
modalContent = (
Expand Down

0 comments on commit 80abf92

Please sign in to comment.