1- import { ActionProps , createFormPath , Form , InferLoader , jsonResponse , LoaderProps , redirectResponse , useDataLoader } from "../../../src" ;
1+ import { ActionProps , createFormPath , Form , jsonResponse , LoaderProps , redirectResponse , useDataLoader , useLoadingState } from "../../../src" ;
22import { useEffect , useState } from "react" ;
33import { Input } from "../components/input" ;
44
@@ -10,9 +10,11 @@ export const actions = () => ({
1010 post : async ( args : ActionProps < Route > ) => {
1111 const url = new URL ( args . request . url ) ;
1212 const json = await args . request . json ( ) ;
13+ console . log ( args . request ) ;
1314 url . searchParams . set ( "firstName" , json . person . name ) ;
1415 url . searchParams . set ( "lastName" , json . person . surname ) ;
1516 url . searchParams . set ( "date" , json . person . birthday ) ;
17+ await new Promise ( ( res ) => setTimeout ( res , 3000 ) ) ;
1618 return redirectResponse ( url . href ) ;
1719 } ,
1820} ) ;
@@ -34,6 +36,8 @@ export default function Root() {
3436 console . log ( "data loader" , data ?. qs ) ;
3537 } , [ data ] ) ;
3638
39+ const loading = useLoadingState ( ) ;
40+
3741 return (
3842 < section className = "flex flex-col gap-12" >
3943 < h2 className = "font-bold text-3xl" > Form post action - json</ h2 >
@@ -43,13 +47,15 @@ export default function Root() {
4347 >
4448 Throw error
4549 </ button >
46- < Form encType = "json" method = "post" className = "flex gap-8 items-end" >
47- < Input defaultValue = { qs ?. firstName } name = { path ( "person.name" ) } placeholder = "First Name" />
48- < Input defaultValue = { qs ?. lastName } name = { path ( "person.surname" ) } placeholder = "Last Name" />
49- < Input defaultValue = { qs ?. date } name = { path ( "person.birthday" ) } type = "date" placeholder = "Birthday" />
50- < button className = "py-2 px-4 rounded bg-blue-500 text-white font-medium" type = "submit" >
51- Submit
52- </ button >
50+ < Form encType = "json" method = "post" >
51+ < fieldset className = "flex gap-8 items-end disabled:opacity-40 disabled:bg-gray-400" >
52+ < Input defaultValue = { qs ?. firstName } name = { path ( "person.name" ) } placeholder = "First Name" />
53+ < Input defaultValue = { qs ?. lastName } name = { path ( "person.surname" ) } placeholder = "Last Name" />
54+ < Input defaultValue = { qs ?. date } name = { path ( "person.birthday" ) } type = "date" placeholder = "Birthday" />
55+ < button className = "py-2 px-4 rounded bg-blue-500 text-white font-medium" type = "submit" >
56+ { loading ? "Saving..." : "Submit" }
57+ </ button >
58+ </ fieldset >
5359 </ Form >
5460 </ section >
5561 ) ;
0 commit comments