@@ -6,16 +6,19 @@ import { GrafanaTheme2 } from '@grafana/data';
6
6
import { Modal , Button , Stack , TextLink , Field , Input , Text , useStyles2 } from '@grafana/ui' ;
7
7
import { Trans , t } from 'app/core/internationalization' ;
8
8
9
- import { ConnectStackDTOMock } from '../../../mockAPI ' ;
9
+ import { CreateMigrationApiArg } from '../../../api ' ;
10
10
11
11
interface Props {
12
12
hideModal : ( ) => void ;
13
- onConfirm : ( connectStackData : ConnectStackDTOMock ) => Promise < { data : void } | { error : unknown } > ;
13
+ onConfirm : ( connectStackData : CreateMigrationApiArg ) => Promise < unknown > ;
14
+ }
15
+
16
+ interface FormData {
17
+ token : string ;
14
18
}
15
19
16
20
export const ConnectModal = ( { hideModal, onConfirm } : Props ) => {
17
21
const [ isConnecting , setIsConnecting ] = useState ( false ) ;
18
- const cloudStackId = useId ( ) ;
19
22
const tokenId = useId ( ) ;
20
23
const styles = useStyles2 ( getStyles ) ;
21
24
@@ -24,19 +27,22 @@ export const ConnectModal = ({ hideModal, onConfirm }: Props) => {
24
27
register,
25
28
formState : { errors } ,
26
29
watch,
27
- } = useForm < ConnectStackDTOMock > ( {
30
+ } = useForm < FormData > ( {
28
31
defaultValues : {
29
- stackURL : '' ,
30
32
token : '' ,
31
33
} ,
32
34
} ) ;
33
35
34
- const stackURL = watch ( 'stackURL' ) ;
35
36
const token = watch ( 'token' ) ;
36
37
37
- const onConfirmConnect : SubmitHandler < ConnectStackDTOMock > = async ( formData ) => {
38
+ const onConfirmConnect : SubmitHandler < FormData > = async ( formData ) => {
38
39
setIsConnecting ( true ) ;
39
- await onConfirm ( formData ) ;
40
+ // TODO: location of this is kinda weird, making it tricky to handle errors from this.
41
+ await onConfirm ( {
42
+ cloudMigrationRequest : {
43
+ authToken : formData . token ,
44
+ } ,
45
+ } ) ;
40
46
setIsConnecting ( false ) ;
41
47
hideModal ( ) ;
42
48
} ;
@@ -49,46 +55,34 @@ export const ConnectModal = ({ hideModal, onConfirm }: Props) => {
49
55
< Trans i18nKey = "migrate-to-cloud.connect-modal.body-get-started" >
50
56
To get started, you'll need a Grafana.com account.
51
57
</ Trans >
58
+
52
59
< TextLink href = "https://grafana.com/auth/sign-up/create-user?pg=prod-cloud" external >
53
60
{ t ( 'migrate-to-cloud.connect-modal.body-sign-up' , 'Sign up for a Grafana.com account' ) }
54
61
</ TextLink >
62
+
55
63
< Trans i18nKey = "migrate-to-cloud.connect-modal.body-cloud-stack" >
56
64
You'll also need a cloud stack. If you just signed up, we'll automatically create your first
57
65
stack. If you have an account, you'll need to select or create a stack.
58
66
</ Trans >
67
+
59
68
< TextLink href = "https://grafana.com/auth/sign-in/" external >
60
69
{ t ( 'migrate-to-cloud.connect-modal.body-view-stacks' , 'View my cloud stacks' ) }
61
70
</ TextLink >
62
- < Trans i18nKey = "migrate-to-cloud.connect-modal.body-paste-stack" >
63
- Once you've decided on a stack, paste the URL below.
64
- </ Trans >
65
- < Field
66
- className = { styles . field }
67
- invalid = { ! ! errors . stackURL }
68
- error = { errors . stackURL ?. message }
69
- label = { t ( 'migrate-to-cloud.connect-modal.body-url-field' , 'Cloud stack URL' ) }
70
- required
71
- >
72
- < Input
73
- { ...register ( 'stackURL' , {
74
- required : t ( 'migrate-to-cloud.connect-modal.stack-required-error' , 'Stack URL is required' ) ,
75
- } ) }
76
- id = { cloudStackId }
77
- placeholder = "https://example.grafana.net/"
78
- />
79
- </ Field >
71
+
80
72
< span >
81
73
< Trans i18nKey = "migrate-to-cloud.connect-modal.body-token" >
82
74
Your self-managed Grafana installation needs special access to securely migrate content. You'll
83
75
need to create a migration token on your chosen cloud stack.
84
76
</ Trans >
85
77
</ span >
78
+
86
79
< span >
87
80
< Trans i18nKey = "migrate-to-cloud.connect-modal.body-token-instructions" >
88
81
Log into your cloud stack and navigate to Administration, General, Migrate to Grafana Cloud. Create a
89
82
migration token on that screen and paste the token here.
90
83
</ Trans >
91
84
</ span >
85
+
92
86
< Field
93
87
className = { styles . field }
94
88
invalid = { ! ! errors . token }
@@ -110,7 +104,7 @@ export const ConnectModal = ({ hideModal, onConfirm }: Props) => {
110
104
< Button variant = "secondary" onClick = { hideModal } >
111
105
< Trans i18nKey = "migrate-to-cloud.connect-modal.cancel" > Cancel</ Trans >
112
106
</ Button >
113
- < Button type = "submit" disabled = { isConnecting || ! ( stackURL && token ) } >
107
+ < Button type = "submit" disabled = { isConnecting || ! token } >
114
108
{ isConnecting
115
109
? t ( 'migrate-to-cloud.connect-modal.connecting' , 'Connecting to this stack...' )
116
110
: t ( 'migrate-to-cloud.connect-modal.connect' , 'Connect to this stack' ) }
0 commit comments