@@ -2,9 +2,42 @@ 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 { createOnboarding } from '@wundergraph/cosmo-connect/dist/platform/v1/platform-PlatformService_connectquery' ;
7+ import { useRouter } from 'next/router' ;
8+ import { useCurrentOrganization } from '@/hooks/use-current-organization' ;
9+ import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb' ;
10+ import { useToast } from '../ui/use-toast' ;
511
612export const Step1 = ( ) => {
7- const { setStep, setSkipped } = useOnboarding ( ) ;
13+ const router = useRouter ( ) ;
14+ const { toast } = useToast ( ) ;
15+ const organization = useCurrentOrganization ( ) ;
16+ const { setStep, setSkipped, setOnboarding } = useOnboarding ( ) ;
17+
18+ const { mutate, isPending } = useMutation ( createOnboarding , {
19+ onSuccess : ( d ) => {
20+ if ( d . response ?. code !== EnumStatusCode . OK ) {
21+ toast ( {
22+ description : d . response ?. details ?? 'We had issues with storing your data. Please try again.' ,
23+ duration : 3000 ,
24+ } ) ;
25+ return ;
26+ }
27+
28+ setOnboarding ( {
29+ federatedGraphsCount : d . federatedGraphsCount ,
30+ finishedAt : d . finishedAt ? new Date ( d . finishedAt ) : undefined ,
31+ } ) ;
32+ router . push ( '/onboarding/2' ) ;
33+ } ,
34+ onError : ( error ) => {
35+ toast ( {
36+ description : error . details . toString ( ) ?? 'We had issues with storing your data. Please try again.' ,
37+ duration : 3000 ,
38+ } ) ;
39+ } ,
40+ } ) ;
841
942 useEffect ( ( ) => {
1043 setStep ( 1 ) ;
@@ -21,8 +54,20 @@ export const Step1 = () => {
2154 < Button className = "mr-2" asChild disabled >
2255 < Link href = "#" > Back</ Link >
2356 </ Button >
24- < Button asChild >
25- < Link href = "/onboarding/2" > Next</ Link >
57+ < Button
58+ onClick = { ( ) => {
59+ // TODO: replace with real values in form
60+ mutate ( {
61+ organizationName : organization ?. name ?? '' ,
62+ slack : true ,
63+ email : false ,
64+ invititationEmails : [ ] ,
65+ } ) ;
66+ } }
67+ isLoading = { isPending }
68+ disabled = { isPending }
69+ >
70+ Next
2671 </ Button >
2772 </ div >
2873 </ div >
0 commit comments