@@ -4,32 +4,106 @@ import { Button } from "../../ui/components/ui/button"
44import SideBar from "../constants/sidebar"
55import { useNavigate } from "react-router"
66import { useGetUser } from "../../hooks/use-auth"
7+ import { z } from "zod"
8+ import { zodResolver } from "@hookform/resolvers/zod"
9+ import { useForm } from "react-hook-form"
10+ import { Field , FieldDescription , FieldLabel , FieldGroup } from "../../ui/components/ui/field"
11+ import { Input } from "../../ui/components/ui/input"
12+ import { useCreatePrediction } from "../../hooks/use-model"
713const Intelligence = ( ) => {
8-
914 const navigate = useNavigate ( ) ;
10- const { data :user } = useGetUser ( ) ;
15+ const { data : user } = useGetUser ( ) ;
16+ const { data : model } = useCreatePrediction ( ) ;
1117 if ( ! user ) {
12- return (
13- navigate ( "/" )
14- )
18+ return (
19+ navigate ( "/" )
20+ )
21+ }
22+ const coordinateValidation = z . object ( {
23+ westLon : z . number ( ) . min ( - 180 , "Cannot exceed -180 degrees" ) . max ( 180 , "Cannot exceed 180 degrees" ) ,
24+ southLat : z . number ( ) . min ( - 90 , "Cannot exceed -90 degrees" ) . max ( 90 , "Cannot exceed 90 degrees" ) ,
25+ eastLon : z . number ( ) . min ( - 90 , "Cannot exceed -180 degrees" ) . max ( 90 , "Cannot exceed 180 degrees" ) ,
26+ northLat : z . number ( ) . min ( - 90 , "Cannot exceed -90 degrees" ) . max ( 90 , "Cannot exceed 90 degrees" ) ,
27+ } )
28+
29+ type coordinateQuery = z . infer < typeof coordinateValidation > ;
30+
31+ const { register, handleSubmit, formState : { errors } , } = useForm < coordinateQuery > ( {
32+ resolver : zodResolver ( coordinateValidation ) ,
33+ defaultValues : {
34+ westLon : 0 ,
35+ southLat : 0 ,
36+ eastLon : 0 ,
37+ northLat : 0 ,
38+ } ,
39+ } ) ;
40+
41+ const onSubmit = ( data : coordinateQuery ) => {
42+ model ( data , {
43+ onSuccess : ( ) => {
44+ navigate ( "/field/reports" )
45+ }
46+ } )
1547 }
48+
49+ const capitalizeLetter = user . role . charAt ( 0 ) . toUpperCase ( ) + user . role . slice ( 1 ) ;
1650 return (
1751 < div className = "bg-white h-full w-screen overflow-hidden" > { /* Main Box */ }
1852 { /* Top Bar */ }
19- < div className = "flex flex-row justify-between border-2 border-black w-[86%] p-4 relative left-[14.9%] place-items-center" >
53+ < div className = "flex flex-row justify-between border-2 border-gray-100 w-[86%] p-4 relative left-[14.9%] place-items-center" >
2054 < div className = "flex flex-col justify-center pl-4" >
21- < h1 className = "text-shadow-black font-bold text-xl" > Wildfire Risk Intelligence</ h1 >
22- < span className = "text-sm" > NASA FIRMS Ingestion • XGBoost Inference</ span >
55+ < h1 className = "text-shadow-black font-bold text-xl" > Wildfire Risk Intelligence</ h1 >
56+ < span className = "text-sm" > NASA FIRMS Ingestion • XGBoost Inference</ span >
2357 </ div >
2458 < div className = "grow shrink-0 relative left-[63%]" >
25- < Button className = "p-1 bg-[#DAFBE6] text-[#639273] w-[9%] h-[15%]" > < FeatherShieldCheck /> { user . role } </ Button >
59+ < Button className = "p-1 bg-[#DAFBE6] text-[#639273] w-[9%] h-[15%]" > < FeatherShieldCheck /> { capitalizeLetter } </ Button >
2660 </ div >
2761 </ div >
2862 < SideBar />
2963
3064 { /* Coordinate Box */ }
31- < div >
65+ < div className = "p-15 border-2 border-gray-100 border-b-2" >
66+ < h1 className = "font-bold text-md" > Geospatial Bounding Box</ h1 >
67+ < span className = "text-[#a79f9f] text-sm" > Define the target region for inference</ span >
68+ < form onSubmit = { handleSubmit ( onSubmit ) } >
69+ < FieldGroup >
70+ < Field >
71+ < FieldLabel htmlFor = "westLon" >
72+ West Longitude
73+ </ FieldLabel >
74+ < Input id = "westLon" placeholder = "-122.6750" required { ...register ( "westLon" ) } />
75+ { errors . westLon && (
76+ < span className = "text-red-500 text-xs" > { errors . westLon . message } </ span >
77+ ) }
78+ </ Field >
79+ < FieldDescription > Decimal degrees (-180 to 180)</ FieldDescription >
80+
81+ < Field >
82+ < FieldLabel htmlFor = "southLat" > South Latitude</ FieldLabel >
83+ < Input id = "southLat" placeholder = "37.4500" required { ...register ( "southLat" ) } />
84+ { errors . southLat && (
85+ < span className = "text-xs text-red-500" > { errors . southLat . message } </ span >
86+ ) }
87+ </ Field >
88+ < FieldDescription > Decimal degrees (-90 to 90)</ FieldDescription >
89+
90+ < Field >
91+ < FieldLabel > East Longitude</ FieldLabel >
92+ < Input id = "eastLon" placeholder = "-122.1500" required { ...register ( "eastLon" ) } />
93+ { errors . eastLon && (
94+ < span className = "text-xs text-red-500" > { errors . eastLon . message } </ span >
95+ ) }
96+ </ Field >
97+ < FieldDescription > Decimal degrees (-180 to 180)</ FieldDescription >
98+
99+ < Field >
100+ < FieldLabel > North Latitude</ FieldLabel >
101+ < Input id = "northLat" placeholder = "37.8750" required { ...register ( "northLat" ) } />
102+ </ Field >
103+ < FieldDescription > Decimal degrees (-90 to 90)</ FieldDescription >
32104
105+ </ FieldGroup >
106+ </ form >
33107 </ div >
34108
35109 { /* Hotspot Box */ }
0 commit comments