@@ -4,17 +4,18 @@ import styled from '@emotion/styled';
4
4
import sentryPattern from 'sentry-images/pattern/sentry-pattern.png' ;
5
5
6
6
import { Alert } from 'sentry/components/alert' ;
7
- import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent ' ;
8
- import ApiForm from 'sentry/components/forms/apiForm ' ;
7
+ import Form from 'sentry/components/forms/form ' ;
8
+ import LoadingIndicator from 'sentry/components/loadingIndicator ' ;
9
9
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle' ;
10
10
import { t } from 'sentry/locale' ;
11
11
import ConfigStore from 'sentry/stores/configStore' ;
12
12
import { space } from 'sentry/styles/space' ;
13
+ import { useApiQuery } from 'sentry/utils/queryClient' ;
13
14
14
15
import type { Field } from '../options' ;
15
16
import { getForm , getOptionDefault , getOptionField } from '../options' ;
16
17
17
- export type InstallWizardProps = DeprecatedAsyncComponent [ 'props' ] & {
18
+ export type InstallWizardProps = {
18
19
onConfigured : ( ) => void ;
19
20
} ;
20
21
@@ -26,21 +27,30 @@ export type InstallWizardOptions = Record<
26
27
}
27
28
> ;
28
29
29
- type State = DeprecatedAsyncComponent [ 'state' ] & {
30
- data : null | InstallWizardOptions ;
31
- } ;
32
-
33
- export default class InstallWizard extends DeprecatedAsyncComponent <
34
- InstallWizardProps ,
35
- State
36
- > {
37
- getEndpoints ( ) : ReturnType < DeprecatedAsyncComponent [ 'getEndpoints' ] > {
38
- return [ [ 'data' , '/internal/options/?query=is:required' ] ] ;
30
+ export default function InstallWizard ( { onConfigured} : InstallWizardProps ) {
31
+ const {
32
+ data : options ,
33
+ isPending,
34
+ isError,
35
+ } = useApiQuery < InstallWizardOptions > ( [ '/internal/options/?query=is:required' ] , {
36
+ staleTime : 0 ,
37
+ } ) ;
38
+
39
+ if ( isPending ) {
40
+ return < LoadingIndicator /> ;
39
41
}
40
42
41
- renderFormFields ( ) {
42
- const options = this . state . data ! ;
43
+ if ( isError ) {
44
+ return (
45
+ < Alert type = "error" showIcon >
46
+ { t (
47
+ 'We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.'
48
+ ) }
49
+ </ Alert >
50
+ ) ;
51
+ }
43
52
53
+ const renderFormFields = ( ) => {
44
54
let missingOptions = new Set (
45
55
Object . keys ( options ) . filter ( option => ! options [ option ] ! . field . isSet )
46
56
) ;
@@ -65,10 +75,9 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
65
75
}
66
76
67
77
return getForm ( fields ) ;
68
- }
78
+ } ;
69
79
70
- getInitialData ( ) {
71
- const options = this . state . data ! ;
80
+ const getInitialData = ( ) => {
72
81
const data = { } ;
73
82
Object . keys ( options ) . forEach ( optionName => {
74
83
const option = options [ optionName ] ! ;
@@ -93,55 +102,33 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
93
102
}
94
103
} ) ;
95
104
return data ;
96
- }
97
-
98
- render ( ) {
99
- const version = ConfigStore . get ( 'version' ) ;
100
- return (
101
- < SentryDocumentTitle noSuffix title = { t ( 'Setup Sentry' ) } >
102
- < Wrapper >
103
- < Pattern />
104
- < SetupWizard >
105
- < Heading >
106
- < span > { t ( 'Welcome to Sentry' ) } </ span >
107
- < Version > { version . current } </ Version >
108
- </ Heading >
109
- { this . state . loading
110
- ? this . renderLoading ( )
111
- : this . state . error
112
- ? this . renderError ( )
113
- : this . renderBody ( ) }
114
- </ SetupWizard >
115
- </ Wrapper >
116
- </ SentryDocumentTitle >
117
- ) ;
118
- }
119
-
120
- renderError ( ) {
121
- return (
122
- < Alert type = "error" showIcon >
123
- { t (
124
- 'We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.'
125
- ) }
126
- </ Alert >
127
- ) ;
128
- }
129
-
130
- renderBody ( ) {
131
- return (
132
- < ApiForm
133
- apiMethod = "PUT"
134
- apiEndpoint = { this . getEndpoints ( ) [ 0 ] ! [ 1 ] ! }
135
- submitLabel = { t ( 'Continue' ) }
136
- initialData = { this . getInitialData ( ) }
137
- onSubmitSuccess = { this . props . onConfigured }
138
- >
139
- < p > { t ( 'Complete setup by filling out the required configuration.' ) } </ p >
140
-
141
- { this . renderFormFields ( ) }
142
- </ ApiForm >
143
- ) ;
144
- }
105
+ } ;
106
+
107
+ const version = ConfigStore . get ( 'version' ) ;
108
+ return (
109
+ < SentryDocumentTitle noSuffix title = { t ( 'Setup Sentry' ) } >
110
+ < Wrapper >
111
+ < Pattern />
112
+ < SetupWizard >
113
+ < Heading >
114
+ < span > { t ( 'Welcome to Sentry' ) } </ span >
115
+ < Version > { version . current } </ Version >
116
+ </ Heading >
117
+ < Form
118
+ apiMethod = "PUT"
119
+ apiEndpoint = { '/internal/options/?query=is:required' }
120
+ submitLabel = { t ( 'Continue' ) }
121
+ initialData = { getInitialData ( ) }
122
+ onSubmitSuccess = { onConfigured }
123
+ >
124
+ < p > { t ( 'Complete setup by filling out the required configuration.' ) } </ p >
125
+
126
+ { renderFormFields ( ) }
127
+ </ Form >
128
+ </ SetupWizard >
129
+ </ Wrapper >
130
+ </ SentryDocumentTitle >
131
+ ) ;
145
132
}
146
133
147
134
const Wrapper = styled ( 'div' ) `
0 commit comments