@@ -2,14 +2,47 @@ import { useEffect } from 'react';
22import { Link } from '../ui/link' ;
33import { Button } from '../ui/button' ;
44import { useOnboarding } from '@/hooks/use-onboarding' ;
5+ import { useMutation } from '@connectrpc/connect-query' ;
6+ import { finishOnboarding } from '@wundergraph/cosmo-connect/dist/platform/v1/platform-PlatformService_connectquery' ;
7+ import { useToast } from '../ui/use-toast' ;
8+ import { useRouter } from 'next/router' ;
9+ import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb' ;
510
611export const Step4 = ( ) => {
7- const { setStep, setSkipped } = useOnboarding ( ) ;
12+ const router = useRouter ( ) ;
13+ const { toast } = useToast ( ) ;
14+ const { setStep, setSkipped, setOnboarding } = useOnboarding ( ) ;
815
916 useEffect ( ( ) => {
10- setStep ( 3 ) ;
17+ setStep ( 4 ) ;
1118 } , [ setStep ] ) ;
1219
20+ const { mutate, isPending } = useMutation ( finishOnboarding , {
21+ onSuccess : ( d ) => {
22+ if ( d . response ?. code !== EnumStatusCode . OK ) {
23+ toast ( {
24+ description : d . response ?. details ?? 'We had issues with finishing the onboarding. Please try again.' ,
25+ duration : 3000 ,
26+ } ) ;
27+ return ;
28+ }
29+
30+ setOnboarding ( {
31+ finishedAt : new Date ( d . finishedAt ) ,
32+ federatedGraphsCount : d . federatedGraphsCount ,
33+ } ) ;
34+
35+ setStep ( undefined ) ;
36+ router . push ( '/' ) ;
37+ } ,
38+ onError : ( error ) => {
39+ toast ( {
40+ description : error . details . toString ( ) ?? 'We had issues with finishing the onboarding. Please try again.' ,
41+ duration : 3000 ,
42+ } ) ;
43+ } ,
44+ } ) ;
45+
1346 return (
1447 < div className = "flex flex-col items-center gap-4 text-center" >
1548 < h2 className = "text-2xl font-semibold tracking-tight" > Step 4</ h2 >
@@ -21,8 +54,14 @@ export const Step4 = () => {
2154 < Button className = "mr-2" asChild >
2255 < Link href = "/onboarding/3" > Back</ Link >
2356 </ Button >
24- < Button asChild >
25- < Link href = "/" > Finish</ Link >
57+ < Button
58+ onClick = { ( ) => {
59+ mutate ( { } ) ;
60+ } }
61+ isLoading = { isPending }
62+ disabled = { isPending }
63+ >
64+ Finish
2665 </ Button >
2766 </ div >
2867 </ div >
0 commit comments