@@ -9,8 +9,7 @@ import React, { useEffect, useState } from 'react'
99import { fetcher } from '../src/auth'
1010
1111export default function Home ( ) {
12- const [ apiKeyId , setApiKeyId ] = useState ( '' )
13- const [ apiKey , setApiKey ] = useState ( '' )
12+ const [ form , setForm ] = useState ( { id : '' , key : '' } )
1413 const [ loading , setLoading ] = useState ( false )
1514 const [ error , setError ] = useState ( '' )
1615 const router = useRouter ( )
@@ -20,7 +19,7 @@ export default function Home() {
2019 try {
2120 setLoading ( true )
2221 setError ( '' )
23- await fetcher . login ( apiKey , apiKeyId )
22+ await fetcher . login ( form )
2423
2524 const url = new URL ( location . href )
2625 const redirectTo = url . searchParams . get ( 'redirectTo' )
@@ -37,8 +36,10 @@ export default function Home() {
3736 }
3837
3938 useEffect ( ( ) => {
40- setApiKeyId ( fetcher . getApiKeyId )
41- setApiKey ( fetcher . getApiKey )
39+ setForm ( {
40+ id : fetcher . getApiKeyId ,
41+ key : fetcher . getApiKey ,
42+ } )
4243 } , [ ] )
4344
4445 return (
@@ -51,23 +52,23 @@ export default function Home() {
5152 < form noValidate onSubmit = { submit } >
5253 < p > Insert a api key with the < b > Dashboard</ b > role</ p >
5354 < TextField
54- value = { apiKeyId }
55+ value = { form . id }
5556 fullWidth
5657 id = "id"
5758 label = "API Key ID"
5859 variant = "filled"
59- onChange = { e => setApiKeyId ( e . target . value ) }
60+ onChange = { e => setForm ( f => ( { ... f , id : e . target . value } ) ) }
6061 disabled = { loading }
6162 error = { ! ! error }
6263 />
6364 < div className = "marginTop" >
6465 < TextField
65- value = { apiKey }
66+ value = { form . key }
6667 fullWidth
6768 id = "key"
6869 label = "API Key"
6970 variant = "filled"
70- onChange = { e => setApiKey ( e . target . value ) }
71+ onChange = { e => setForm ( f => ( { ... f , key : e . target . value } ) ) }
7172 disabled = { loading }
7273 error = { ! ! error }
7374 helperText = { error }
0 commit comments