@@ -71,11 +71,10 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
71
71
} ) => {
72
72
const styles = useStyles ( ) ;
73
73
const [ owner , setOwner ] = useState ( defaultOwner ) ;
74
- const { verifyExternalAuth, externalAuthErrors } =
75
- useExternalAuthVerification ( externalAuth ) ;
76
74
const [ searchParams ] = useSearchParams ( ) ;
77
75
const disabledParamsList = searchParams ?. get ( "disable_params" ) ?. split ( "," ) ;
78
76
77
+ const { authErrors, errorCount } = getAuthErrors ( externalAuth ) ;
79
78
const form : FormikContextType < TypesGen . CreateWorkspaceRequest > =
80
79
useFormik < TypesGen . CreateWorkspaceRequest > ( {
81
80
initialValues : {
@@ -92,7 +91,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
92
91
} ) ,
93
92
enableReinitialize : true ,
94
93
onSubmit : ( request ) => {
95
- if ( ! verifyExternalAuth ( ) ) {
94
+ if ( errorCount > 0 ) {
96
95
form . setSubmitting ( false ) ;
97
96
return ;
98
97
}
@@ -180,7 +179,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
180
179
startPollingExternalAuth = { startPollingExternalAuth }
181
180
displayName = { auth . display_name }
182
181
displayIcon = { auth . display_icon }
183
- error = { externalAuthErrors [ auth . id ] }
182
+ error = { authErrors [ auth . id ] }
184
183
/>
185
184
) ) }
186
185
</ FormFields >
@@ -245,40 +244,21 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
245
244
246
245
type ExternalAuthErrors = Record < string , string > ;
247
246
248
- const useExternalAuthVerification = (
249
- externalAuth : TypesGen . TemplateVersionExternalAuth [ ] ,
250
- ) => {
251
- const [ externalAuthErrors , setExternalAuthErrors ] =
252
- useState < ExternalAuthErrors > ( { } ) ;
247
+ function getAuthErrors (
248
+ externalAuth : readonly TypesGen . TemplateVersionExternalAuth [ ] ,
249
+ ) {
250
+ const authErrors : ExternalAuthErrors = { } ;
251
+ let errorCount = 0 ;
253
252
254
- // Clear errors when externalAuth is refreshed
255
- useEffect ( ( ) => {
256
- setExternalAuthErrors ( { } ) ;
257
- } , [ externalAuth ] ) ;
258
-
259
- const verifyExternalAuth = ( ) => {
260
- const errors : ExternalAuthErrors = { } ;
261
-
262
- for ( let i = 0 ; i < externalAuth . length ; i ++ ) {
263
- const auth = externalAuth . at ( i ) ;
264
- if ( ! auth ) {
265
- continue ;
266
- }
267
- if ( ! auth . authenticated ) {
268
- errors [ auth . id ] = "You must authenticate to create a workspace!" ;
269
- }
253
+ for ( const auth of externalAuth ) {
254
+ if ( ! auth . authenticated ) {
255
+ authErrors [ auth . id ] = "You must authenticate to create a workspace!" ;
256
+ errorCount ++ ;
270
257
}
258
+ }
271
259
272
- setExternalAuthErrors ( errors ) ;
273
- const isValid = Object . keys ( errors ) . length === 0 ;
274
- return isValid ;
275
- } ;
276
-
277
- return {
278
- externalAuthErrors,
279
- verifyExternalAuth,
280
- } ;
281
- } ;
260
+ return { authErrors, errorCount } as const ;
261
+ }
282
262
283
263
const useStyles = makeStyles ( ( theme ) => ( {
284
264
hasDescription : {
0 commit comments