diff --git a/web/app/install/installForm.tsx b/web/app/install/installForm.tsx index abf377e389..df7aa0cbf4 100644 --- a/web/app/install/installForm.tsx +++ b/web/app/install/installForm.tsx @@ -1,6 +1,7 @@ 'use client' -import React, { useEffect } from 'react' +import React, { useCallback, useEffect } from 'react' import { useTranslation } from 'react-i18next' +import { useDebounceFn } from 'ahooks' import Link from 'next/link' import { useRouter } from 'next/navigation' @@ -39,7 +40,7 @@ const InstallForm = () => { const { register, handleSubmit, - formState: { errors }, + formState: { errors, isSubmitting }, } = useForm({ resolver: zodResolver(accountFormSchema), defaultValues: { @@ -59,9 +60,22 @@ const InstallForm = () => { } const handleSetting = async () => { + if (isSubmitting) return handleSubmit(onSubmit)() } + const { run: debouncedHandleKeyDown } = useDebounceFn( + (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + e.preventDefault() + handleSetting() + } + }, + { wait: 200 }, + ) + + const handleKeyDown = useCallback(debouncedHandleKeyDown, [debouncedHandleKeyDown]) + useEffect(() => { fetchSetupStatus().then((res: SetupStatusResponse) => { if (res.step === 'finished') { @@ -90,7 +104,7 @@ const InstallForm = () => {
-
+
@@ -114,7 +128,7 @@ const InstallForm = () => {
{errors.name && {t(`${errors.name.message}`)}} @@ -129,7 +143,7 @@ const InstallForm = () => { {...register('password')} type={showPassword ? 'text' : 'password'} placeholder={t('login.passwordPlaceholder') || ''} - className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm pr-10'} + className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder:text-gray-400 caret-primary-600 sm:text-sm pr-10'} />