@@ -7,33 +7,37 @@ import { useRouter } from "next/navigation";
7
7
8
8
export default function ( ) {
9
9
const router = useRouter ( ) ;
10
- const [ description , setDescription ] = useState ( "" ) ;
10
+ const [ email , setEmail ] = useState ( "" ) ;
11
11
12
12
const handleSubmit = async ( ) => {
13
- if ( ! description ) {
14
- toast . error ( "please descibe your story " ) ;
13
+ if ( ! email ) {
14
+ toast . error ( "please enter your email " ) ;
15
15
return ;
16
16
}
17
17
18
18
try {
19
19
const params = {
20
- description : description ,
20
+ email : email ,
21
21
} ;
22
- const resp = await fetch ( "/api/gen-video " , {
22
+ const resp = await fetch ( "/api/save-user " , {
23
23
method : "POST" ,
24
24
headers : {
25
25
"Content-Type" : "application/json" ,
26
26
} ,
27
27
body : JSON . stringify ( params ) ,
28
28
} ) ;
29
29
const { code, message, data } = await resp . json ( ) ;
30
+ if ( code !== 0 ) {
31
+ toast . error ( message ) ;
32
+ return ;
33
+ }
30
34
if ( data ) {
31
- toast . success ( "We generated an random video for your story. " ) ;
32
- router . push ( `/video/ ${ data . uuid } ` ) ;
35
+ toast . success ( "subscribe ok " ) ;
36
+ setEmail ( "" ) ;
33
37
}
34
38
} catch ( e ) {
35
- toast . error ( "gen video failed" ) ;
36
- console . log ( "gen video failed" , e ) ;
39
+ toast . error ( "subscribe failed" ) ;
40
+ console . log ( "subscribe failed" , e ) ;
37
41
}
38
42
} ;
39
43
@@ -49,20 +53,20 @@ export default function () {
49
53
return (
50
54
< div className = "mx-auto mt-6 flex max-w-md gap-x-4" >
51
55
< input
52
- type = "text "
56
+ type = "email "
53
57
required
54
58
className = "min-w-0 flex-auto rounded-md border-0 bg-white/5 px-3.5 py-2 text-white shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-white sm:text-sm sm:leading-6"
55
- placeholder = "Describe your story "
56
- value = { description }
57
- onChange = { ( e ) => setDescription ( e . target . value ) }
59
+ placeholder = "Enter your email "
60
+ value = { email }
61
+ onChange = { ( e ) => setEmail ( e . target . value ) }
58
62
onKeyDown = { handleInputKeydown }
59
63
/>
60
64
< button
61
65
type = "button"
62
66
className = "flex-none rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
63
67
onClick = { handleSubmit }
64
68
>
65
- Surprise me
69
+ Subscribe
66
70
</ button >
67
71
</ div >
68
72
) ;
0 commit comments