2
2
3
3
import React , { useState } from "react" ;
4
4
import { useDispatch , useSelector } from "react-redux" ;
5
- import { resetForm , setCurrentStep } from "@/store/slices/form-slice" ;
5
+ import { setCurrentStep } from "@/store/slices/form-slice" ;
6
6
import { Button } from "../ui/button" ;
7
7
import { createEvent } from "@/actions/events" ;
8
8
import { Loader } from "lucide-react" ;
9
9
import { useToast } from "../ui/use-toast" ;
10
+ import { getCurrentUser } from "@/lib/authProvider" ;
10
11
11
12
export default function FooterBtns ( ) {
12
13
const { toast } = useToast ( ) ;
@@ -22,29 +23,37 @@ export default function FooterBtns() {
22
23
} ;
23
24
24
25
async function handleSubmit ( ) {
25
- // Submit formData to your database
26
- // console.log("function running");
27
- console . log ( "Final Form Data: " , formData ) ;
28
26
setLoading ( true ) ;
27
+
29
28
try {
30
- const event : any = await createEvent ( { data : formData } ) ;
31
- console . log ( event ) ;
29
+ // Retrieving the current user
30
+ const user : any = await getCurrentUser ( ) ;
31
+ const userId = user . id ;
32
+
33
+ // Merging userId into formData
34
+ const updatedFormData = { ...formData , userId } ;
35
+ console . log ( updatedFormData ) ;
36
+
37
+ const event : any = await createEvent ( { data : updatedFormData } ) ;
38
+ console . log ( "Event created: " , event ) ;
32
39
33
40
toast ( {
34
41
title : "Event has been created successfully" ,
35
42
} ) ;
43
+
36
44
dispatch ( setCurrentStep ( step + 1 ) ) ;
37
45
// dispatch(resetForm());
38
- } catch ( error : any ) {
46
+ } catch ( error ) {
47
+ console . error ( "Error creating event:" , error ) ;
39
48
toast ( {
40
49
title : "Event creation has failed..." ,
41
50
variant : "destructive" ,
42
51
} ) ;
43
- console . error ( "Event creation error:" , error ) ;
44
52
} finally {
45
53
setLoading ( false ) ;
46
54
}
47
55
}
56
+
48
57
return (
49
58
< div className = 'flex max-w-4xl w-full mx-auto justify-end gap-2 items-end' >
50
59
{ step > 1 && (
@@ -58,19 +67,15 @@ export default function FooterBtns() {
58
67
) }
59
68
60
69
{ ( step === 1 || step === 2 || step === 3 ) && (
61
- < Button
62
- type = 'submit'
63
- // onClick={() => handleSubmit()}
64
- className = 'w-[10rem] mt-4'
65
- >
70
+ < Button type = 'submit' className = 'w-[10rem] mt-4' >
66
71
Save and Continue{ " " }
67
72
</ Button >
68
73
) }
69
74
70
75
{ step === 4 && (
71
76
< Button
72
77
type = 'submit'
73
- onClick = { handleSubmit }
78
+ onClick = { ( ) => handleSubmit ( ) }
74
79
className = 'flex gap-2 w-[15rem] mt-4'
75
80
>
76
81
{ loading && < Loader className = 'animate-spin size-4' /> }
0 commit comments