@@ -6,14 +6,13 @@ import { useAuthContext } from "contexts/auth/AuthProvider";
6
6
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata" ;
7
7
import { type FC , useEffect , useState } from "react" ;
8
8
import { Helmet } from "react-helmet-async" ;
9
- import { useMutation , useQuery } from "react-query" ;
9
+ import { useMutation , useQuery , useQueryClient } from "react-query" ;
10
10
import { Navigate , useNavigate } from "react-router-dom" ;
11
11
import { pageTitle } from "utils/page" ;
12
12
import { sendDeploymentEvent } from "utils/telemetry" ;
13
13
import { SetupPageView } from "./SetupPageView" ;
14
14
import { useDebouncedFunction } from "hooks/debounce" ;
15
15
16
-
17
16
export const SetupPage : FC = ( ) => {
18
17
const {
19
18
isLoading,
@@ -23,12 +22,16 @@ export const SetupPage: FC = () => {
23
22
isSigningIn,
24
23
} = useAuthContext ( ) ;
25
24
const createFirstUserMutation = useMutation ( createFirstUser ( ) ) ;
25
+ const validatePasswordMutation = useMutation ( validatePassword ( ) ) ;
26
+
26
27
const setupIsComplete = ! isConfiguringTheFirstUser ;
27
28
const { metadata } = useEmbeddedMetadata ( ) ;
28
29
const buildInfoQuery = useQuery ( buildInfo ( metadata [ "build-info" ] ) ) ;
29
- const validatePasswordQuery = useQuery ( { ... validatePassword ( ) , enabled : true } ) ;
30
+ const queryClient = useQueryClient ( ) ;
30
31
const navigate = useNavigate ( ) ;
31
32
33
+ const [ passwordIsValid , setPasswordIsValid ] = useState ( false ) ;
34
+
32
35
useEffect ( ( ) => {
33
36
if ( ! buildInfoQuery . data ) {
34
37
return ;
@@ -53,7 +56,11 @@ export const SetupPage: FC = () => {
53
56
}
54
57
55
58
const validateUserPassword = async ( password : string ) => {
56
- const isValid = await validateUserPassword ( password ) ;
59
+ const isValid = validatePasswordMutation . mutate ( { password} , {
60
+ onSuccess : ( data ) => {
61
+ setPasswordIsValid ( data . isValid ) ;
62
+ } ,
63
+ } )
57
64
} ;
58
65
59
66
const { debounced : debouncedValidateUserPassword } = useDebouncedFunction ( validateUserPassword , 500 ) ;
@@ -65,6 +72,7 @@ export const SetupPage: FC = () => {
65
72
</ Helmet >
66
73
< SetupPageView
67
74
onPasswordChange = { debouncedValidateUserPassword }
75
+ passwordIsValid = { passwordIsValid }
68
76
isLoading = { isSigningIn || createFirstUserMutation . isLoading }
69
77
error = { createFirstUserMutation . error }
70
78
onSubmit = { async ( firstUser ) => {
0 commit comments