-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathcompleteOnboardingButton.tsx
More file actions
52 lines (45 loc) · 1.52 KB
/
completeOnboardingButton.tsx
File metadata and controls
52 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use client"
import { useState } from "react"
import { useRouter } from "next/navigation"
import { Button } from "@/components/ui/button"
import { completeOnboarding } from "@/actions"
import { isServiceError } from "@/lib/utils"
import { useToast } from "@/components/hooks/use-toast"
export function CompleteOnboardingButton() {
const [isLoading, setIsLoading] = useState(false)
const router = useRouter()
const { toast } = useToast()
const handleCompleteOnboarding = async () => {
setIsLoading(true)
try {
const result = await completeOnboarding()
if (isServiceError(result)) {
toast({
title: "Error",
description: "Failed to complete onboarding. Please try again.",
variant: "destructive",
})
setIsLoading(false)
return
}
router.push("/")
} catch (error) {
console.error("Error completing onboarding:", error)
toast({
title: "Error",
description: "Failed to complete onboarding. Please try again.",
variant: "destructive",
})
setIsLoading(false)
}
}
return (
<Button
onClick={handleCompleteOnboarding}
disabled={isLoading}
className="w-full"
>
{isLoading ? "Completing..." : "Complete Onboarding →"}
</Button>
)
}