@@ -2,14 +2,48 @@ 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 ( ( prev ) => ( {
31+ ...prev ,
32+ finishedAt : new Date ( d . finishedAt ) ,
33+ federatedGraphsCount : d . federatedGraphsCount ,
34+ } ) ) ;
35+
36+ setStep ( undefined ) ;
37+ router . push ( '/' ) ;
38+ } ,
39+ onError : ( error ) => {
40+ toast ( {
41+ description : error . details . toString ( ) ?? 'We had issues with finishing the onboarding. Please try again.' ,
42+ duration : 3000 ,
43+ } ) ;
44+ } ,
45+ } ) ;
46+
1347 return (
1448 < div className = "flex flex-col items-center gap-4 text-center" >
1549 < h2 className = "text-2xl font-semibold tracking-tight" > Step 4</ h2 >
@@ -21,8 +55,14 @@ export const Step4 = () => {
2155 < Button className = "mr-2" asChild >
2256 < Link href = "/onboarding/3" > 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