@@ -14,6 +14,7 @@ import {
1414 useInstanceResetPasswordMutation ,
1515} from '@/features/instance/operations/mutations/useInstanceResetPasswordMutation' ;
1616import { getInstanceUserInfo } from '@/features/instance/operations/queries/getInstanceUserInfo' ;
17+ import { AddUserFormSchema } from '@/features/instance/operations/schemas/addUserFormSchema' ;
1718import { authStore } from '@/lib/authStore' ;
1819import { getOperationsUrlForCluster } from '@/lib/urls/getOperationsUrlForCluster' ;
1920import { zodResolver } from '@hookform/resolvers/zod' ;
@@ -24,25 +25,6 @@ import { useForm } from 'react-hook-form';
2425import { toast } from 'sonner' ;
2526import { z } from 'zod' ;
2627
27- const ClusterSetPasswordSchema = z
28- . object ( {
29- username : z . string ( {
30- error : 'Please enter a username.' ,
31- // TODO: usernames must have only letters, numbers, hyphens, and underscores
32- } ) . min ( 1 , { error : 'Please enter a username.' } ) ,
33- password : z
34- . string ( {
35- error : 'Please enter your password' ,
36- } )
37- . min ( 1 , { error : 'Password is required' } )
38- . max ( 50 , { error : 'Password must be less than 50 characters' } ) ,
39- confirmPassword : z . string ( ) ,
40- } )
41- . refine ( ( data ) => data . password === data . confirmPassword , {
42- error : 'Passwords do not match' ,
43- path : [ 'confirmPassword' ] ,
44- } ) ;
45-
4628const route = getRouteApi ( '' ) ;
4729
4830export function ClusterSetPassword ( ) {
@@ -59,18 +41,19 @@ export function ClusterSetPassword() {
5941 const router = useRouter ( ) ;
6042
6143 const form = useForm ( {
62- resolver : zodResolver ( ClusterSetPasswordSchema ) ,
44+ resolver : zodResolver ( AddUserFormSchema ) ,
6345 defaultValues : {
64- username : '' ,
65- password : '' ,
6646 confirmPassword : '' ,
47+ password : '' ,
48+ role : 'super_user' ,
49+ username : '' ,
6750 } ,
6851 } ) ;
6952 const tempPassword = cluster ?. instances ?. find ( i => i . tempPassword ) ?. tempPassword ;
7053
7154 const { mutate : submitInstanceResetPassword , isPending } = useInstanceResetPasswordMutation ( ) ;
7255
73- const submitForm = useCallback ( async ( formData : z . infer < typeof ClusterSetPasswordSchema > ) => {
56+ const submitForm = useCallback ( async ( formData : z . infer < typeof AddUserFormSchema > ) => {
7457 if ( ! operationsUrl ) {
7558 toast . error ( 'Cluster is not yet fully loaded, please wait a moment before trying to sign in.' ) ;
7659 return ;
@@ -87,7 +70,7 @@ export function ClusterSetPassword() {
8770 toast . success ( response . message ) ;
8871 const user = await getInstanceUserInfo ( { instanceClient } ) ;
8972 authStore . setUserForEntity ( cluster || null , user ) ;
90- router . invalidate ( ) ;
73+ void router . invalidate ( ) ;
9174 await navigate ( { to : redirect ?. startsWith ( '/' ) ? redirect : defaultInstanceRouteUpOne } ) ;
9275 } ,
9376 } ) ;
@@ -97,7 +80,6 @@ export function ClusterSetPassword() {
9780 return < Navigate to = "../sign-in" replace = { true } /> ;
9881 }
9982
100- // TODO: There's a lot we can DRY up between the sign in form variants.
10183 return (
10284 < >
10385 < nav className = "fixed top-20 w-full h-12 z-39 px-4 md:px-12 bg-grey-700 flex items-center" >
0 commit comments