11import type { IExecution } from '@plumber/types'
22
3- import { Fragment , ReactElement } from 'react'
3+ import { Fragment , ReactElement , useCallback } from 'react'
44import { BiChevronLeft } from 'react-icons/bi'
55import { useNavigate , useSearchParams } from 'react-router-dom'
66import { Flex , Icon , Link , Stack , Text } from '@chakra-ui/react'
@@ -14,26 +14,30 @@ type ExecutionHeaderProps = {
1414}
1515
1616function ExecutionName ( props : Pick < IExecution [ 'flow' ] , 'name' | 'id' > ) {
17+ const { id, name } = props
1718 const [ searchParams ] = useSearchParams ( )
1819 const navigate = useNavigate ( )
1920 const backToPage = searchParams . get ( 'backToPage' )
2021
22+ const handleBack = useCallback ( ( ) => {
23+ let backUrl = URLS . EXECUTIONS_FOR_FLOW ( id )
24+
25+ if ( backToPage ) {
26+ backUrl += `?page=${ backToPage } `
27+ }
28+ navigate ( backUrl )
29+ } , [ navigate , id , backToPage ] )
30+
2131 return (
2232 < Flex gap = { 2 } alignItems = "center" >
23- < Button
24- as = { Link }
25- variant = "link"
26- onClick = { ( ) => {
27- navigate ( `${ URLS . EXECUTIONS_FOR_FLOW ( props . id ) } ?page=${ backToPage } ` )
28- } }
29- >
33+ < Button as = { Link } variant = "link" onClick = { handleBack } >
3034 < Icon
3135 boxSize = { 6 }
3236 color = "interaction.support.disabled-content"
3337 as = { BiChevronLeft }
3438 />
3539 </ Button >
36- < Text textStyle = "h4" > { props . name } </ Text >
40+ < Text textStyle = "h4" > { name } </ Text >
3741 </ Flex >
3842 )
3943}
0 commit comments