11"use client"
22
33import React from "react" ;
4- import { Button , DRuntimeList , Flex , Spacing , Text , TextInput } from "@code0-tech/pictor" ;
5- import { IconSearch } from "@tabler/icons-react" ;
4+ import { Button , DRuntimeList , Flex , Spacing , Text , useService , useStore , useUserSession } from "@code0-tech/pictor" ;
65import Link from "next/link" ;
7- import { useParams , useRouter } from "next/navigation" ;
6+ import { notFound , useParams , useRouter } from "next/navigation" ;
7+ import { UserService } from "@edition/user/User.service" ;
88
99export const RuntimesPage : React . FC = ( ) => {
1010
11+ const currentSession = useUserSession ( )
12+ const userStore = useStore ( UserService )
13+ const userService = useService ( UserService )
14+ const currentUser = React . useMemo ( ( ) => userService . getById ( currentSession ?. user ?. id ) , [ userStore , currentSession ] )
15+
1116 const params = useParams ( )
12- const namespaceId = params . namespaceId as any as number
17+ const namespaceIndex = params . namespaceId as any as number
18+
19+ if ( ! namespaceIndex && currentUser && ! currentUser . admin ) {
20+ notFound ( )
21+ }
1322
1423 const router = useRouter ( )
1524 return < >
@@ -18,16 +27,16 @@ export const RuntimesPage: React.FC = () => {
1827 Runtimes
1928 </ Text >
2029 < Flex align = { "center" } style = { { gap : "0.7rem" } } >
21- < Link href = { namespaceId ? `/namespace/${ namespaceId } /runtimes/create` : "/runtimes/create" } >
30+ < Link href = { namespaceIndex ? `/namespace/${ namespaceIndex } /runtimes/create` : "/runtimes/create" } >
2231 < Button color = { "success" } > Create runtime</ Button >
2332 </ Link >
2433 </ Flex >
2534 </ Flex >
2635 < Spacing spacing = { "xl" } />
27- < DRuntimeList namespaceId = { namespaceId ? `gid://sagittarius/Namespace/${ namespaceId } ` : undefined }
28- filter = { ( runtime ) => namespaceId ? true : ! runtime ?. namespace ?. id } onSetting = { ( runtime ) => {
36+ < DRuntimeList namespaceId = { namespaceIndex ? `gid://sagittarius/Namespace/${ namespaceIndex } ` : undefined }
37+ filter = { ( runtime ) => namespaceIndex ? true : ! runtime ?. namespace ?. id } onSetting = { ( runtime ) => {
2938 const number = runtime . id ?. match ( / R u n t i m e \/ ( \d + ) $ / ) ?. [ 1 ]
30- router . push ( namespaceId ? `/namespace/${ namespaceId } /runtimes/${ number } /settings` : `/runtimes/${ number } /settings` )
39+ router . push ( namespaceIndex ? `/namespace/${ namespaceIndex } /runtimes/${ number } /settings` : `/runtimes/${ number } /settings` )
3140 } } />
3241 </ >
3342}
0 commit comments