11import { FC , useCallback , useEffect , useRef , useState } from 'react' ;
2- import {
3- useApiResourceMutation ,
4- useRevalidateApiResource ,
5- } from '../../lib/api/useApiResource' ;
6- import { ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx' ;
2+ import { useApiResourceMutation } from '../../lib/api/useApiResource' ;
73
8- import {
9- CreateWorkspaceResource ,
10- CreateWorkspaceType ,
11- } from '../../lib/api/types/crate/createWorkspace' ;
12- import { projectnameToNamespace } from '../../utils' ;
13- import { ListWorkspaces } from '../../lib/api/types/crate/listWorkspaces' ;
14- import { useToast } from '../../context/ToastContext.tsx' ;
154import { useAuth } from '../../spaces/onboarding/auth/AuthContext.tsx' ;
165import { Member , MemberRoles } from '../../lib/api/types/shared/members.ts' ;
17- import { useTranslation } from 'react-i18next' ;
6+
187import { zodResolver } from '@hookform/resolvers/zod' ;
198import { useForm } from 'react-hook-form' ;
209import { validationSchemaProjectWorkspace } from '../../lib/api/validations/schemas.ts' ;
21- import { MetadataAndMembersForm } from '../Dialogs/CreateProjectWorkspaceDialog.tsx' ;
10+ import {
11+ MetadataAndMembersForm ,
12+ OnCreatePayload ,
13+ } from '../Dialogs/CreateProjectWorkspaceDialog.tsx' ;
2214import {
2315 Bar ,
2416 Button ,
2517 Dialog ,
2618 Grid ,
2719 List ,
2820 ListItemStandard ,
29- Text ,
3021 Wizard ,
3122 WizardStep ,
3223} from '@ui5/webcomponents-react' ;
3324import YamlViewer from '../Yaml/YamlViewer.tsx' ;
3425import { stringify } from 'yaml' ;
26+ import { APIError } from '../../lib/api/error.ts' ;
27+ import {
28+ CreateManagedControlPlane ,
29+ CreateManagedControlPlaneResource ,
30+ CreateManagedControlPlaneType ,
31+ } from '../../lib/api/types/crate/createManagedControlPlane.ts' ;
32+ import { ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx' ;
33+ import { useToast } from '../../context/ToastContext.tsx' ;
3534
3635export type CreateDialogProps = {
3736 name : string ;
@@ -67,6 +66,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<
6766 members : [ ] ,
6867 } ,
6968 } ) ;
69+ const errorDialogRef = useRef < ErrorDialogHandle > ( null ) ;
7070 const resetFormAndClose = ( ) => {
7171 reset ( ) ;
7272 setSelectedStep ( 1 ) ;
@@ -77,7 +77,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<
7777 const { user } = useAuth ( ) ;
7878 const [ selectedStep , setSelectedStep ] = useState ( 1 ) ;
7979 const username = user ?. email ;
80-
80+ const toast = useToast ( ) ;
8181 const clearForm = useCallback ( ( ) => {
8282 resetField ( 'name' ) ;
8383 resetField ( 'chargingTarget' ) ;
@@ -94,6 +94,39 @@ export const CreateManagedControlPlaneWizardContainer: FC<
9494 clearForm ( ) ;
9595 }
9696 } , [ resetField , setValue , username , isOpen , clearForm ] ) ;
97+ const { trigger } = useApiResourceMutation < CreateManagedControlPlaneType > (
98+ CreateManagedControlPlaneResource ( namespace ) ,
99+ ) ;
100+ const handleCreateManagedControlPlane = async ( {
101+ name,
102+ displayName,
103+ chargingTarget,
104+ members,
105+ } : OnCreatePayload ) : Promise < boolean > => {
106+ try {
107+ await trigger (
108+ CreateManagedControlPlane ( name , namespace , {
109+ displayName : displayName ,
110+ chargingTarget : chargingTarget ,
111+ members : members ,
112+ } ) ,
113+ ) ;
114+ // await revalidate();
115+ setIsOpen ( false ) ;
116+ toast . show ( 'mcp created' ) ;
117+ return true ;
118+ } catch ( e ) {
119+ console . error ( e ) ;
120+ if ( e instanceof APIError ) {
121+ if ( errorDialogRef . current ) {
122+ errorDialogRef . current . showErrorDialog (
123+ `${ e . message } : ${ JSON . stringify ( e . info ) } ` ,
124+ ) ;
125+ }
126+ }
127+ return false ;
128+ }
129+ } ;
97130
98131 const onNextClick = ( ) => {
99132 console . log ( 'test' ) ;
0 commit comments