@@ -27,12 +27,12 @@ import {
27
27
ImmutableTemplateParametersSection ,
28
28
MutableTemplateParametersSection ,
29
29
} from "components/TemplateParameters/TemplateParameters" ;
30
- import { ExternalAuth } from "./ExternalAuth " ;
30
+ import { ExternalAuthButton } from "./ExternalAuthButton " ;
31
31
import { ErrorAlert } from "components/Alert/ErrorAlert" ;
32
32
import { Stack } from "components/Stack/Stack" ;
33
33
import {
34
34
CreateWorkspaceMode ,
35
- type ExternalAuthPollingState ,
35
+ ExternalAuthPollingState ,
36
36
} from "./CreateWorkspacePage" ;
37
37
import { useSearchParams } from "react-router-dom" ;
38
38
import { CreateWSPermissions } from "./permissions" ;
@@ -85,10 +85,9 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
85
85
} ) => {
86
86
const theme = useTheme ( ) ;
87
87
const [ owner , setOwner ] = useState ( defaultOwner ) ;
88
- const { verifyExternalAuth, externalAuthErrors } =
89
- useExternalAuthVerification ( externalAuth ) ;
90
88
const [ searchParams ] = useSearchParams ( ) ;
91
89
const disabledParamsList = searchParams ?. get ( "disable_params" ) ?. split ( "," ) ;
90
+ const requiresExternalAuth = externalAuth . some ( ( auth ) => ! auth . authenticated ) ;
92
91
93
92
const form : FormikContextType < TypesGen . CreateWorkspaceRequest > =
94
93
useFormik < TypesGen . CreateWorkspaceRequest > ( {
@@ -106,7 +105,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
106
105
} ) ,
107
106
enableReinitialize : true ,
108
107
onSubmit : ( request ) => {
109
- if ( ! verifyExternalAuth ( ) ) {
108
+ if ( requiresExternalAuth ) {
110
109
return ;
111
110
}
112
111
@@ -192,16 +191,20 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
192
191
description = "This template requires authentication to external services."
193
192
>
194
193
< FormFields >
194
+ { requiresExternalAuth && (
195
+ < Alert severity = "error" >
196
+ To create a workspace using the selected template, please
197
+ ensure you are authenticated with all the external providers
198
+ listed below.
199
+ </ Alert >
200
+ ) }
195
201
{ externalAuth . map ( ( auth ) => (
196
- < ExternalAuth
202
+ < ExternalAuthButton
197
203
key = { auth . id }
198
- authenticateURL = { auth . authenticate_url }
199
- authenticated = { auth . authenticated }
200
- externalAuthPollingState = { externalAuthPollingState }
201
- startPollingExternalAuth = { startPollingExternalAuth }
202
- displayName = { auth . display_name }
203
- displayIcon = { auth . display_icon }
204
- error = { externalAuthErrors [ auth . id ] }
204
+ auth = { auth }
205
+ isLoading = { externalAuthPollingState === "polling" }
206
+ onStartPolling = { startPollingExternalAuth }
207
+ displayRetry = { externalAuthPollingState === "abandoned" }
205
208
/>
206
209
) ) }
207
210
</ FormFields >
@@ -273,43 +276,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
273
276
) ;
274
277
} ;
275
278
276
- type ExternalAuthErrors = Record < string , string > ;
277
-
278
- const useExternalAuthVerification = (
279
- externalAuth : TypesGen . TemplateVersionExternalAuth [ ] ,
280
- ) => {
281
- const [ externalAuthErrors , setExternalAuthErrors ] =
282
- useState < ExternalAuthErrors > ( { } ) ;
283
-
284
- // Clear errors when externalAuth is refreshed
285
- useEffect ( ( ) => {
286
- setExternalAuthErrors ( { } ) ;
287
- } , [ externalAuth ] ) ;
288
-
289
- const verifyExternalAuth = ( ) => {
290
- const errors : ExternalAuthErrors = { } ;
291
-
292
- for ( let i = 0 ; i < externalAuth . length ; i ++ ) {
293
- const auth = externalAuth . at ( i ) ;
294
- if ( ! auth ) {
295
- continue ;
296
- }
297
- if ( ! auth . authenticated ) {
298
- errors [ auth . id ] = "You must authenticate to create a workspace!" ;
299
- }
300
- }
301
-
302
- setExternalAuthErrors ( errors ) ;
303
- const isValid = Object . keys ( errors ) . length === 0 ;
304
- return isValid ;
305
- } ;
306
-
307
- return {
308
- externalAuthErrors,
309
- verifyExternalAuth,
310
- } ;
311
- } ;
312
-
313
279
const styles = {
314
280
hasDescription : {
315
281
paddingBottom : 16 ,
0 commit comments