1
+ 'use client' ;
2
+
3
+ import SharedConnectionCreationForm from "./sharedConnectionCreationForm" ;
4
+ import { BitbucketConnectionConfig } from "@sourcebot/schemas/v3/connection.type" ;
5
+ import { bitbucketSchema } from "@sourcebot/schemas/v3/bitbucket.schema" ;
6
+ import { bitbucketCloudQuickActions } from "../../connections/quickActions" ;
7
+
8
+ interface BitbucketCloudConnectionCreationFormProps {
9
+ onCreated ?: ( id : number ) => void ;
10
+ }
11
+
12
+ const additionalConfigValidation = ( config : BitbucketConnectionConfig ) : { message : string , isValid : boolean } => {
13
+ const hasProjects = config . projects && config . projects . length > 0 && config . projects . some ( p => p . trim ( ) . length > 0 ) ;
14
+ const hasRepos = config . repos && config . repos . length > 0 && config . repos . some ( r => r . trim ( ) . length > 0 ) ;
15
+ const hasWorkspaces = config . workspaces && config . workspaces . length > 0 && config . workspaces . some ( w => w . trim ( ) . length > 0 ) ;
16
+
17
+ if ( ! hasProjects && ! hasRepos && ! hasWorkspaces ) {
18
+ return {
19
+ message : "At least one project, repository, or workspace must be specified" ,
20
+ isValid : false ,
21
+ }
22
+ }
23
+
24
+ return {
25
+ message : "Valid" ,
26
+ isValid : true ,
27
+ }
28
+ } ;
29
+
30
+ export const BitbucketCloudConnectionCreationForm = ( { onCreated } : BitbucketCloudConnectionCreationFormProps ) => {
31
+ const defaultConfig : BitbucketConnectionConfig = {
32
+ type : 'bitbucket' ,
33
+ deploymentType : 'cloud' ,
34
+ }
35
+
36
+ return (
37
+ < SharedConnectionCreationForm < BitbucketConnectionConfig >
38
+ type = "bitbucket"
39
+ title = "Create a Bitbucket Cloud connection"
40
+ defaultValues = { {
41
+ config : JSON . stringify ( defaultConfig , null , 2 ) ,
42
+ } }
43
+ schema = { bitbucketSchema }
44
+ additionalConfigValidation = { additionalConfigValidation }
45
+ quickActions = { bitbucketCloudQuickActions }
46
+ onCreated = { onCreated }
47
+ />
48
+ )
49
+ }
0 commit comments