@@ -2,10 +2,39 @@ 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 = ( ) => {
13+ const router = useRouter ( ) ;
14+ const { toast } = useToast ( ) ;
15+ const organization = useCurrentOrganization ( ) ;
716 const { setStep, setSkipped } = useOnboarding ( ) ;
817
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+ router . push ( '/onboarding/2' ) ;
29+ } ,
30+ onError : ( error ) => {
31+ toast ( {
32+ description : error . details . toString ( ) ?? 'We had issues with storing your data. Please try again.' ,
33+ duration : 3000 ,
34+ } ) ;
35+ } ,
36+ } ) ;
37+
938 useEffect ( ( ) => {
1039 setStep ( 1 ) ;
1140 } , [ setStep ] ) ;
@@ -21,8 +50,20 @@ export const Step1 = () => {
2150 < Button className = "mr-2" asChild disabled >
2251 < Link href = "#" > Back</ Link >
2352 </ Button >
24- < Button asChild >
25- < Link href = "/onboarding/2" > Next</ Link >
53+ < Button
54+ onClick = { ( ) => {
55+ // TODO: replace with real values in form
56+ mutate ( {
57+ organizationName : organization ?. name ?? '' ,
58+ slack : true ,
59+ email : false ,
60+ invititationEmails : [ ] ,
61+ } ) ;
62+ } }
63+ isLoading = { isPending }
64+ disabled = { isPending }
65+ >
66+ Next
2667 </ Button >
2768 </ div >
2869 </ div >
0 commit comments