Skip to content

Commit 878dd13

Browse files
committed
add retry, minor refactor
1 parent 7b07358 commit 878dd13

File tree

1 file changed

+34
-27
lines changed
  • packages/frontend/src/pages/AiBuilder/components/StepsPreview

1 file changed

+34
-27
lines changed

packages/frontend/src/pages/AiBuilder/components/StepsPreview/index.tsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export default function StepsPreview() {
5858
const { isOpen, onClose, onOpen } = useDisclosure()
5959
const isMobile = useIsMobile()
6060
const navigate = useNavigate()
61-
61+
const [createFlowWithSteps, { loading: isCreatingFlow }] = useMutation(
62+
CREATE_FLOW_WITH_STEPS,
63+
)
6264
const [generateAiStepsMutation, { loading: isGeneratingSteps }] =
6365
useMutation(GENERATE_AI_STEPS)
6466

@@ -104,9 +106,10 @@ export default function StepsPreview() {
104106
navigate,
105107
])
106108

107-
const [createFlowWithSteps, { loading: isCreatingFlow }] = useMutation(
108-
CREATE_FLOW_WITH_STEPS,
109-
)
109+
const retryGenerateAiSteps = useCallback(async () => {
110+
setError(false)
111+
await generateAiSteps(formInput)
112+
}, [generateAiSteps, formInput])
110113

111114
/** FOR EACH STEPS COMPUTATION */
112115
const forEachSteps = groupedSteps[0]
@@ -185,31 +188,35 @@ export default function StepsPreview() {
185188
})
186189
}
187190

188-
if (isGeneratingSteps || !output) {
191+
if (error) {
189192
return (
190193
<Center h="100%">
191-
{error ? (
192-
<Flex
193-
flexDir="column"
194-
alignItems="center"
195-
justifyContent="center"
196-
gap={4}
197-
w="100%"
198-
maxW="400px"
199-
>
200-
<Text>Something went wrong</Text>
201-
<Button onClick={() => setError(false)}>Try again</Button>
202-
</Flex>
203-
) : output && !isGeneratingSteps ? (
204-
<PrimarySpinner fontSize="4xl" />
205-
) : (
206-
<MultiStepLoader
207-
loadingStates={LOADING_STATES}
208-
loading={isGeneratingSteps}
209-
duration={1500}
210-
loop={false}
211-
/>
212-
)}
194+
<Flex
195+
flexDir="column"
196+
alignItems="center"
197+
justifyContent="center"
198+
gap={4}
199+
w="100%"
200+
maxW="400px"
201+
>
202+
<Text textStyle="h4" fontWeight="normal">
203+
Something went wrong
204+
</Text>
205+
<Button onClick={retryGenerateAiSteps}>Try again</Button>
206+
</Flex>
207+
</Center>
208+
)
209+
}
210+
211+
if (isGeneratingSteps) {
212+
return (
213+
<Center h="100%">
214+
<MultiStepLoader
215+
loadingStates={LOADING_STATES}
216+
loading={isGeneratingSteps}
217+
duration={1500}
218+
loop={false}
219+
/>
213220
</Center>
214221
)
215222
}

0 commit comments

Comments
 (0)