11import { useEffect } from 'react' ;
2+ import { useRouter } from 'next/router' ;
3+ import { useMutation } from '@connectrpc/connect-query' ;
4+ import { useOnboarding } from '@/hooks/use-onboarding' ;
5+ import { finishOnboarding } from '@wundergraph/cosmo-connect/dist/platform/v1/platform-PlatformService_connectquery' ;
6+ import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb' ;
7+ import { useToast } from '../ui/use-toast' ;
28import { Link } from '../ui/link' ;
39import { Button } from '../ui/button' ;
4- import { useOnboarding } from '@/hooks/use-onboarding' ;
510
611export const Step3 = ( ) => {
7- const { setStep, setSkipped } = useOnboarding ( ) ;
12+ const router = useRouter ( ) ;
13+ const { toast } = useToast ( ) ;
14+ const { setStep, setSkipped, setOnboarding } = useOnboarding ( ) ;
15+
16+ const { mutate, isPending } = useMutation ( finishOnboarding , {
17+ onSuccess : ( d ) => {
18+ if ( d . response ?. code !== EnumStatusCode . OK ) {
19+ toast ( {
20+ description : d . response ?. details ?? 'We had issues with finishing the onboarding. Please try again.' ,
21+ duration : 3000 ,
22+ } ) ;
23+ return ;
24+ }
25+
26+ setOnboarding ( ( prev ) => ( {
27+ ...prev ,
28+ finishedAt : new Date ( d . finishedAt ) ,
29+ federatedGraphsCount : d . federatedGraphsCount ,
30+ } ) ) ;
31+
32+ setStep ( undefined ) ;
33+ router . push ( '/' ) ;
34+ } ,
35+ onError : ( error ) => {
36+ toast ( {
37+ description : error . details . toString ( ) ?? 'We had issues with finishing the onboarding. Please try again.' ,
38+ duration : 3000 ,
39+ } ) ;
40+ } ,
41+ } ) ;
842
943 useEffect ( ( ) => {
1044 setStep ( 3 ) ;
@@ -21,8 +55,14 @@ export const Step3 = () => {
2155 < Button className = "mr-2" asChild >
2256 < Link href = "/onboarding/2" > Back</ Link >
2357 </ Button >
24- < Button asChild >
25- < Link href = "/" > Finish</ Link >
58+ < Button
59+ onClick = { ( ) => {
60+ mutate ( { } ) ;
61+ } }
62+ isLoading = { isPending }
63+ disabled = { isPending }
64+ >
65+ Finish
2666 </ Button >
2767 </ div >
2868 </ div >
0 commit comments