1717 */
1818
1919import { useEffect , useState } from 'react' ;
20- import { useLocation } from 'react-router-dom' ;
21- import { Tabs } from 'antd' ;
22-
20+ import { useLocation , useNavigate } from 'react-router-dom' ;
21+ import { Tabs , message } from 'antd' ;
22+ import axios from 'axios' ;
2323import API from '@/api' ;
2424import { PageLoading } from '@/components' ;
2525import { useRefreshData } from '@/hooks' ;
26+ import { PATHS } from '@/config' ;
2627
2728import { FromEnum } from '../types' ;
2829
@@ -40,16 +41,27 @@ export const BlueprintDetail = ({ id, from }: Props) => {
4041 const [ activeKey , setActiveKey ] = useState ( 'status' ) ;
4142
4243 const { state } = useLocation ( ) ;
44+ const navigate = useNavigate ( ) ;
4345
4446 useEffect ( ( ) => {
4547 setActiveKey ( state ?. activeKey ?? 'status' ) ;
4648 } , [ state ] ) ;
4749
48- const { ready, data } = useRefreshData ( async ( ) => {
49- const [ bpRes , pipelineRes ] = await Promise . all ( [ API . blueprint . get ( id ) , API . blueprint . pipelines ( id ) ] ) ;
50+ const { ready, data, error } = useRefreshData ( async ( ) => {
51+ const [ bpRes , pipelineRes ] = await Promise . all ( [
52+ API . blueprint . get ( id ) ,
53+ API . blueprint . pipelines ( id ) ,
54+ ] ) ;
5055 return [ bpRes , pipelineRes . pipelines [ 0 ] ] ;
5156 } , [ version ] ) ;
5257
58+ useEffect ( ( ) => {
59+ if ( axios . isAxiosError ( error ) && error . response ?. status === 404 ) {
60+ message . error ( `Blueprint not found with id: ${ id } ` ) ;
61+ navigate ( PATHS . BLUEPRINTS ( ) , { replace : true } ) ;
62+ }
63+ } , [ error , navigate , id ] ) ;
64+
5365 const handlRefresh = ( ) => {
5466 setVersion ( ( v ) => v + 1 ) ;
5567 } ;
0 commit comments