1+ import { Skeleton } from '@heroui/skeleton' ;
12import { DeploymentContextType , useDeploymentContext } from '@lib/contexts/deployment' ;
2- import { FormType } from '@typedefs/deployment' ;
3+ import { routePath } from '@lib/routes/route-paths' ;
4+ import db from '@lib/storage/db' ;
5+ import { FormType , Project } from '@typedefs/deployment' ;
6+ import { useLiveQuery } from 'dexie-react-hooks' ;
7+ import { useEffect } from 'react' ;
38import { RiArrowLeftLine } from 'react-icons/ri' ;
9+ import { useNavigate , useParams } from 'react-router-dom' ;
410
511interface Props {
612 steps : string [ ] ;
@@ -9,11 +15,49 @@ interface Props {
915function JobFormHeader ( { steps } : Props ) {
1016 const { formType, setFormType, step, setStep } = useDeploymentContext ( ) as DeploymentContextType ;
1117
18+ const navigate = useNavigate ( ) ;
19+ const { id } = useParams ( ) ;
20+
21+ const isValidId = id && ! isNaN ( parseInt ( id ) ) && isFinite ( parseInt ( id ) ) ;
22+
23+ // Only run the query if we have a valid ID
24+ const project : Project | undefined | null = useLiveQuery (
25+ isValidId ? ( ) => db . projects . where ( 'id' ) . equals ( parseInt ( id ) ) . first ( ) : ( ) => undefined ,
26+ [ isValidId , id ] ,
27+ null , // Default value returned while data is loading
28+ ) ;
29+
30+ useEffect ( ( ) => {
31+ if ( project === undefined ) {
32+ navigate ( routePath . notFound ) ;
33+ }
34+ } , [ project ] ) ;
35+
36+ if ( project === null ) {
37+ return (
38+ < div className = "col w-full gap-8" >
39+ < Skeleton className = "min-h-[82.5px] w-full rounded-lg" />
40+ < Skeleton className = "min-h-[50px] w-full rounded-lg" />
41+ </ div >
42+ ) ;
43+ }
44+
45+ if ( project === undefined ) {
46+ return < > </ > ;
47+ }
48+
1249 return (
1350 < div className = "col w-full gap-8" >
1451 < div className = "col gap-4" >
15- < div className = "big-title text-center" >
16- Deeploy a { formType } { formType === FormType . Service ? '' : 'App' }
52+ < div className = "row justify-between" >
53+ < div className = "row gap-2" >
54+ < div className = "mt-[1px] h-2.5 w-2.5 rounded-full" style = { { backgroundColor : project . color } } > </ div >
55+ < div className = "big-title max-w-[280px] truncate" > { project . name } </ div >
56+ </ div >
57+
58+ < div className = "big-title" >
59+ Add a { formType } { formType === FormType . Service ? '' : 'App' } Job
60+ </ div >
1761 </ div >
1862
1963 < div className = "col gap-2.5" >
@@ -24,7 +68,7 @@ function JobFormHeader({ steps }: Props) {
2468 > </ div >
2569 </ div >
2670
27- < div className = "flex justify-between" >
71+ < div className = "row justify-between" >
2872 < RiArrowLeftLine
2973 className = "-ml-0.5 cursor-pointer text-xl text-slate-500 hover:opacity-50"
3074 onClick = { ( ) => {
@@ -37,7 +81,7 @@ function JobFormHeader({ steps }: Props) {
3781 />
3882
3983 < div
40- className = "cursor-pointer text-sm font-medium text-slate-500 hover:opacity-50"
84+ className = "cursor-pointer text-[15px] font-medium text-slate-500 hover:opacity-50"
4185 onClick = { ( ) => setFormType ( undefined ) }
4286 >
4387 Cancel
@@ -50,7 +94,7 @@ function JobFormHeader({ steps }: Props) {
5094 < div className = "text-sm font-semibold uppercase text-primary" >
5195 Step { step } of { steps . length }
5296 </ div >
53- < div className = "text-[22px] font-medium " > { steps [ step - 1 ] } </ div >
97+ < div className = "big-title " > { steps [ step - 1 ] } </ div >
5498 </ div >
5599 </ div >
56100 ) ;
0 commit comments