@@ -2,14 +2,50 @@ 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+ slack : Boolean ( prev ?. slack ) ,
35+ email : Boolean ( prev ?. email ) ,
36+ } ) ) ;
37+
38+ setStep ( undefined ) ;
39+ router . push ( '/' ) ;
40+ } ,
41+ onError : ( error ) => {
42+ toast ( {
43+ description : error . details . toString ( ) ?? 'We had issues with finishing the onboarding. Please try again.' ,
44+ duration : 3000 ,
45+ } ) ;
46+ } ,
47+ } ) ;
48+
1349 return (
1450 < div className = "flex flex-col items-center gap-4 text-center" >
1551 < h2 className = "text-2xl font-semibold tracking-tight" > Step 4</ h2 >
@@ -21,8 +57,14 @@ export const Step4 = () => {
2157 < Button className = "mr-2" asChild >
2258 < Link href = "/onboarding/3" > Back</ Link >
2359 </ Button >
24- < Button asChild >
25- < Link href = "/" > Finish</ Link >
60+ < Button
61+ onClick = { ( ) => {
62+ mutate ( { } ) ;
63+ } }
64+ isLoading = { isPending }
65+ disabled = { isPending }
66+ >
67+ Finish
2668 </ Button >
2769 </ div >
2870 </ div >
0 commit comments