@@ -4,17 +4,18 @@ import styled from '@emotion/styled';
44import sentryPattern from 'sentry-images/pattern/sentry-pattern.png' ;
55
66import { 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 ' ;
99import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle' ;
1010import { t } from 'sentry/locale' ;
1111import ConfigStore from 'sentry/stores/configStore' ;
1212import { space } from 'sentry/styles/space' ;
13+ import { useApiQuery } from 'sentry/utils/queryClient' ;
1314
1415import type { Field } from '../options' ;
1516import { getForm , getOptionDefault , getOptionField } from '../options' ;
1617
17- export type InstallWizardProps = DeprecatedAsyncComponent [ 'props' ] & {
18+ export type InstallWizardProps = {
1819 onConfigured : ( ) => void ;
1920} ;
2021
@@ -26,21 +27,30 @@ export type InstallWizardOptions = Record<
2627 }
2728> ;
2829
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 /> ;
3941 }
4042
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+ }
4352
53+ const renderFormFields = ( ) => {
4454 let missingOptions = new Set (
4555 Object . keys ( options ) . filter ( option => ! options [ option ] ! . field . isSet )
4656 ) ;
@@ -65,10 +75,9 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
6575 }
6676
6777 return getForm ( fields ) ;
68- }
78+ } ;
6979
70- getInitialData ( ) {
71- const options = this . state . data ! ;
80+ const getInitialData = ( ) => {
7281 const data = { } ;
7382 Object . keys ( options ) . forEach ( optionName => {
7483 const option = options [ optionName ] ! ;
@@ -93,55 +102,33 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
93102 }
94103 } ) ;
95104 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+ ) ;
145132}
146133
147134const Wrapper = styled ( 'div' ) `
0 commit comments